Browse Source

Add test case for #120

Ben Hsieh 8 years ago
parent
commit
76e7582cec
2 changed files with 28 additions and 9 deletions
  1. 2
    0
      test/test-0.7.0.js
  2. 26
    9
      test/test-0.9.4.js

+ 2
- 0
test/test-0.7.0.js View File

45
     if(Date.now() - deb < 1000)
45
     if(Date.now() - deb < 1000)
46
       return
46
       return
47
     deb = Date.now()
47
     deb = Date.now()
48
+    console.log('download', now, total)
48
     report(<Info uid="200" key="progress">
49
     report(<Info uid="200" key="progress">
49
       <Text>
50
       <Text>
50
         {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}
51
         {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}
72
       if(Date.now() - deb < 1000)
73
       if(Date.now() - deb < 1000)
73
         return
74
         return
74
       deb = Date.now()
75
       deb = Date.now()
76
+      console.log('upload', now, total)
75
       report(<Info uid="300" key="upload progress">
77
       report(<Info uid="300" key="upload progress">
76
         <Text>
78
         <Text>
77
           {`upload ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}
79
           {`upload ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}

+ 26
- 9
test/test-0.9.4.js View File

117
       cache = res.path()
117
       cache = res.path()
118
       return fs.readStream(cache, 'utf8', 102400)
118
       return fs.readStream(cache, 'utf8', 102400)
119
     })
119
     })
120
-    // .then((res) => {
121
-    //   cache = res.path()
122
-    //   return fs.readFile(cache, 'utf8')
123
-    // })
124
-    // .then(() => {
125
-    //   report(<Info key="good" />)
126
-    //   done()
127
-    //   fs.unlink(cache)
128
-    // })
129
     .then((stream) => {
120
     .then((stream) => {
130
       stream.open()
121
       stream.open()
131
       start = Date.now()
122
       start = Date.now()
153
     })
144
     })
154
 
145
 
155
 })
146
 })
147
+
148
+describe('issue #120 upload progress should work when sending body as-is', (report, done) => {
149
+
150
+  let data = RNTest.prop('image')
151
+  let tick = 0
152
+
153
+  let task = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
154
+    Authorization : `Bearer ${DROPBOX_TOKEN}`,
155
+    'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
156
+    'Content-Type' : 'text/plain; charset=dropbox-cors-hack',
157
+  }, data)
158
+
159
+  task.uploadProgress((current, total) => {
160
+    tick ++
161
+  })
162
+  .then((res) => {
163
+    let resp = res.json()
164
+    report(
165
+      <Info key="viewer"><Text>{JSON.stringify(resp)}</Text></Info>,
166
+      <Assert key="event should be triggered"
167
+        expect={tick}
168
+        comparer={Comparer.greater} actual={0}/>)
169
+    done()
170
+  })
171
+
172
+})