Explorar el Código

Fix 0.7.0 test case

Ben Hsieh hace 7 años
padre
commit
20b2c3cb88
Se han modificado 1 ficheros con 27 adiciones y 1 borrados
  1. 27
    1
      test/test-0.7.0.js

+ 27
- 1
test/test-0.7.0.js Ver fichero

@@ -33,11 +33,13 @@ describe('Upload and download large file', (report, done) => {
33 33
   let begin = -1
34 34
   let begin2 = -1
35 35
   let deb = Date.now()
36
+  let download = false, upload = false
36 37
   RNFetchBlob.config({
37 38
     fileCache : true
38 39
   })
39
-  .fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`)
40
+  .fetch('GET', `${TEST_SERVER_URL}/public/2mb-dummy`)
40 41
   .progress((now, total) => {
42
+    download = true
41 43
     if(begin === -1)
42 44
       begin = Date.now()
43 45
     if(Date.now() - deb < 1000)
@@ -57,6 +59,29 @@ describe('Upload and download large file', (report, done) => {
57 59
     report(<Info key="big file stat">
58 60
       <Text>{JSON.stringify(stat)}</Text>
59 61
     </Info>)
62
+    let task = RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
63
+      Authorization : `Bearer ${DROPBOX_TOKEN}`,
64
+      'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+Date.now()+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
65
+      'Content-Type' : 'application/octet-stream',
66
+    }, RNFetchBlob.wrap(bigfile))
67
+    begin = -1
68
+    task.uploadProgress((now, total) => {
69
+      upload = true
70
+      if(begin === -1)
71
+        begin = Date.now()
72
+      if(Date.now() - deb < 1000)
73
+        return
74
+      deb = Date.now()
75
+      report(<Info uid="300" key="upload progress">
76
+        <Text>
77
+          {`upload ${now} / ${total} bytes (${Math.floor(now / (Date.now() - begin))} kb/s) ${(100*now/total).toFixed(2)}%`}
78
+        </Text>
79
+      </Info>)
80
+    })
81
+    return task
82
+  })
83
+  .then(() => {
84
+    report(<Assert key="upload and download event triggered" expect={true} actual={download && upload}/>)
60 85
     done()
61 86
   })
62 87
 })
@@ -87,6 +112,7 @@ describe('cancel task should work properly', (report, done) => {
87 112
       </Text>
88 113
     </Info>)
89 114
   })
115
+
90 116
   let checkpoint1 = 0
91 117
   Timer.setTimeout(() => {
92 118
     task.cancel()