import RNTest from './react-native-testkit/'
import React from 'react'
import RNFetchBlob from 'react-native-fetch-blob'
import {
AppRegistry,
StyleSheet,
Text,
View,
Platform,
ScrollView,
Dimensions,
Image,
} from 'react-native';
const FILENAME = `${Platform.OS}-0.4.2-${Date.now()}.png`
// paste your test config here
const TEST_SERVER_URL = 'http://192.168.17.193:8123'
const DROPBOX_TOKEN = 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4'
const ctx = new RNTest.TestContext()
const Assert = RNTest.Assert
const Info = RNTest.Info
let image = null
ctx.describe('GET image from server', async function(report) {
let resp = await RNFetchBlob
.fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
Authorization : 'Bearer abde123eqweje'
})
image = resp.base64()
report(
)
})
ctx.describe('The check if it follows 301/302 redirection', async function(report) {
let resp = await RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
report(
,
)
})
ctx.describe('Upload octet-stream image to Dropbox', async function(report) {
let resp = await RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
Authorization : `Bearer ${DROPBOX_TOKEN}`,
'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
'Content-Type' : 'application/octet-stream',
}, image)
resp = resp.json()
report(
)
})
ctx.describe('Upload multipart/form-data', async function(report, data) {
let resp = await RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
'Content-Type' : 'multipart/form-data',
}, [
{ name : 'test-img', filename : 'test-img.png', data: image},
{ name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
{ name : 'field1', data : 'hello !!'},
{ name : 'field2', data : 'hello2 !!'}
])
resp = resp.json()
report(
,
,
)
})
ctx.describe('Compare uploaded multipart image', async function(report) {
let resp = await RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
let resp2 = await RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
report(
,
)
})
ctx.describe('Progress report test', (report) => new Promise((resolve) => {
let received = 0
let p1 = RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
Authorization : 'Bearer abde123eqweje'
})
// .progress((written, total) => {
// // report()
// if(written === total)
// report()
// })
.then((resp) => {
report()
resolve()
})
}))
export default ctx