Nenhuma descrição

test-0.6.0.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. const fs = RNFetchBlob.fs
  14. const { Assert, Comparer, Info, prop } = RNTest
  15. const describe = RNTest.config({
  16. group : '0.6.0',
  17. run : true,
  18. expand : false,
  19. timeout : 10000,
  20. })
  21. const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  22. const dirs = RNFetchBlob.fs.dirs
  23. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  24. describe('writeFile and readFile test', (report, done) => {
  25. let path = dirs.DocumentDir + '/0.6.0-'+Date.now()+'/writeFileTest'+Date.now()
  26. let data = 'hellofrom'+Date.now()
  27. fs.writeFile(path, data)
  28. .then(() => fs.readFile(path, 'utf8'))
  29. .then((actual) => {
  30. report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>)
  31. data += 'base64'
  32. return fs.writeFile(path, RNFetchBlob.base64.encode('base64'), 'base64')
  33. })
  34. .then(() => fs.readFile(path, 'base64'))
  35. .then((actual) => {
  36. report(<Assert key="base64 content should correct"
  37. expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))}
  38. actual={RNFetchBlob.base64.decode(actual)}/>)
  39. data += 'ascii'
  40. return fs.writeFile(path, getASCIIArray('ascii'), 'ascii');
  41. })
  42. .then(() => fs.readFile(path, 'ascii'))
  43. .then((actual) => {
  44. report(<Assert key="ascii content should correct"
  45. expect={getASCIIArray(data)}
  46. comparer={Comparer.equalToArray}
  47. actual={actual}/>)
  48. done()
  49. })
  50. })
  51. describe('append file test', (report, done) => {
  52. // TODO
  53. })
  54. function getASCIIArray(str) {
  55. let r = []
  56. for(let i=0;i<str.length;i++) {
  57. r.push(str[i].charCodeAt(0))
  58. }
  59. return r
  60. }