Browse Source

#8 Add test cases

Ben Hsieh 8 years ago
parent
commit
e582a16d2a
2 changed files with 53 additions and 30 deletions
  1. 14
    0
      test/react-native-testkit/lib/comparer.js
  2. 39
    30
      test/tests.js

+ 14
- 0
test/react-native-testkit/lib/comparer.js View File

7
   exists : (a, b) => a,
7
   exists : (a, b) => a,
8
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
8
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
9
   isArray : (a, b) => Array.isArray(a),
9
   isArray : (a, b) => Array.isArray(a),
10
+  hasProperties : (a, b) => {
11
+    let res = true
12
+    for(let i in a) {
13
+      let found = false
14
+      for(let j in b) {
15
+        if(b[j] === i) {
16
+          found = true
17
+          break;
18
+        }
19
+      }
20
+      res = res && found
21
+    }
22
+    return res
23
+  }
10
 }
24
 }

+ 39
- 30
test/tests.js View File

127
 
127
 
128
 // added after 0.4.2
128
 // added after 0.4.2
129
 
129
 
130
-ctx.describe('Progress report test', (report, done) => {
131
-  let received = 0
132
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
133
-      Authorization : 'Bearer abde123eqweje'
134
-    })
135
-    .progress((written, total) => {
136
-      report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
137
-      if(written === total)
138
-        report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
139
-    })
140
-    .then((resp) => {
141
-      report(<Assert key="response data should be correct event with progress listener"
142
-        expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
143
-      done()
144
-    })
145
-
146
-})
130
+// ctx.describe('Progress report test', (report, done) => {
131
+//   let received = 0
132
+//   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
133
+//       Authorization : 'Bearer abde123eqweje'
134
+//     })
135
+//     .progress((written, total) => {
136
+//       report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
137
+//       if(written === total)
138
+//         report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
139
+//     })
140
+//     .then((resp) => {
141
+//       report(<Assert key="response data should be correct event with progress listener"
142
+//         expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
143
+//       done()
144
+//     })
145
+//
146
+// })
147
 
147
 
148
 // FIXME : not yet supported
148
 // FIXME : not yet supported
149
-ctx.describe('Large file download test', (report, done) => {
150
-  let received = 0
151
-  // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
152
-  //   Authorization : 'Bearer abde123eqweje'
153
-  // })
154
-  // .then((resp) => {
155
-    report(<Assert key="not supported" expect={true} actual={false}/>)
156
-    done()
157
-  // })
158
-
159
-})
149
+// ctx.describe('Large file download test', (report, done) => {
150
+//   let received = 0
151
+//   // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
152
+//   //   Authorization : 'Bearer abde123eqweje'
153
+//   // })
154
+//   // .then((resp) => {
155
+//     report(<Assert key="not supported" expect={true} actual={false}/>)
156
+//     done()
157
+//   // })
158
+//
159
+// })
160
 
160
 
161
 // added after 0.5.0
161
 // added after 0.5.0
162
 
162
 
165
   RNFetchBlob.getSystemDirs().then((dirs) => {
165
   RNFetchBlob.getSystemDirs().then((dirs) => {
166
     report(
166
     report(
167
       <Assert key="system folders should exists" expect={dirs} comparer={Comparer.exists} />,
167
       <Assert key="system folders should exists" expect={dirs} comparer={Comparer.exists} />,
168
+      <Assert key="check properties"
169
+        expect={dirs}
170
+        comparer={Comparer.hasProperties}
171
+        actual={['PictureDir', 'MovieDir', 'DocumentDir', 'CacheDir']}
172
+      />,
168
       <Info key="System Folders">
173
       <Info key="System Folders">
169
         <Text>{`${JSON.stringify(dirs)}`}</Text>
174
         <Text>{`${JSON.stringify(dirs)}`}</Text>
170
       </Info>
175
       </Info>
171
     )
176
     )
177
+    done()
172
   })
178
   })
173
 
179
 
174
 })
180
 })
175
 
181
 
176
 ctx.describe('Download file to storage', (report, done) => {
182
 ctx.describe('Download file to storage', (report, done) => {
177
 
183
 
178
-  RNFetchBlob.config({fileCache : true})
184
+  RNFetchBlob.config({
185
+      fileCache : true,
186
+      appendExt : 'png'
187
+    })
179
     .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
188
     .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
180
     .then((resp) => {
189
     .then((resp) => {
181
       report(<Info key={`image from ${resp.path()}`}>
190
       report(<Info key={`image from ${resp.path()}`}>
182
-        <Image ssource={{ uri : 'file://' + resp.path()}} style={styles.image}/>
191
+        <Image source={{ uri : resp.path()}} style={styles.image}/>
183
       </Info>)
192
       </Info>)
184
       done()
193
       done()
185
     })
194
     })