Browse Source

Add test case for #141

Ben Hsieh 8 years ago
parent
commit
7d970fa45b
1 changed files with 83 additions and 0 deletions
  1. 83
    0
      test/test-0.9.6.js

+ 83
- 0
test/test-0.9.6.js View File

@@ -0,0 +1,83 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+import {
5
+  StyleSheet,
6
+  Text,
7
+  View,
8
+  ScrollView,
9
+  Platform,
10
+  Dimensions,
11
+  Image,
12
+  TouchableOpacity,
13
+} from 'react-native';
14
+
15
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
16
+window.Blob = RNFetchBlob.polyfill.Blob
17
+
18
+const fs = RNFetchBlob.fs
19
+const { Assert, Comparer, Info, prop } = RNTest
20
+const describe = RNTest.config({
21
+  group : '0.9.6',
22
+  run : true,
23
+  expand : false,
24
+  timeout : 20000,
25
+})
26
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
27
+const dirs = RNFetchBlob.fs.dirs
28
+
29
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
30
+
31
+describe('support #141 breakpoint download', (report, done) => {
32
+  let dest = dirs.DocumentDir + '/breakpoint.png'
33
+  let firstChunkSize = 0
34
+
35
+  fs.unlink(dest)
36
+  .then(() => {
37
+
38
+    let session = RNFetchBlob.config({
39
+      path : dest
40
+    })
41
+    .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
42
+      'Cache-Control' : 'no-cache',
43
+      Range : 'bytes=0-200'
44
+    })
45
+    .then((res) => {
46
+      console.log(res.info())
47
+      console.log(res.data)
48
+      return fs.stat(res.path())
49
+    })
50
+    .then((stat) => {
51
+      firstChunkSize = Math.floor(stat.size)
52
+      console.log(firstChunkSize)
53
+    })
54
+    .then(() => {
55
+      RNFetchBlob.config({
56
+        path : dest + '?append=true'
57
+      })
58
+      .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
59
+        'Cache-Control' : 'no-cache',
60
+        Range : 'bytes=201-'
61
+      })
62
+      .then((res) => {
63
+        console.log(res.info())
64
+        console.log(res.path())
65
+        return fs.stat(res.path())
66
+      })
67
+      .then((stat) => {
68
+        report(
69
+          <Info key="image">
70
+            <Image style={RNTest.prop('styles').image} source={{uri : prefix + dest}}/>
71
+          </Info>,
72
+          <Assert key="request data should append to existing one" expect={23975} actual={Math.floor(stat.size)}/>)
73
+        done()
74
+      })
75
+
76
+    })
77
+  })
78
+
79
+})
80
+
81
+describe('support download/upload progress interval and division #140 ', (report, done) => {
82
+
83
+})