Explorar el Código

#8 Add test cases

Ben Hsieh hace 8 años
padre
commit
e582a16d2a
Se han modificado 2 ficheros con 53 adiciones y 30 borrados
  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 Ver fichero

@@ -7,4 +7,18 @@ export default {
7 7
   exists : (a, b) => a,
8 8
   hasValue : (a, b) => (a !== void 0) && (Array.isArray(a) ? a.length !==0 : true),
9 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 Ver fichero

@@ -127,36 +127,36 @@ ctx.describe('Compare uploaded multipart image', (report, done) => {
127 127
 
128 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 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 161
 // added after 0.5.0
162 162
 
@@ -165,21 +165,30 @@ ctx.describe('Get storage folders', (report, done) => {
165 165
   RNFetchBlob.getSystemDirs().then((dirs) => {
166 166
     report(
167 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 173
       <Info key="System Folders">
169 174
         <Text>{`${JSON.stringify(dirs)}`}</Text>
170 175
       </Info>
171 176
     )
177
+    done()
172 178
   })
173 179
 
174 180
 })
175 181
 
176 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 188
     .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
180 189
     .then((resp) => {
181 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 192
       </Info>)
184 193
       done()
185 194
     })