Sin descripción

test-0.9.4.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import {
  5. StyleSheet,
  6. Text,
  7. View,
  8. ScrollView,
  9. Platform,
  10. Dimensions,
  11. Image,
  12. } from 'react-native';
  13. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  14. window.Blob = RNFetchBlob.polyfill.Blob
  15. const fs = RNFetchBlob.fs
  16. const { Assert, Comparer, Info, prop } = RNTest
  17. const describe = RNTest.config({
  18. group : '0.9.4',
  19. run : true,
  20. expand : true,
  21. timeout : 20000,
  22. })
  23. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  24. const dirs = RNFetchBlob.fs.dirs
  25. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  26. describe('issue #105', (report, done) => {
  27. let tmp = null
  28. RNFetchBlob
  29. .config({ fileCache : true })
  30. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  31. .then((res) => {
  32. tmp = res.path()
  33. return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
  34. 'Content-Type' : 'multipart/form-data',
  35. 'Expect' : '100-continue'
  36. }, [
  37. { name : 'data', data : 'issue#105 test' },
  38. { name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
  39. ])
  40. })
  41. .then((res) => {
  42. done()
  43. })
  44. })
  45. describe('issue #106', (report, done) => {
  46. fetch('https://rnfb-test-app.firebaseapp.com/6m-json.json')
  47. .then((res) => {
  48. console.log('## converted')
  49. return res.json()
  50. })
  51. .then((data) => {
  52. // console.log(data)
  53. report(<Assert key="fetch request success" expect={20000} actual={data.total}/>)
  54. done()
  55. })
  56. })
  57. describe('issue #111 get redirect destination', (report, done) => {
  58. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
  59. .then((res) => {
  60. report(
  61. <Assert key="redirect history should tracable"
  62. expect={2}
  63. actual={res.info().redirects.length}/>,
  64. <Assert key="redirect history verify"
  65. expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`]}
  66. comparer={Comparer.equalToArray}
  67. actual={res.info().redirects}/>,
  68. )
  69. done()
  70. })
  71. })