Parcourir la source

Add test case for #27

Ben Hsieh il y a 8 ans
Parent
révision
ea7428994d
3 fichiers modifiés avec 64 ajouts et 2 suppressions
  1. 62
    0
      test/test-0.6.0.js
  2. 0
    1
      test/test-fs.js
  3. 2
    1
      test/test-init.js

+ 62
- 0
test/test-0.6.0.js Voir le fichier

@@ -0,0 +1,62 @@
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.6.0',
19
+  run : true,
20
+  expand : false,
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('writeFile test', (report, done) => {
29
+  let path = dirs.DocumentDir + '/0.6.0-'+Date.now()+'/writeFileTest'+Date.now()
30
+  let data = 'hellofrom'+Date.now()
31
+  fs.writeFile(path, 'utf8', data)
32
+    .then(() => fs.readFile(path, 'utf8'))
33
+    .then((actual) => {
34
+      report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
35
+      data += 'base64'
36
+      return fs.writeFile(path, 'base64', RNFetchBlob.base64.encode(data))
37
+    })
38
+    .then(() => fs.readFile(path, 'base64'))
39
+    .then((actual) => {
40
+      report(<Assert key="base64 content should correct"
41
+        expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
42
+        actual={RNFetchBlob.base64.decode(actual)}/>)
43
+      data += 'ascii'
44
+      return fs.writeFile(path, 'ascii', getASCIIArray(data));
45
+    })
46
+    .then(() => fs.readFile(path, 'ascii'))
47
+    .then((actual) => {
48
+      report(<Assert key="ascii content should correct"
49
+        expect={getASCIIArray(data)}
50
+        comparer={Comparer.equalToArray}
51
+        actual={actual}/>)
52
+      done()
53
+    })
54
+})
55
+
56
+function getASCIIArray(str) {
57
+  let r = []
58
+  for(let i=0;i<str.length;i++) {
59
+    r.push(str[i].charCodeAt(0))
60
+  }
61
+  return r
62
+}

+ 0
- 1
test/test-fs.js Voir le fichier

@@ -22,7 +22,6 @@ let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
22 22
 let dirs = RNFetchBlob.fs.dirs
23 23
 
24 24
 describe('Get storage folders', (report, done) => {
25
-  console.log(dirs)
26 25
   report(
27 26
     <Assert key="system folders should exists"
28 27
       expect={dirs}

+ 2
- 1
test/test-init.js Voir le fichier

@@ -55,5 +55,6 @@ require('./test-0.1.x-0.4.x')
55 55
 require('./test-0.5.1')
56 56
 require('./test-0.5.2')
57 57
 require('./test-0.5.3')
58
+require('./test-0.6.0')
58 59
 require('./test-fs')
59
-// require('./test-android')
60
+require('./test-android')