|
@@ -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
|
+})
|