|
@@ -28,126 +28,126 @@ let prefix = ((Platform.OS === 'android') ? 'file://' : '')
|
28
|
28
|
let tmpFilePath = null
|
29
|
29
|
const dirs = RNFetchBlob.fs.dirs
|
30
|
30
|
|
31
|
|
-describe('Download with notification', (report, done) => {
|
32
|
|
- let filePath = null
|
33
|
|
- let filename = `test-${Date.now()}.png`
|
34
|
|
-
|
35
|
|
- filePath = `${dirs.DownloadDir}/${filename}`
|
36
|
|
- RNFetchBlob.config({
|
37
|
|
- path : filePath,
|
38
|
|
- addAndroidDownloads : {
|
39
|
|
- title : 'RNFetchBlob test download success',
|
40
|
|
- description : `File description added by RNFetchblob`,
|
41
|
|
- mediaScannable : true,
|
42
|
|
- mime : "image/png",
|
43
|
|
- notification : true
|
44
|
|
- }
|
45
|
|
- })
|
46
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
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
|
|
-})
|
58
|
|
-
|
59
|
|
-describe('MediaScanner tests ', (report, done) => {
|
60
|
|
- let filename = `scannable-test-${Date.now()}.png`
|
61
|
|
- let filePath = `${dirs.DownloadDir}/${filename}`
|
62
|
|
- RNFetchBlob.config({
|
63
|
|
- path : filePath,
|
64
|
|
- })
|
65
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
66
|
|
- .then((resp) => {
|
67
|
|
- tmpFilePath = resp.path()
|
68
|
|
- return RNFetchBlob.fs.scanFile([
|
69
|
|
- { path:resp.path() }
|
70
|
|
- ])
|
71
|
|
- })
|
72
|
|
- .then(() => {
|
73
|
|
- report(<Assert key={`scan image success, there should be a new file in Picture app named "${filename}"`} expect={true} actual={true}/>)
|
74
|
|
- return RNFetchBlob
|
75
|
|
- .config({
|
76
|
|
- path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
|
77
|
|
- })
|
78
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
|
79
|
|
- })
|
80
|
|
- .then((resp) => {
|
81
|
|
- fs.scanFile([{
|
82
|
|
- path : resp.path()
|
83
|
|
- }])
|
84
|
|
- .then(() => {
|
85
|
|
- report(<Assert
|
86
|
|
- key={`scan mp3 file success, there exist a new file named "beethoven-${Date.now()}.mp3" in Music app`}
|
87
|
|
- expect={true}
|
88
|
|
- actual={true}/>)
|
89
|
|
- done()
|
90
|
|
- })
|
91
|
|
- })
|
92
|
|
-
|
93
|
|
-})
|
94
|
|
-
|
95
|
|
-describe('android download manager', (report, done) => {
|
96
|
|
- RNFetchBlob.config({
|
97
|
|
- addAndroidDownloads : {
|
98
|
|
- useDownloadManager : true,
|
99
|
|
- title : 'RNFetchBlob test download manager test',
|
100
|
|
- description : `File description added by RNFetchblob`,
|
101
|
|
- mediaScannable : true,
|
102
|
|
- notification : true
|
103
|
|
- }
|
104
|
|
- })
|
105
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`).then((resp) => {
|
106
|
|
- report(
|
107
|
|
- <Assert key="download manager complete handler" expect={true} actual={true}/>
|
108
|
|
- )
|
109
|
|
- return resp.readStream('ascii')
|
110
|
|
- })
|
111
|
|
- .then((stream) => {
|
112
|
|
- stream.open();
|
113
|
|
- let len = 0
|
114
|
|
- stream.onData((chunk) => {
|
115
|
|
- len += chunk.length
|
116
|
|
- })
|
117
|
|
- stream.onEnd(() => {
|
118
|
|
- report(
|
119
|
|
- <Assert key="download manager URI is readable"
|
120
|
|
- expect={len}
|
121
|
|
- comparer={Comparer.greater}
|
122
|
|
- actual={0}/>
|
123
|
|
- )
|
124
|
|
- done()
|
125
|
|
- })
|
126
|
|
- })
|
127
|
|
-})
|
128
|
|
-
|
129
|
|
-describe('open a file from intent', (report, done) => {
|
130
|
|
- let url = null
|
131
|
|
- RNFetchBlob.config({
|
132
|
|
- addAndroidDownloads : {
|
133
|
|
- useDownloadManager : true,
|
134
|
|
- title : 'test-image',
|
135
|
|
- description : 'open it from intent !',
|
136
|
|
- mime : 'image/png',
|
137
|
|
- mediaScannable : true,
|
138
|
|
- notification : true,
|
139
|
|
- }
|
140
|
|
- })
|
141
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
142
|
|
- .then((res) => {
|
143
|
|
- let sendIntent = RNFetchBlob.android.actionViewIntent
|
144
|
|
- return sendIntent(res.path(), 'image/png')
|
145
|
|
- })
|
146
|
|
- .then(() => {
|
147
|
|
- done()
|
148
|
|
- })
|
149
|
|
-})
|
150
|
|
-
|
|
31
|
+// describe('Download with notification', (report, done) => {
|
|
32
|
+// let filePath = null
|
|
33
|
+// let filename = `test-${Date.now()}.png`
|
|
34
|
+//
|
|
35
|
+// filePath = `${dirs.DownloadDir}/${filename}`
|
|
36
|
+// RNFetchBlob.config({
|
|
37
|
+// path : filePath,
|
|
38
|
+// addAndroidDownloads : {
|
|
39
|
+// title : 'RNFetchBlob test download success',
|
|
40
|
+// description : `File description added by RNFetchblob`,
|
|
41
|
+// mediaScannable : true,
|
|
42
|
+// mime : "image/png",
|
|
43
|
+// notification : true
|
|
44
|
+// }
|
|
45
|
+// })
|
|
46
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
|
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
|
+// })
|
|
58
|
+//
|
|
59
|
+// describe('MediaScanner tests ', (report, done) => {
|
|
60
|
+// let filename = `scannable-test-${Date.now()}.png`
|
|
61
|
+// let filePath = `${dirs.DownloadDir}/${filename}`
|
|
62
|
+// RNFetchBlob.config({
|
|
63
|
+// path : filePath,
|
|
64
|
+// })
|
|
65
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
|
66
|
+// .then((resp) => {
|
|
67
|
+// tmpFilePath = resp.path()
|
|
68
|
+// return RNFetchBlob.fs.scanFile([
|
|
69
|
+// { path:resp.path() }
|
|
70
|
+// ])
|
|
71
|
+// })
|
|
72
|
+// .then(() => {
|
|
73
|
+// report(<Assert key={`scan image success, there should be a new file in Picture app named "${filename}"`} expect={true} actual={true}/>)
|
|
74
|
+// return RNFetchBlob
|
|
75
|
+// .config({
|
|
76
|
+// path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
|
|
77
|
+// })
|
|
78
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
|
|
79
|
+// })
|
|
80
|
+// .then((resp) => {
|
|
81
|
+// fs.scanFile([{
|
|
82
|
+// path : resp.path()
|
|
83
|
+// }])
|
|
84
|
+// .then(() => {
|
|
85
|
+// report(<Assert
|
|
86
|
+// key={`scan mp3 file success, there exist a new file named "beethoven-${Date.now()}.mp3" in Music app`}
|
|
87
|
+// expect={true}
|
|
88
|
+// actual={true}/>)
|
|
89
|
+// done()
|
|
90
|
+// })
|
|
91
|
+// })
|
|
92
|
+//
|
|
93
|
+// })
|
|
94
|
+//
|
|
95
|
+// describe('android download manager', (report, done) => {
|
|
96
|
+// RNFetchBlob.config({
|
|
97
|
+// addAndroidDownloads : {
|
|
98
|
+// useDownloadManager : true,
|
|
99
|
+// title : 'RNFetchBlob test download manager test',
|
|
100
|
+// description : `File description added by RNFetchblob`,
|
|
101
|
+// mediaScannable : true,
|
|
102
|
+// notification : true
|
|
103
|
+// }
|
|
104
|
+// })
|
|
105
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`).then((resp) => {
|
|
106
|
+// report(
|
|
107
|
+// <Assert key="download manager complete handler" expect={true} actual={true}/>
|
|
108
|
+// )
|
|
109
|
+// return resp.readStream('ascii')
|
|
110
|
+// })
|
|
111
|
+// .then((stream) => {
|
|
112
|
+// stream.open();
|
|
113
|
+// let len = 0
|
|
114
|
+// stream.onData((chunk) => {
|
|
115
|
+// len += chunk.length
|
|
116
|
+// })
|
|
117
|
+// stream.onEnd(() => {
|
|
118
|
+// report(
|
|
119
|
+// <Assert key="download manager URI is readable"
|
|
120
|
+// expect={len}
|
|
121
|
+// comparer={Comparer.greater}
|
|
122
|
+// actual={0}/>
|
|
123
|
+// )
|
|
124
|
+// done()
|
|
125
|
+// })
|
|
126
|
+// })
|
|
127
|
+// })
|
|
128
|
+//
|
|
129
|
+// describe('open a file from intent', (report, done) => {
|
|
130
|
+// let url = null
|
|
131
|
+// RNFetchBlob.config({
|
|
132
|
+// addAndroidDownloads : {
|
|
133
|
+// useDownloadManager : true,
|
|
134
|
+// title : 'test-image',
|
|
135
|
+// description : 'open it from intent !',
|
|
136
|
+// mime : 'image/png',
|
|
137
|
+// mediaScannable : true,
|
|
138
|
+// notification : true,
|
|
139
|
+// }
|
|
140
|
+// })
|
|
141
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
|
142
|
+// .then((res) => {
|
|
143
|
+// let sendIntent = RNFetchBlob.android.actionViewIntent
|
|
144
|
+// return sendIntent(res.path(), 'image/png')
|
|
145
|
+// })
|
|
146
|
+// .then(() => {
|
|
147
|
+// done()
|
|
148
|
+// })
|
|
149
|
+// })
|
|
150
|
+//
|
151
|
151
|
// #75
|
152
|
152
|
describe('APK downloaded from Download Manager should correct', (report, done) => {
|
153
|
153
|
|
|
@@ -175,25 +175,25 @@ describe('APK downloaded from Download Manager should correct', (report, done) =
|
175
|
175
|
})
|
176
|
176
|
|
177
|
177
|
// issue #74
|
178
|
|
-describe('download file to specific location using DownloadManager', (report, done) => {
|
179
|
|
- let dest = dirs.DCIMDir + '/android-download-test-' +Date.now() + '.png'
|
180
|
|
- RNFetchBlob.config({
|
181
|
|
- addAndroidDownloads : {
|
182
|
|
- useDownloadManager : true,
|
183
|
|
- path : dest,
|
184
|
|
- mime : 'image/png',
|
185
|
|
- title : 'android-download-path-test.png',
|
186
|
|
- description : 'download to specific path #74'
|
187
|
|
- }
|
188
|
|
- })
|
189
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
190
|
|
- .then((res) => fs.stat(res.path()))
|
191
|
|
- .then((stat) => {
|
192
|
|
- report(
|
193
|
|
- <Assert key="file exists at the path"
|
194
|
|
- expect={true} actual={true}/>,
|
195
|
|
- <Assert key="file size correct"
|
196
|
|
- expect="23975" actual={stat.size}/>)
|
197
|
|
- done()
|
198
|
|
- })
|
199
|
|
-})
|
|
178
|
+// describe('download file to specific location using DownloadManager', (report, done) => {
|
|
179
|
+// let dest = dirs.DCIMDir + '/android-download-test-' +Date.now() + '.png'
|
|
180
|
+// RNFetchBlob.config({
|
|
181
|
+// addAndroidDownloads : {
|
|
182
|
+// useDownloadManager : true,
|
|
183
|
+// path : dest,
|
|
184
|
+// mime : 'image/png',
|
|
185
|
+// title : 'android-download-path-test.png',
|
|
186
|
+// description : 'download to specific path #74'
|
|
187
|
+// }
|
|
188
|
+// })
|
|
189
|
+// .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
|
190
|
+// .then((res) => fs.stat(res.path()))
|
|
191
|
+// .then((stat) => {
|
|
192
|
+// report(
|
|
193
|
+// <Assert key="file exists at the path"
|
|
194
|
+// expect={true} actual={true}/>,
|
|
195
|
+// <Assert key="file size correct"
|
|
196
|
+// expect="23975" actual={stat.size}/>)
|
|
197
|
+// done()
|
|
198
|
+// })
|
|
199
|
+// })
|