Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. TouchableOpacity,
  13. } from 'react-native';
  14. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  15. window.Blob = RNFetchBlob.polyfill.Blob
  16. const fs = RNFetchBlob.fs
  17. const { Assert, Comparer, Info, prop } = RNTest
  18. const describe = RNTest.config({
  19. group : '0.9.5',
  20. run : true,
  21. expand : false,
  22. timeout : 20000,
  23. })
  24. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  25. const dirs = RNFetchBlob.fs.dirs
  26. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  27. // describe('issue #122 force response data format', (report, done) => {
  28. //
  29. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`, {
  30. // 'RNFB-Response' : 'base64'
  31. // })
  32. // .then((res) => {
  33. // let r = RNFetchBlob.base64.decode(res.data)
  34. // report(
  35. // <Assert key="test data verify" expect="fetchblob-dev" actual={JSON.parse(r).name}/>,
  36. // <Assert key="should successfully decode the data" expect={true} actual={true}/>)
  37. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/json-dummy.json`)
  38. // })
  39. // .then((res) => {
  40. // report(
  41. // <Assert key="response should in format of plain-text" expect="fetchblob-dev" actual={JSON.parse(res.data).name}/>)
  42. // done()
  43. // })
  44. // .catch(() => {
  45. // report(
  46. // <Assert key="Should successfully decode the data" expect={true} actual={false}/>)
  47. // done()
  48. // })
  49. //
  50. // })
  51. // describe('#129 memory leaking when enable uploadProgress', (report, done) => {
  52. //
  53. // let file = null
  54. // let count = 0
  55. //
  56. // RNFetchBlob.config({ fileCache : true })
  57. // .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
  58. // .then((res) => {
  59. // file = res.path()
  60. // setTimeout(() => {
  61. // for(let i=0;i<20;i++){
  62. // RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload`, {}, RNFetchBlob.wrap(file))
  63. // .uploadProgress(() => {})
  64. // .then(() => {
  65. // if(count > 20) {
  66. // fs.unlink(file)
  67. // report(<Assert key="finished" expect={true} actual={true}/>)
  68. // done()
  69. // }
  70. // })
  71. // }
  72. // }, 3000)
  73. // })
  74. //
  75. // })
  76. describe('#131 status code != 200 should not throw an error', (report, done) => {
  77. let count = 0
  78. let codes = [404, 500, 501, 403]
  79. codes.forEach((code) => {
  80. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/xhr-code/${code}`, {
  81. 'Cache-Control' : 'no-store'
  82. })
  83. .then(function(res) {
  84. report(<Assert key={`status code should be ${this}`} expect={Math.floor(this)} actual={Math.floor(res.info().status)}/>)
  85. count ++
  86. if(count >= 4)
  87. done()
  88. }.bind(code))
  89. .catch(function(err) {
  90. report(<Assert key={`status code ${this} should not cause error`} expect={true} actual={false}/>)
  91. count++
  92. }.bind(code))
  93. })
  94. })