Ben Hsieh пре 8 година
родитељ
комит
e4c03f5945
2 измењених фајлова са 106 додато и 15 уклоњено
  1. 91
    1
      test/test-blob.js
  2. 15
    14
      test/test-init.js

+ 91
- 1
test/test-blob.js Прегледај датотеку

@@ -21,7 +21,7 @@ const { Assert, Comparer, Info, prop } = RNTest
21 21
 const describe = RNTest.config({
22 22
   group : 'Blob',
23 23
   run : true,
24
-  expand : true,
24
+  expand : false,
25 25
   timeout : 20000,
26 26
 })
27 27
 const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
@@ -29,3 +29,93 @@ const  dirs = RNFetchBlob.fs.dirs
29 29
 
30 30
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
31 31
 let file = RNTest.prop('image')
32
+
33
+describe('create Blob from string', (report, done) => {
34
+  Blob.build('hello world !')
35
+      .then((b) => fs.readFile(b.getRNFetchBlobRef(), 'utf8'))
36
+      .then((data) => {
37
+        report(
38
+          <Assert
39
+            key="string data verification"
40
+            expect={'hello world !'}
41
+            actual={data}/>)
42
+        done()
43
+      })
44
+})
45
+
46
+describe('create blob from BASE64 encoded data', (report, done) => {
47
+  let image = RNTest.prop('image')
48
+  Blob.build(image, {type : 'image/png;base64'})
49
+      .then((b) => fs.readFile(b.getRNFetchBlobRef(), 'base64'))
50
+      .then((data) => {
51
+        report(
52
+          <Assert
53
+            key="compare content length"
54
+            expect={image.length}
55
+            actual={data.length} />,
56
+          <Assert
57
+            key="compare content"
58
+            expect={image}
59
+            actual={data} />)
60
+        done()
61
+      })
62
+})
63
+
64
+describe('create blob from file', (report, done) => {
65
+  let path = fs.dirs.DocumentDir + '/blob-test-temp-img'
66
+  let image = RNTest.prop('image')
67
+  fs.writeFile(path, image, 'base64')
68
+    .then(() => Blob.build(RNFetchBlob.wrap(path)))
69
+    .then((b) => fs.readFile(b.getRNFetchBlobRef(), 'base64'))
70
+    .then((data) => {
71
+      report(
72
+        <Assert
73
+          key="compare content length"
74
+          expect={image.length}
75
+          actual={data.length} />,
76
+        <Assert
77
+          key="compare content"
78
+          expect={image}
79
+          actual={data} />)
80
+      done()
81
+    })
82
+})
83
+
84
+describe('create Blob without any agument', (report, done) => {
85
+  Blob.build().then((b) => fs.stat(b.getRNFetchBlobRef()))
86
+      .then((stat) => {
87
+        report(
88
+          <Assert
89
+            key="cache file exists"
90
+            expect={true}
91
+            actual={stat !== undefined && stat !== null}
92
+          />,
93
+        <Assert
94
+          key="cache file size is 0"
95
+          expect={0}
96
+          actual={Math.floor(stat.size)}/>)
97
+        done()
98
+      })
99
+})
100
+
101
+describe('blob clear cache test', (report, done) => {
102
+  let expect = 'test-'+Date.now()
103
+  Blob.clearCache()
104
+      .then(() => Blob.build(expect))
105
+      .then((b) => fs.readFile(b.getRNFetchBlobRef(), 'utf8'))
106
+      .then((data) => {
107
+        report(
108
+          <Assert key="Blob cache still working properly after clearCache"
109
+            expect={expect}
110
+            actual={data}/>)
111
+        return fs.lstat(fs.dirs.DocumentDir + '/RNFetchBlob-blobs/')
112
+      })
113
+      .then((stat) => {
114
+        report(
115
+          <Assert
116
+            key="should remain one file in cache directory."
117
+            expect={1}
118
+            actual={stat.length}/>)
119
+        done()
120
+      })
121
+})

+ 15
- 14
test/test-init.js Прегледај датотеку

@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.8.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
21
+prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
22
+prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {
@@ -58,15 +58,16 @@ describe('GET image from server', (report, done) => {
58 58
 })
59 59
 
60 60
 
61
-require('./test-0.1.x-0.4.x')
62
-require('./test-0.5.1')
63
-require('./test-0.5.2')
64
-require('./test-0.6.0')
65
-require('./test-0.6.2')
66
-require('./test-0.6.3')
67
-require('./test-0.7.0')
68
-require('./test-0.8.0')
69
-require('./test-fs')
70
-require('./test-xmlhttp')
71
-require('./test-firebase')
72
-require('./test-android')
61
+// require('./test-0.1.x-0.4.x')
62
+// require('./test-0.5.1')
63
+// require('./test-0.5.2')
64
+// require('./test-0.6.0')
65
+// require('./test-0.6.2')
66
+// require('./test-0.6.3')
67
+// require('./test-0.7.0')
68
+// require('./test-0.8.0')
69
+// require('./test-fs')
70
+// require('./test-xmlhttp')
71
+require('./test-blob')
72
+// require('./test-firebase')
73
+// require('./test-android')