|
@@ -1,235 +0,0 @@
|
1
|
|
-import RNTest from './react-native-testkit/'
|
2
|
|
-import React from 'react'
|
3
|
|
-import RNFetchBlob from 'react-native-fetch-blob'
|
4
|
|
-
|
5
|
|
-import {
|
6
|
|
- AppRegistry,
|
7
|
|
- StyleSheet,
|
8
|
|
- Text,
|
9
|
|
- View,
|
10
|
|
- Platform,
|
11
|
|
- ScrollView,
|
12
|
|
- Dimensions,
|
13
|
|
- Image,
|
14
|
|
-} from 'react-native';
|
15
|
|
-
|
16
|
|
-const FILENAME = `${Platform.OS}-0.5.0-${Date.now()}.png`
|
17
|
|
-// paste your test config here
|
18
|
|
-const TEST_SERVER_URL = 'http://192.168.0.14:8123'
|
19
|
|
-const DROPBOX_TOKEN = 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4'
|
20
|
|
-
|
21
|
|
-const ctx = new RNTest.TestContext()
|
22
|
|
-const Assert = RNTest.Assert
|
23
|
|
-const Comparer = RNTest.Comparer
|
24
|
|
-const Info = RNTest.Info
|
25
|
|
-
|
26
|
|
-let image = null
|
27
|
|
-
|
28
|
|
-const styles = StyleSheet.create({
|
29
|
|
- image : {
|
30
|
|
- width:Dimensions.get('window').width*0.9,
|
31
|
|
- height : Dimensions.get('window').width*0.9,
|
32
|
|
- margin :16
|
33
|
|
- }
|
34
|
|
-})
|
35
|
|
-
|
36
|
|
-ctx.describe('GET image from server', (report, done) => {
|
37
|
|
- RNFetchBlob
|
38
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
|
39
|
|
- Authorization : 'Bearer abde123eqweje'
|
40
|
|
- })
|
41
|
|
- .then((resp) => {
|
42
|
|
- image = resp.base64()
|
43
|
|
- report(
|
44
|
|
- <Info key="Response image">
|
45
|
|
- <Image
|
46
|
|
- style={styles.image}
|
47
|
|
- source={{uri : `data:image/png;base64, ${image}`}}/>
|
48
|
|
- </Info>)
|
49
|
|
- done()
|
50
|
|
- })
|
51
|
|
-
|
52
|
|
-
|
53
|
|
-})
|
54
|
|
-
|
55
|
|
-// ctx.describe('The check if it follows 301/302 redirection', (report, done) => {
|
56
|
|
-//
|
57
|
|
-// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
|
58
|
|
-// .then((resp) => {
|
59
|
|
-// report(
|
60
|
|
-// <Assert key="check image size" expect={image.length} actual={resp.base64().length}/>,
|
61
|
|
-// <Info key="Response image">
|
62
|
|
-// <Image
|
63
|
|
-// style={{width:Dimensions.get('window').width*0.9, height : Dimensions.get('window').width*0.9,margin :16}}
|
64
|
|
-// source={{uri : `data:image/png;base64, ${image}`}}/>
|
65
|
|
-// </Info>)
|
66
|
|
-// done()
|
67
|
|
-// })
|
68
|
|
-//
|
69
|
|
-// })
|
70
|
|
-//
|
71
|
|
-// ctx.describe('Upload octet-stream image to Dropbox', (report, done) => {
|
72
|
|
-//
|
73
|
|
-// RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
74
|
|
-// Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
75
|
|
-// 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
76
|
|
-// 'Content-Type' : 'application/octet-stream',
|
77
|
|
-// }, image)
|
78
|
|
-// .then((resp) => {
|
79
|
|
-// resp = resp.json()
|
80
|
|
-// report(
|
81
|
|
-// <Assert key="confirm the file has been uploaded" expect={FILENAME} actual={resp.name}/>
|
82
|
|
-// )
|
83
|
|
-// done()
|
84
|
|
-// })
|
85
|
|
-//
|
86
|
|
-// })
|
87
|
|
-//
|
88
|
|
-// ctx.describe('Upload multipart/form-data', (report, done) => {
|
89
|
|
-//
|
90
|
|
-// RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
91
|
|
-// Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
|
92
|
|
-// 'Content-Type' : 'multipart/form-data',
|
93
|
|
-// }, [
|
94
|
|
-// { name : 'test-img', filename : 'test-img.png', data: image},
|
95
|
|
-// { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
96
|
|
-// { name : 'field1', data : 'hello !!'},
|
97
|
|
-// { name : 'field2', data : 'hello2 !!'}
|
98
|
|
-// ])
|
99
|
|
-// .then((resp) => {
|
100
|
|
-// resp = resp.json()
|
101
|
|
-// report(
|
102
|
|
-// <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
103
|
|
-// <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
104
|
|
-// )
|
105
|
|
-// done()
|
106
|
|
-// })
|
107
|
|
-//
|
108
|
|
-//
|
109
|
|
-// })
|
110
|
|
-//
|
111
|
|
-// ctx.describe('Compare uploaded multipart image', (report, done) => {
|
112
|
|
-// let r1 = null
|
113
|
|
-// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
|
114
|
|
-// .then((resp) => {
|
115
|
|
-// r1 = resp
|
116
|
|
-// return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
|
117
|
|
-// })
|
118
|
|
-// .then((resp) => {
|
119
|
|
-// report(
|
120
|
|
-// <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
|
121
|
|
-// <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
|
122
|
|
-// )
|
123
|
|
-// done()
|
124
|
|
-// })
|
125
|
|
-//
|
126
|
|
-// })
|
127
|
|
-
|
128
|
|
-// added after 0.4.2
|
129
|
|
-
|
130
|
|
-// ctx.describe('Progress report test', (report, done) => {
|
131
|
|
-// let received = 0
|
132
|
|
-// RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
|
133
|
|
-// Authorization : 'Bearer abde123eqweje'
|
134
|
|
-// })
|
135
|
|
-// .progress((written, total) => {
|
136
|
|
-// report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
|
137
|
|
-// if(written === total)
|
138
|
|
-// report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
|
139
|
|
-// })
|
140
|
|
-// .then((resp) => {
|
141
|
|
-// report(<Assert key="response data should be correct event with progress listener"
|
142
|
|
-// expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
|
143
|
|
-// done()
|
144
|
|
-// })
|
145
|
|
-//
|
146
|
|
-// })
|
147
|
|
-
|
148
|
|
-// FIXME : not yet supported
|
149
|
|
-ctx.describe('Large file download test', (report, done) => {
|
150
|
|
- let received = 0
|
151
|
|
- // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
|
152
|
|
- // Authorization : 'Bearer abde123eqweje'
|
153
|
|
- // })
|
154
|
|
- // .then((resp) => {
|
155
|
|
- report(<Assert key="not supported" expect={true} actual={false}/>)
|
156
|
|
- done()
|
157
|
|
- // })
|
158
|
|
-
|
159
|
|
-})
|
160
|
|
-
|
161
|
|
-// added after 0.5.0
|
162
|
|
-
|
163
|
|
-ctx.describe('Get storage folders', (report, done) => {
|
164
|
|
-
|
165
|
|
- RNFetchBlob.getSystemDirs().then((dirs) => {
|
166
|
|
- report(
|
167
|
|
- <Assert key="system folders should exists" expect={dirs} comparer={Comparer.exists} />,
|
168
|
|
- <Assert key="check properties"
|
169
|
|
- expect={dirs}
|
170
|
|
- comparer={Comparer.hasProperties}
|
171
|
|
- actual={['PictureDir', 'MovieDir', 'DocumentDir', 'CacheDir']}
|
172
|
|
- />,
|
173
|
|
- <Info key="System Folders">
|
174
|
|
- <Text>{`${JSON.stringify(dirs)}`}</Text>
|
175
|
|
- </Info>
|
176
|
|
- )
|
177
|
|
- done()
|
178
|
|
- })
|
179
|
|
-
|
180
|
|
-})
|
181
|
|
-
|
182
|
|
-let tmpFilePath = null
|
183
|
|
-
|
184
|
|
-ctx.describe('Download file to storage with custom file extension', (report, done) => {
|
185
|
|
-
|
186
|
|
- RNFetchBlob.config({
|
187
|
|
- fileCache : true,
|
188
|
|
- appendExt : 'png'
|
189
|
|
- })
|
190
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
191
|
|
- .then((resp) => {
|
192
|
|
- tmpFilePath = resp.path()
|
193
|
|
- report(<Info key={`image from ${tmpFilePath}`}>
|
194
|
|
- <Image source={{ uri : tmpFilePath}} style={styles.image}/>
|
195
|
|
- </Info>)
|
196
|
|
- done()
|
197
|
|
- })
|
198
|
|
-})
|
199
|
|
-
|
200
|
|
-ctx.describe('Read cached file via file stream', (report, done) => {
|
201
|
|
- let data = 'data:image/png;base64, '
|
202
|
|
- let stream = RNFetchBlob.openReadStream(tmpFilePath, 'base64')
|
203
|
|
- stream.onData((chunk) => {
|
204
|
|
- data += chunk
|
205
|
|
- })
|
206
|
|
- stream.onEnd(() => {
|
207
|
|
- report(
|
208
|
|
- <Assert key="image should have value" expect={0} comparer={Comparer.smaller} actual={data.length}/>,
|
209
|
|
- <Info key="image from read stream">
|
210
|
|
- <Image source={{uri : data}} style={styles.image}/>
|
211
|
|
- </Info>)
|
212
|
|
- done()
|
213
|
|
- })
|
214
|
|
- stream.onError((err) => {
|
215
|
|
- console.log('stream err', err)
|
216
|
|
- })
|
217
|
|
-
|
218
|
|
-})
|
219
|
|
-
|
220
|
|
-ctx.describe('File stream reader error should be able to handled', (report, done) => {
|
221
|
|
-
|
222
|
|
- let stream = RNFetchBlob.openReadStream('^_^ not exists', 'base64')
|
223
|
|
- stream.onError((err) => {
|
224
|
|
- report(<Info key="error message">
|
225
|
|
- <Text>
|
226
|
|
- {err}
|
227
|
|
- </Text>
|
228
|
|
- </Info>)
|
229
|
|
- done()
|
230
|
|
-
|
231
|
|
- })
|
232
|
|
-
|
233
|
|
-})
|
234
|
|
-
|
235
|
|
-export default ctx
|