浏览代码

Change test cased, added android only tests

Ben Hsieh 8 年前
父节点
当前提交
3fac600be5
共有 3 个文件被更改,包括 83 次插入4 次删除
  1. 57
    0
      test/test-android.js
  2. 21
    0
      test/test-fs.js
  3. 5
    4
      test/test-init.js

+ 57
- 0
test/test-android.js 查看文件

@@ -0,0 +1,57 @@
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 : 'Android only functions',
19
+  run : true,
20
+  expand : false,
21
+})
22
+const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23
+
24
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
25
+
26
+// Android only tests
27
+
28
+let tmpFilePath = null
29
+
30
+describe('Download with notification', (report, done) => {
31
+  let filePath = null
32
+  let filename = `test-${Date.now()}.png`
33
+  RNFetchBlob.fs.getSystemDirs().then((dirs) => {
34
+    filePath = `${dirs.DownloadDir}/${filename}`
35
+    return RNFetchBlob.config({
36
+        path : filePath,
37
+        addAndroidDownloads : {
38
+          title : 'RNFetchBlob test download success',
39
+          description : `File description added by RNFetchblob`,
40
+          mediaScannable : true,
41
+          mime : "image/png",
42
+          notification : true
43
+        }
44
+      })
45
+      .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
46
+  })
47
+  .then((resp) => {
48
+    tmpFilePath = resp.path()
49
+    report(<Info key={`image from ${tmpFilePath}`}>
50
+      <Image
51
+        source={{ uri : prefix + tmpFilePath}}
52
+        style={styles.image}/>
53
+    </Info>)
54
+    done()
55
+  })
56
+
57
+})

+ 21
- 0
test/test-fs.js 查看文件

@@ -291,3 +291,24 @@ describe('cp API test', {timeout : 10000},(report, done) => {
291 291
     })
292 292
   })
293 293
 })
294
+
295
+describe('Download file to `download` folder', (report, done) => {
296
+  RNFetchBlob.fs
297
+    .getSystemDirs()
298
+    .then((dirs) => {
299
+      return RNFetchBlob.config({
300
+        path : dirs.DownloadDir + '/download-test.png'
301
+      })
302
+      .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
303
+        Authorization : 'Bearer abde123eqweje'
304
+      })
305
+    })
306
+    .then((resp) => {
307
+      report(<Info key="image in download path">
308
+        <Image
309
+          style={styles.image}
310
+          source={{uri : 'file://' + dirs.DownloadDir + '/download-test.png'}}/>
311
+      </Info>)
312
+      done()
313
+    })
314
+})

+ 5
- 4
test/test-init.js 查看文件

@@ -18,7 +18,7 @@ const { Assert, Comparer, Info, describe, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.5.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.0.14:8123')
21
+prop('TEST_SERVER_URL', 'http://192.168.40.7:8123')
22 22
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
23 23
 prop('styles', {
24 24
   image : {
@@ -51,6 +51,7 @@ describe('GET image from server', (report, done) => {
51 51
     })
52 52
 })
53 53
 
54
-require('./test-fs')
55
-require('./test-0.1.x-0.4.x')
56
-require('./test-0.5.x')
54
+// require('./test-fs')
55
+// require('./test-0.1.x-0.4.x')
56
+// require('./test-0.5.x')
57
+require('./test-android')