No Description

test-0.10.2.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import _ from 'lodash'
  4. import RNFetchBlob from 'react-native-fetch-blob'
  5. import {
  6. StyleSheet,
  7. Text,
  8. View,
  9. ScrollView,
  10. Linking,
  11. Platform,
  12. Dimensions,
  13. BackAndroid,
  14. AsyncStorage,
  15. Image,
  16. } from 'react-native';
  17. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  18. window.Blob = RNFetchBlob.polyfill.Blob
  19. const JSONStream = RNFetchBlob.JSONStream
  20. const fs = RNFetchBlob.fs
  21. const { Assert, Comparer, Info, prop } = RNTest
  22. const describe = RNTest.config({
  23. group : '0.10.2',
  24. run : true,
  25. expand : true,
  26. timeout : 20000,
  27. })
  28. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  29. const dirs = RNFetchBlob.fs.dirs
  30. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  31. let begin = Date.now()
  32. describe('#227 IOS file modification date correctness', (report, done) => {
  33. let path = dirs.DocumentDir + '/issue-223-' + Date.now()
  34. fs.createFile(path, 'datafornow')
  35. .then(() => fs.stat(path))
  36. .then((stat) => {
  37. let date = stat.lastModified;
  38. console.log(date, stat);
  39. let correct = date/Date.now() > 0.95 || date/Date.now() < 1.05;
  40. report(<Assert key="modification date should be correct"
  41. expect={true} actual={correct}/>);
  42. done()
  43. })
  44. })
  45. describe('#230 add and option for setting if the request follow redirect or not', (report, done) => {
  46. RNFetchBlob
  47. .config({ followRedirect : false })
  48. .fetch('GET',`${TEST_SERVER_URL}/redirect`)
  49. .then((res) => {
  50. console.log(res.data)
  51. report(<Assert key="should not redirect twice" expect={1} actual={res.info().redirects.length}/>);
  52. done()
  53. })
  54. })
  55. describe('#240 openDocument does not support file URI', (report, done) => {
  56. RNFetchBlob
  57. .config({ fileCache : true })
  58. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  59. .then((res) => {
  60. RNFetchBlob.ios.openDocument(res.path())
  61. .then(() => {
  62. done();
  63. })
  64. })
  65. })
  66. describe('#241 null header silent failed issue', (report, done) => {
  67. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
  68. foo : null
  69. })
  70. .then(() => {
  71. done()
  72. })
  73. })