Browse Source

Change test script

Ben Hsieh 8 years ago
parent
commit
765d0164fb
1 changed files with 59 additions and 34 deletions
  1. 59
    34
      test/tests.js

+ 59
- 34
test/tests.js View File

@@ -15,7 +15,7 @@ import {
15 15
 
16 16
 const FILENAME = `${Platform.OS}-0.5.0-${Date.now()}.png`
17 17
 // paste your test config here
18
-const TEST_SERVER_URL = 'http://192.168.17.193:8123'
18
+const TEST_SERVER_URL = 'http://192.168.0.14:8123'
19 19
 const DROPBOX_TOKEN = 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4'
20 20
 
21 21
 const ctx = new RNTest.TestContext()
@@ -51,6 +51,8 @@ ctx.describe('GET image from server', (report, done) => {
51 51
 
52 52
 
53 53
 })
54
+
55
+// FIXME : discard these test cases in feature branch
54 56
 //
55 57
 // ctx.describe('The check if it follows 301/302 redirection', (report, done) => {
56 58
 //
@@ -108,43 +110,43 @@ ctx.describe('GET image from server', (report, done) => {
108 110
 //
109 111
 // })
110 112
 
111
-ctx.describe('Compare uploaded multipart image', (report, done) => {
112
-  let r1 = null
113
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
114
-    .then((resp) => {
115
-      r1 = resp
116
-      return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
117
-    })
118
-    .then((resp) => {
119
-      report(
120
-        <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
121
-        <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
122
-      )
123
-      done()
124
-    })
125
-
126
-})
127
-
128
-// added after 0.4.2
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}/>)
113
+// ctx.describe('Compare uploaded multipart image', (report, done) => {
114
+//   let r1 = null
115
+//   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
116
+//     .then((resp) => {
117
+//       r1 = resp
118
+//       return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
139 119
 //     })
140 120
 //     .then((resp) => {
141
-//       report(<Assert key="response data should be correct event with progress listener"
142
-//         expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
121
+//       report(
122
+//         <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
123
+//         <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
124
+//       )
143 125
 //       done()
144 126
 //     })
145 127
 //
146 128
 // })
147 129
 
130
+// added after 0.4.2
131
+
132
+ctx.describe('Progress report test', (report, done) => {
133
+  let received = 0
134
+  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
135
+      Authorization : 'Bearer abde123eqweje'
136
+    })
137
+    .progress((written, total) => {
138
+      report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
139
+      if(written === total)
140
+        report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
141
+    })
142
+    .then((resp) => {
143
+      report(<Assert key="response data should be correct event with progress listener"
144
+        expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
145
+      done()
146
+    })
147
+
148
+})
149
+
148 150
 // FIXME : not yet supported
149 151
 // ctx.describe('Large file download test', (report, done) => {
150 152
 //   let received = 0
@@ -179,7 +181,9 @@ ctx.describe('Get storage folders', (report, done) => {
179 181
 
180 182
 })
181 183
 
182
-ctx.describe('Download file to storage', (report, done) => {
184
+let tmpFilePath = null
185
+
186
+ctx.describe('Download file to storage with custom file extension', (report, done) => {
183 187
 
184 188
   RNFetchBlob.config({
185 189
       fileCache : true,
@@ -187,11 +191,32 @@ ctx.describe('Download file to storage', (report, done) => {
187 191
     })
188 192
     .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
189 193
     .then((resp) => {
190
-      report(<Info key={`image from ${resp.path()}`}>
191
-        <Image source={{ uri : resp.path()}} style={styles.image}/>
194
+      tmpFilePath = resp.path()
195
+      report(<Info key={`image from ${tmpFilePath}`}>
196
+        <Image source={{ uri : tmpFilePath}} style={styles.image}/>
192 197
       </Info>)
193 198
       done()
194 199
     })
195 200
 })
196 201
 
202
+ctx.describe('Read cache file with file stream', (report, done) => {
203
+  let data = 'data:image/png;base64, '
204
+  let stream = RNFetchBlob.openReadStream(tmpFilePath, 'base64')
205
+  stream.onData((chunk) => {
206
+    data += chunk
207
+  })
208
+  stream.onEnd(() => {
209
+    report(
210
+      <Assert key="image should have value" expect={0} comparer={Comparer.smaller} actual={data.length}/>,
211
+      <Info key="image from read stream">
212
+        <Image source={{uri : data}} style={styles.image}/>
213
+      </Info>)
214
+    done()
215
+  })
216
+  stream.onError((err) => {
217
+    console.log('stream err', err)
218
+  })
219
+
220
+})
221
+
197 222
 export default ctx