설명 없음

tests.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import {
  5. AppRegistry,
  6. StyleSheet,
  7. Text,
  8. View,
  9. Platform,
  10. ScrollView,
  11. Dimensions,
  12. Image,
  13. } from 'react-native';
  14. const FILENAME = `${Platform.OS}-0.5.0-${Date.now()}.png`
  15. // paste your test config here
  16. const TEST_SERVER_URL = 'http://192.168.17.193:8123'
  17. const DROPBOX_TOKEN = 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4'
  18. const ctx = new RNTest.TestContext()
  19. const Assert = RNTest.Assert
  20. const Comparer = RNTest.Comparer
  21. const Info = RNTest.Info
  22. let image = null
  23. const styles = StyleSheet.create({
  24. image : {
  25. width:Dimensions.get('window').width*0.9,
  26. height : Dimensions.get('window').width*0.9,
  27. margin :16
  28. }
  29. })
  30. ctx.describe('GET image from server', (report, done) => {
  31. RNFetchBlob
  32. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
  33. Authorization : 'Bearer abde123eqweje'
  34. })
  35. .then((resp) => {
  36. image = resp.base64()
  37. report(
  38. <Info key="Response image">
  39. <Image
  40. style={styles.image}
  41. source={{uri : `data:image/png;base64, ${image}`}}/>
  42. </Info>)
  43. done()
  44. })
  45. })
  46. //
  47. // ctx.describe('The check if it follows 301/302 redirection', (report, done) => {
  48. //
  49. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
  50. // .then((resp) => {
  51. // report(
  52. // <Assert key="check image size" expect={image.length} actual={resp.base64().length}/>,
  53. // <Info key="Response image">
  54. // <Image
  55. // style={{width:Dimensions.get('window').width*0.9, height : Dimensions.get('window').width*0.9,margin :16}}
  56. // source={{uri : `data:image/png;base64, ${image}`}}/>
  57. // </Info>)
  58. // done()
  59. // })
  60. //
  61. // })
  62. //
  63. // ctx.describe('Upload octet-stream image to Dropbox', (report, done) => {
  64. //
  65. // RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
  66. // Authorization : `Bearer ${DROPBOX_TOKEN}`,
  67. // 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
  68. // 'Content-Type' : 'application/octet-stream',
  69. // }, image)
  70. // .then((resp) => {
  71. // resp = resp.json()
  72. // report(
  73. // <Assert key="confirm the file has been uploaded" expect={FILENAME} actual={resp.name}/>
  74. // )
  75. // done()
  76. // })
  77. //
  78. // })
  79. //
  80. // ctx.describe('Upload multipart/form-data', (report, done) => {
  81. //
  82. // RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
  83. // Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
  84. // 'Content-Type' : 'multipart/form-data',
  85. // }, [
  86. // { name : 'test-img', filename : 'test-img.png', data: image},
  87. // { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
  88. // { name : 'field1', data : 'hello !!'},
  89. // { name : 'field2', data : 'hello2 !!'}
  90. // ])
  91. // .then((resp) => {
  92. // resp = resp.json()
  93. // report(
  94. // <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
  95. // <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
  96. // )
  97. // done()
  98. // })
  99. //
  100. //
  101. // })
  102. ctx.describe('Compare uploaded multipart image', (report, done) => {
  103. let r1 = null
  104. RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
  105. .then((resp) => {
  106. r1 = resp
  107. return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
  108. })
  109. .then((resp) => {
  110. report(
  111. <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
  112. <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
  113. )
  114. done()
  115. })
  116. })
  117. // added after 0.4.2
  118. // ctx.describe('Progress report test', (report, done) => {
  119. // let received = 0
  120. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
  121. // Authorization : 'Bearer abde123eqweje'
  122. // })
  123. // .progress((written, total) => {
  124. // report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
  125. // if(written === total)
  126. // report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
  127. // })
  128. // .then((resp) => {
  129. // report(<Assert key="response data should be correct event with progress listener"
  130. // expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
  131. // done()
  132. // })
  133. //
  134. // })
  135. // FIXME : not yet supported
  136. // ctx.describe('Large file download test', (report, done) => {
  137. // let received = 0
  138. // // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/22mb-dummy`, {
  139. // // Authorization : 'Bearer abde123eqweje'
  140. // // })
  141. // // .then((resp) => {
  142. // report(<Assert key="not supported" expect={true} actual={false}/>)
  143. // done()
  144. // // })
  145. //
  146. // })
  147. // added after 0.5.0
  148. ctx.describe('Get storage folders', (report, done) => {
  149. RNFetchBlob.getSystemDirs().then((dirs) => {
  150. report(
  151. <Assert key="system folders should exists" expect={dirs} comparer={Comparer.exists} />,
  152. <Assert key="check properties"
  153. expect={dirs}
  154. comparer={Comparer.hasProperties}
  155. actual={['PictureDir', 'MovieDir', 'DocumentDir', 'CacheDir']}
  156. />,
  157. <Info key="System Folders">
  158. <Text>{`${JSON.stringify(dirs)}`}</Text>
  159. </Info>
  160. )
  161. done()
  162. })
  163. })
  164. ctx.describe('Download file to storage', (report, done) => {
  165. RNFetchBlob.config({
  166. fileCache : true,
  167. appendExt : 'png'
  168. })
  169. .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
  170. .then((resp) => {
  171. report(<Info key={`image from ${resp.path()}`}>
  172. <Image source={{ uri : resp.path()}} style={styles.image}/>
  173. </Info>)
  174. done()
  175. })
  176. })
  177. export default ctx