import RNTest from './react-native-testkit/'
import React from 'react'
import RNFetchBlob from 'react-native-fetch-blob'
import {
StyleSheet,
Text,
View,
ScrollView,
Platform,
Dimensions,
Image,
} from 'react-native';
const fs = RNFetchBlob.fs
const { Assert, Comparer, Info, prop } = RNTest
const describe = RNTest.config({
group : '0.8.0',
run : true,
expand : true,
timeout : 10000,
})
const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
const dirs = RNFetchBlob.fs.dirs
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
describe('fs URI encoding support', (report, done) => {
let testData1 = `test date write file from file ${Date.now()}`
let testData2 = `test date write file from file ${Date.now()*Math.random()}`
let file1 = dirs.DocumentDir + '/testFiletFile1' + Date.now()
let file2 = dirs.DocumentDir + '/testFiletFile2' + Date.now()
let init = [fs.createFile(file1, testData1, 'utf8'),
fs.createFile(file2, testData2, 'utf8')]
Promise.all(init)
.then(() => fs.appendFile(file1, file2, 'uri'))
.then(() => fs.readFile(file1, 'utf8'))
.then((data) => {
report(
)
return fs.writeFile(file1, file2, 'uri')
})
.then(() => fs.readFile(file1, 'utf8'))
.then((data) => {
report(
)
done()
})
})
describe('request timeout working properly', (report, done) => {
RNFetchBlob.config({ timeout : 1000 })
.fetch('GET', `${TEST_SERVER_URL}/timeout`)
.then(() => {
report(
)
done()
})
.catch((err) => {
report(
)
done()
})
})
describe('regular request should have correct body', (report, done) => {
RNFetchBlob
.fetch('POST', `${TEST_SERVER_URL}/echo`, {
'content-type' : 'text/foo',
foo : 'bar'
}, 'foo is bar')
.then((res) => {
report(
,
,
)
done()
})
})
describe('automatic content conversion test', (report, done) => {
let expect1 = `test-alpha-${Date.now()}`
let expect2 = `test-beta-${Date.now()}`
RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {
'Content-Type' : 'application/octet-foo',
}, RNFetchBlob.base64.encode(expect1))
.then((res) => {
report(
)
return fs.writeFile(dirs.DocumentDir + '/test-0.8.0-auto', expect2, 'utf8')
})
.then(() => RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {
/* what ever the header is */
}, RNFetchBlob.wrap(dirs.DocumentDir + '/test-0.8.0-auto')))
.then((resp) => {
report(
)
done()
})
})
function getASCIIArray(str) {
let r = []
for(let i=0;i