Brak opisu

test-android.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 : 'Android only functions',
  17. run : Platform.OS === 'android',
  18. expand : false,
  19. })
  20. const { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles } = prop()
  21. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  22. // Android only tests
  23. let tmpFilePath = null
  24. describe('Download with notification', (report, done) => {
  25. let filePath = null
  26. let filename = `test-${Date.now()}.png`
  27. RNFetchBlob.fs.getSystemDirs().then((dirs) => {
  28. filePath = `${dirs.DownloadDir}/${filename}`
  29. return RNFetchBlob.config({
  30. path : filePath,
  31. addAndroidDownloads : {
  32. title : 'RNFetchBlob test download success',
  33. description : `File description added by RNFetchblob`,
  34. mediaScannable : true,
  35. mime : "image/png",
  36. notification : true
  37. }
  38. })
  39. .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
  40. })
  41. .then((resp) => {
  42. tmpFilePath = resp.path()
  43. report(<Info key={`image from ${tmpFilePath}`}>
  44. <Image
  45. source={{ uri : prefix + tmpFilePath}}
  46. style={styles.image}/>
  47. </Info>)
  48. done()
  49. })
  50. })
  51. describe('MediaScanner tests ', (report, done) => {
  52. let filePath = null
  53. let filename = `scannable-test-${Date.now()}.png`
  54. let dirs = null
  55. RNFetchBlob.fs.getSystemDirs().then((resp) => {
  56. dirs = resp
  57. filePath = `${dirs.DownloadDir}/${filename}`
  58. return RNFetchBlob.config({
  59. path : filePath,
  60. })
  61. .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
  62. })
  63. .then((resp) => {
  64. tmpFilePath = resp.path()
  65. return RNFetchBlob.fs.scanFile([
  66. { path:resp.path() }
  67. ])
  68. .then(() => {
  69. report(<Assert key="scan success" expect={true} actual={true}/>)
  70. return RNFetchBlob
  71. .config({
  72. path : dirs.DCIMDir + '/beethoven-'+ Date.now() +'.mp3'
  73. })
  74. .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
  75. })
  76. })
  77. .then((resp) => {
  78. fs.scanFile([{
  79. path : resp.path()
  80. }])
  81. .then(() => {
  82. report(<Assert key="scan mp3 file success" expect={true} actual={true}/>)
  83. done()
  84. })
  85. })
  86. })