|
| 1 | +import RNTest from './react-native-testkit/' |
| 2 | +import React from 'react' |
| 3 | +import RNFetchBlob from 'react-native-fetch-blob' |
| 4 | + |
| 5 | +import { |
| 6 | + StyleSheet, |
| 7 | + Text, |
| 8 | + View, |
| 9 | + ScrollView, |
| 10 | + Platform, |
| 11 | + Dimensions, |
| 12 | + Image, |
| 13 | +} from 'react-native'; |
| 14 | + |
| 15 | +const fs = RNFetchBlob.fs |
| 16 | +const { Assert, Comparer, Info, prop } = RNTest |
| 17 | +const describe = RNTest.config({ |
| 18 | + group : '0.5.2', |
| 19 | + run : true, |
| 20 | + expand : false, |
| 21 | +}) |
| 22 | +const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop() |
| 23 | + |
| 24 | +let prefix = ((Platform.OS === 'android') ? 'file://' : '') |
| 25 | + |
| 26 | + |
| 27 | +describe('GET request with params', (report, done) => { |
| 28 | + let time = Date.now() |
| 29 | + RNFetchBlob.config({ fileCache : true }) |
| 30 | + .fetch('GET', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) |
| 31 | + .then((resp) => { |
| 32 | + let file = resp.path() |
| 33 | + return RNFetchBlob.fs.readStream(resp.path(), 'utf8') |
| 34 | + }) |
| 35 | + .then((stream) => { |
| 36 | + let result = '' |
| 37 | + stream.open() |
| 38 | + stream.onData((chunk) => { |
| 39 | + result += chunk |
| 40 | + }) |
| 41 | + stream.onEnd(() => { |
| 42 | + result = JSON.parse(result) |
| 43 | + report(<Assert key="param#1 should correct" |
| 44 | + expect={parseInt(time)} |
| 45 | + actual={parseInt(result.time)}/>, |
| 46 | + <Assert key="param#2 should correct" |
| 47 | + expect={'RNFetchBlobParams'} |
| 48 | + actual={result.name}/>, |
| 49 | + <Assert key="param contains unicode data should correct" |
| 50 | + expect={'中文'} |
| 51 | + actual={result.lang}/>) |
| 52 | + done() |
| 53 | + }) |
| 54 | + }) |
| 55 | +}) |
| 56 | + |
| 57 | + |
| 58 | +describe('POST request with params', (report, done) => { |
| 59 | + let time = Date.now() |
| 60 | + RNFetchBlob.config({ fileCache : true }) |
| 61 | + .fetch('POST', `${TEST_SERVER_URL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) |
| 62 | + .then((resp) => { |
| 63 | + let file = resp.path() |
| 64 | + return RNFetchBlob.fs.readStream(resp.path(), 'utf8') |
| 65 | + }) |
| 66 | + .then((stream) => { |
| 67 | + let result = '' |
| 68 | + stream.open() |
| 69 | + stream.onData((chunk) => { |
| 70 | + result += chunk |
| 71 | + }) |
| 72 | + stream.onEnd(() => { |
| 73 | + result = JSON.parse(result) |
| 74 | + report(<Assert key="param#1 should correct" |
| 75 | + expect={parseInt(time)} |
| 76 | + actual={parseInt(result.time)}/>, |
| 77 | + <Assert key="param#2 should correct" |
| 78 | + expect={'RNFetchBlobParams'} |
| 79 | + actual={result.name}/>, |
| 80 | + <Assert key="param contains unicode data should correct" |
| 81 | + expect={'中文'} |
| 82 | + actual={result.lang}/>) |
| 83 | + done() |
| 84 | + }) |
| 85 | + }) |
| 86 | +}) |
0 commit comments