123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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.5.2',
- run : true,
- expand : false,
- })
- const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
-
- let prefix = ((Platform.OS === 'android') ? 'file://' : '')
-
-
- describe('GET request with params', (report, done) => {
- let time = Date.now()
- RNFetchBlob.config({ fileCache : true })
- .fetch('GET', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
- .then((resp) => {
- let file = resp.path()
- return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
- })
- .then((stream) => {
- let result = ''
- stream.open()
- stream.onData((chunk) => {
- result += chunk
- })
- stream.onEnd(() => {
- result = JSON.parse(result)
- report(<Assert key="param#1 should correct"
- expect={parseInt(time)}
- actual={parseInt(result.time)}/>,
- <Assert key="param#2 should correct"
- expect={'RNFetchBlobParams'}
- actual={result.name}/>,
- <Assert key="param contains unicode data should correct"
- expect={'中文'}
- actual={result.lang}/>)
- done()
- })
- })
- })
-
-
- describe('POST request with params', (report, done) => {
- let time = Date.now()
- RNFetchBlob.config({ fileCache : true })
- .fetch('POST', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`, {}, RNFetchBlob.base64.encode('123'))
- .then((resp) => {
- let file = resp.path()
- return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
- })
- .then((stream) => {
- let result = ''
- stream.open()
- stream.onData((chunk) => {
- result += chunk
- })
- stream.onEnd(() => {
- result = JSON.parse(result)
- report(<Assert key="param#1 should correct"
- expect={parseInt(time)}
- actual={parseInt(result.time)}/>,
- <Assert key="param#2 should correct"
- expect={'RNFetchBlobParams'}
- actual={result.name}/>,
- <Assert key="param contains unicode data should correct"
- expect={'中文'}
- actual={result.lang}/>)
- done()
- })
- })
- })
|