瀏覽代碼

Add test case for #120

Ben Hsieh 8 年之前
父節點
當前提交
76e7582cec
共有 2 個文件被更改,包括 28 次插入9 次删除
  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 查看文件

@@ -45,6 +45,7 @@ describe('Upload and download large file', (report, done) => {
45 45
     if(Date.now() - deb < 1000)
46 46
       return
47 47
     deb = Date.now()
48
+    console.log('download', now, total)
48 49
     report(<Info uid="200" key="progress">
49 50
       <Text>
50 51
         {`download ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}
@@ -72,6 +73,7 @@ describe('Upload and download large file', (report, done) => {
72 73
       if(Date.now() - deb < 1000)
73 74
         return
74 75
       deb = Date.now()
76
+      console.log('upload', now, total)
75 77
       report(<Info uid="300" key="upload progress">
76 78
         <Text>
77 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 查看文件

@@ -117,15 +117,6 @@ describe('#118 ', (report, done) => {
117 117
       cache = res.path()
118 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 120
     .then((stream) => {
130 121
       stream.open()
131 122
       start = Date.now()
@@ -153,3 +144,29 @@ describe('#118 ', (report, done) => {
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
+})