Nav apraksta

test-0.6.0.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 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. function getASCIIArray(str) {
  52. let r = []
  53. for(let i=0;i<str.length;i++) {
  54. r.push(str[i].charCodeAt(0))
  55. }
  56. return r
  57. }