소스 검색

Add test cases for #45

Ben Hsieh 8 년 전
부모
커밋
271d9f5ecf
2개의 변경된 파일66개의 추가작업 그리고 12개의 파일을 삭제
  1. 58
    4
      test/test-0.6.2.js
  2. 8
    8
      test/test-init.js

+ 58
- 4
test/test-0.6.2.js 파일 보기

@@ -18,14 +18,37 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 const describe = RNTest.config({
19 19
   group : '0.6.2',
20 20
   run : true,
21
-  expand : true,
21
+  expand : false,
22 22
   timeout : 12000,
23 23
 })
24
-const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
24
+const { TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
25 25
 const  dirs = RNFetchBlob.fs.dirs
26 26
 
27 27
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
28 28
 
29
+describe('upload asset from camera roll', (report, done) => {
30
+  let imgName = `image-from-camera-roll-${Platform.OS}.jpg`
31
+  CameraRoll.getPhotos({first : 10})
32
+    .then((resp) => {
33
+      let url = resp.edges[0].node.image.uri
34
+      return fs.readFile(url, 'base64')
35
+    })
36
+    .then((data) => {
37
+      return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
38
+        Authorization : `Bearer ${DROPBOX_TOKEN}`,
39
+        'Dropbox-API-Arg': `{\"path\": \"/rn-upload/${imgName}\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
40
+        'Content-Type' : 'application/octet-stream',
41
+      }, data)
42
+    })
43
+    .then((resp) => {
44
+      resp = resp.json()
45
+      report(
46
+        <Assert key="confirm the file has been uploaded" expect={imgName} actual={resp.name}/>
47
+      )
48
+      done()
49
+    })
50
+
51
+})
29 52
 
30 53
 describe('access assets from camera roll', (report, done) => {
31 54
   let photo = null
@@ -48,7 +71,7 @@ describe('access assets from camera roll', (report, done) => {
48 71
 })
49 72
 
50 73
 describe('read asset in app bundle',(report, done) => {
51
-  let target = 'bundle-assets://test-asset2.png'
74
+  let target = fs.asset('test-asset2.png')
52 75
   fs.readFile(target, 'base64')
53 76
   .then((data) => {
54 77
     report(<Info key="asset image">
@@ -56,7 +79,7 @@ describe('read asset in app bundle',(report, done) => {
56 79
         style={styles.image}
57 80
         source={{uri: `data:image/png;base64, ${data}`}}/>
58 81
     </Info>)
59
-    return fs.readFile('bundle-assets://test-asset1.json', 'utf8')
82
+    return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
60 83
   })
61 84
   .then((resp) => {
62 85
     report(
@@ -66,3 +89,34 @@ describe('read asset in app bundle',(report, done) => {
66 89
       done()
67 90
   })
68 91
 })
92
+
93
+describe('stat assets in app', (report, done) => {
94
+  fs.stat(fs.asset('test-asset2.png'))
95
+    .then((data) => {
96
+      report(<Info key="list of assets">
97
+        <Text>{JSON.stringify(data)}</Text>
98
+      </Info>)
99
+      done()
100
+    })
101
+})
102
+
103
+describe('copy asset', (report, done) => {
104
+  let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
105
+  fs.cp(fs.asset('test-asset1.json'), dest)
106
+    .then(() => fs.readFile(dest, 'utf8'))
107
+    .then((data) => {
108
+      report(<Assert key="asset copied correctly"
109
+        expect={'asset#1'}
110
+        actual={JSON.parse(data).secret}/>)
111
+      return fs.stat(fs.asset('test-asset1.json'))
112
+    })
113
+    .then((stat) => {
114
+      report(<Assert key="file size check"
115
+        expect={27}
116
+        actual={Math.floor(stat.size)}/>,
117
+      <Info key="dest file info">
118
+        <Text>{JSON.stringify(stat)}</Text>
119
+      </Info>)
120
+      done()
121
+    })
122
+})

+ 8
- 8
test/test-init.js 파일 보기

@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, describe, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 prop('FILENAME', `${Platform.OS}-0.7.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
21
+prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
22
+prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {
@@ -51,10 +51,10 @@ describe('GET image from server', (report, done) => {
51 51
     })
52 52
 })
53 53
 //
54
-// require('./test-0.1.x-0.4.x')
55
-// require('./test-0.5.1')
56
-// require('./test-0.5.2')
57
-// require('./test-0.6.0')
54
+require('./test-0.1.x-0.4.x')
55
+require('./test-0.5.1')
56
+require('./test-0.5.2')
57
+require('./test-0.6.0')
58 58
 require('./test-0.6.2')
59
-// require('./test-fs')
60
-// require('./test-android')
59
+require('./test-fs')
60
+require('./test-android')