説明なし

test-0.1.x-0.4.x.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. Dimensions,
  10. Image,
  11. } from 'react-native';
  12. const { Assert, Comparer, Info, prop } = RNTest
  13. const describe = RNTest.config({
  14. group : '0.1.x - 0.4.x',
  15. expand : false,
  16. run : true
  17. })
  18. let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
  19. // describe('The check if it follows 301/302 redirection', (report, done) => {
  20. //
  21. // image = RNTest.prop('image')
  22. //
  23. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
  24. // .then((resp) => {
  25. // report(
  26. // <Assert key="check image size" expect={image.length} actual={resp.base64().length}/>,
  27. // <Info key="Response image">
  28. // <Image
  29. // style={{width:Dimensions.get('window').width*0.9, height : Dimensions.get('window').width*0.9,margin :16}}
  30. // source={{uri : `data:image/png;base64, ${image}`}}/>
  31. // </Info>)
  32. // done()
  33. // })
  34. //
  35. // })
  36. //
  37. // describe('Upload octet-stream image to Dropbox', (report, done) => {
  38. //
  39. // RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
  40. // Authorization : `Bearer ${DROPBOX_TOKEN}`,
  41. // 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
  42. // 'Content-Type' : 'application/octet-stream',
  43. // }, image)
  44. // .then((resp) => {
  45. // resp = resp.json()
  46. // report(
  47. // <Assert key="confirm the file has been uploaded" expect={FILENAME} actual={resp.name}/>
  48. // )
  49. // done()
  50. // })
  51. //
  52. // })
  53. //
  54. // describe('Upload multipart/form-data', (report, done) => {
  55. //
  56. // RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
  57. // Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
  58. // 'Content-Type' : 'multipart/form-data',
  59. // }, [
  60. // { name : 'test-img', filename : 'test-img.png', data: image},
  61. // { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
  62. // { name : 'field1', data : 'hello !!'},
  63. // { name : 'field2', data : 'hello2 !!'}
  64. // ])
  65. // .then((resp) => {
  66. // resp = resp.json()
  67. // report(
  68. // <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
  69. // <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
  70. // )
  71. // done()
  72. // })
  73. //
  74. //
  75. // })
  76. //
  77. // describe('Compare uploaded multipart image', (report, done) => {
  78. // let r1 = null
  79. // RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
  80. // .then((resp) => {
  81. // r1 = resp
  82. // return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
  83. // })
  84. // .then((resp) => {
  85. // report(
  86. // <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
  87. // <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
  88. // )
  89. // done()
  90. // })
  91. //
  92. // })
  93. //
  94. // // added after 0.4.2
  95. //
  96. // describe('Progress report test', (report, done) => {
  97. // let actual = 0, expect = -1
  98. // RNFetchBlob
  99. // .fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
  100. // Authorization : 'Bearer abde123eqweje'
  101. // })
  102. // .progress((received, total) => {
  103. // actual = received
  104. // expect = total
  105. // })
  106. // .then((resp) => {
  107. // report(
  108. // <Assert key="download progress correct" expect={expect} actual={actual}/>,
  109. // <Assert key="response data should be correct event with progress listener"
  110. // expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
  111. // done()
  112. // })
  113. //
  114. // })
  115. describe('PUT request test', (report, done) => {
  116. let actual = 0, expect = -1
  117. RNFetchBlob.fetch('PUT', `${TEST_SERVER_URL}/upload-form`, {
  118. Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
  119. 'Content-Type' : 'multipart/form-data',
  120. }, [
  121. { name : 'test-img', filename : 'test-img.png', data: image},
  122. { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
  123. { name : 'field1', data : 'hello !!'},
  124. { name : 'field2', data : 'hello2 !!'}
  125. ])
  126. .progress((written, total) => {
  127. actual = written
  128. expect = total
  129. })
  130. .then((resp) => {
  131. resp = resp.json()
  132. report(
  133. <Assert key="upload progress correct" expect={expect} actual={actual}/>,
  134. <Assert key="check put form data #1" expect="hello !!" actual={resp.fields.field1}/>,
  135. <Assert key="check put form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
  136. )
  137. done()
  138. })
  139. })
  140. describe('DELETE request test', (report, done) => {
  141. RNFetchBlob.fetch('DELETE', `${TEST_SERVER_URL}/hey`)
  142. .then((resp) => {
  143. report(
  144. <Assert key="check DELETE request result" expect={'man'} actual={resp.text()}/>)
  145. done()
  146. })
  147. })