Açıklama Yok

test-android.js 2.3KB

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 : true,
  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. const dirs = RNFetchBlob.fs.dirs
  25. describe('Download with notification', (report, done) => {
  26. let filePath = null
  27. let filename = `test-${Date.now()}.png`
  28. filePath = `${dirs.DownloadDir}/${filename}`
  29. 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. .then((resp) => {
  41. tmpFilePath = resp.path()
  42. report(<Info key={`image from ${tmpFilePath}`}>
  43. <Image
  44. source={{ uri : prefix + tmpFilePath}}
  45. style={styles.image}/>
  46. </Info>)
  47. done()
  48. })
  49. })
  50. describe('MediaScanner tests ', (report, done) => {
  51. let filename = `scannable-test-${Date.now()}.png`
  52. let filePath = `${dirs.DownloadDir}/${filename}`
  53. RNFetchBlob.config({
  54. path : filePath,
  55. })
  56. .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
  57. .then((resp) => {
  58. tmpFilePath = resp.path()
  59. return RNFetchBlob.fs.scanFile([
  60. { path:resp.path() }
  61. ])
  62. })
  63. .then(() => {
  64. report(<Assert key="scan success" expect={true} actual={true}/>)
  65. console.log(dirs)
  66. for(let i in dirs) {
  67. console.log(i)
  68. }
  69. console.log(dirs.DCIMDir)
  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. .then((resp) => {
  77. fs.scanFile([{
  78. path : resp.path()
  79. }])
  80. .then(() => {
  81. report(<Assert key="scan mp3 file success" expect={true} actual={true}/>)
  82. done()
  83. })
  84. })
  85. })