|
@@ -0,0 +1,65 @@
|
|
1
|
+import RNTest from './react-native-testkit/'
|
|
2
|
+import React from 'react'
|
|
3
|
+import RNFetchBlob from 'react-native-fetch-blob'
|
|
4
|
+
|
|
5
|
+import {
|
|
6
|
+ StyleSheet,
|
|
7
|
+ Text,
|
|
8
|
+ View,
|
|
9
|
+ ScrollView,
|
|
10
|
+ Platform,
|
|
11
|
+ Dimensions,
|
|
12
|
+ Image,
|
|
13
|
+} from 'react-native';
|
|
14
|
+
|
|
15
|
+const fs = RNFetchBlob.fs
|
|
16
|
+const { Assert, Comparer, Info, prop } = RNTest
|
|
17
|
+const describe = RNTest.config({
|
|
18
|
+ group : '0.8.0',
|
|
19
|
+ run : true,
|
|
20
|
+ expand : true,
|
|
21
|
+ timeout : 10000,
|
|
22
|
+})
|
|
23
|
+const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
|
|
24
|
+const dirs = RNFetchBlob.fs.dirs
|
|
25
|
+
|
|
26
|
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
|
|
27
|
+
|
|
28
|
+describe('URI encoding support', (report, done) => {
|
|
29
|
+
|
|
30
|
+ let testData1 = `test date write file from file ${Date.now()}`
|
|
31
|
+ let testData2 = `test date write file from file ${Date.now()*Math.random()}`
|
|
32
|
+ let file1 = dirs.DocumentDir + '/testFiletFile1' + Date.now()
|
|
33
|
+ let file2 = dirs.DocumentDir + '/testFiletFile2' + Date.now()
|
|
34
|
+ let init = [fs.createFile(file1, testData1, 'utf8'),
|
|
35
|
+ fs.createFile(file2, testData2, 'utf8')]
|
|
36
|
+ Promise.all(init)
|
|
37
|
+ .then(() => fs.appendFile(file1, file2, 'uri'))
|
|
38
|
+ .then(() => fs.readFile(file1, 'utf8'))
|
|
39
|
+ .then((data) => {
|
|
40
|
+ report(
|
|
41
|
+ <Assert key="append content from URI should be correct"
|
|
42
|
+ expect={testData1 + testData2}
|
|
43
|
+ actual={data}
|
|
44
|
+ />)
|
|
45
|
+ return fs.writeFile(file1, file2, 'uri')
|
|
46
|
+ })
|
|
47
|
+ .then(() => fs.readFile(file1, 'utf8'))
|
|
48
|
+ .then((data) => {
|
|
49
|
+ report(
|
|
50
|
+ <Assert key="write content from URI should be correct"
|
|
51
|
+ expect={testData2}
|
|
52
|
+ actual={data}
|
|
53
|
+ />)
|
|
54
|
+ done()
|
|
55
|
+ })
|
|
56
|
+
|
|
57
|
+})
|
|
58
|
+
|
|
59
|
+function getASCIIArray(str) {
|
|
60
|
+ let r = []
|
|
61
|
+ for(let i=0;i<str.length;i++) {
|
|
62
|
+ r.push(str[i].charCodeAt(0))
|
|
63
|
+ }
|
|
64
|
+ return r
|
|
65
|
+}
|