Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 42a4615

Browse files
committed
Change android test cases
1 parent a1b9dcc commit 42a4615

File tree

1 file changed

+145
-145
lines changed

1 file changed

+145
-145
lines changed

test/test-android.js

Lines changed: 145 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -28,151 +28,151 @@ let prefix = ((Platform.OS === 'android') ? 'file://' : '')
2828
let tmpFilePath = null
2929
const dirs = RNFetchBlob.fs.dirs
3030

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-
// // #75
152-
// describe('APK downloaded from Download Manager should correct', (report, done) => {
153-
//
154-
// let url = null
155-
//
156-
// RNFetchBlob.config({
157-
// addAndroidDownloads : {
158-
// useDownloadManager : true,
159-
// title : 'test-APK',
160-
// description : 'apk install file',
161-
// mime : 'application/vnd.android.package-archive',
162-
// mediaScannable : true,
163-
// notification : true,
164-
// }
165-
// })
166-
// .fetch('GET', `${TEST_SERVER_URL}/public/apk-dummy.apk`)
167-
// .then((res) => {
168-
// let sendIntent = RNFetchBlob.android.actionViewIntent
169-
// return sendIntent(res.path(), 'application/vnd.android.package-archive')
170-
// })
171-
// .then(() => {
172-
// done()
173-
// })
174-
//
175-
// })
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+
// #75
152+
describe('APK downloaded from Download Manager should correct', (report, done) => {
153+
154+
let url = null
155+
156+
RNFetchBlob.config({
157+
addAndroidDownloads : {
158+
useDownloadManager : true,
159+
title : 'test-APK',
160+
description : 'apk install file',
161+
mime : 'application/vnd.android.package-archive',
162+
mediaScannable : true,
163+
notification : true,
164+
}
165+
})
166+
.fetch('GET', `${TEST_SERVER_URL}/public/apk-dummy.apk`)
167+
.then((res) => {
168+
let sendIntent = RNFetchBlob.android.actionViewIntent
169+
return sendIntent(res.path(), 'application/vnd.android.package-archive')
170+
})
171+
.then(() => {
172+
done()
173+
})
174+
175+
})
176176

177177
// issue #74
178178
describe('download file to specific location using DownloadManager', (report, done) => {

0 commit comments

Comments
 (0)