Ei kuvausta

test-firebase.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import RNTest from './react-native-testkit/'
  2. import React from 'react'
  3. import RNFetchBlob from 'react-native-fetch-blob'
  4. import Timer from 'react-timer-mixin'
  5. import firebase from 'firebase'
  6. import {
  7. StyleSheet,
  8. Text,
  9. View,
  10. ScrollView,
  11. CameraRoll,
  12. Platform,
  13. Dimensions,
  14. Image,
  15. } from 'react-native';
  16. const fs = RNFetchBlob.fs
  17. const Blob = RNFetchBlob.polyfill.Blob
  18. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  19. window.Blob = Blob
  20. const { Assert, Comparer, Info, prop } = RNTest
  21. const describe = RNTest.config({
  22. group : 'firebase',
  23. run : true,
  24. expand : false,
  25. timeout : 300000000,
  26. })
  27. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
  28. const dirs = RNFetchBlob.fs.dirs
  29. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  30. let file = RNTest.prop('image')
  31. // Initialize Firebase
  32. var config = {
  33. apiKey: "AIzaSyCnoNvJu2tYYHe87Sm-FrW7j-G-c0MPWGQ",
  34. authDomain: "rnfb-test-app.firebaseapp.com",
  35. databaseURL: "https://rnfb-test-app.firebaseio.com",
  36. storageBucket: "rnfb-test-app.appspot.com",
  37. };
  38. firebase.initializeApp(config);
  39. describe('firebase login', (report, done) => {
  40. firebase.auth().signInWithEmailAndPassword('xeiyan@gmail.com', 'rnfbtest1024')
  41. .catch((err) => {
  42. console.log('firebase sigin failed', err)
  43. })
  44. firebase.auth().onAuthStateChanged((user) => {
  45. report(<Assert key="login status" uid="100"
  46. expect={true}
  47. actual={user !== null}/>,
  48. <Info key="user content" uid="user data">
  49. <Text>{JSON.stringify(user)}</Text>
  50. </Info>)
  51. done()
  52. })
  53. })
  54. // describe('upload file to firebase', (report, done) => {
  55. //
  56. // // create Blob from BASE64 data
  57. // let blob = new Blob(RNTest.prop('image'), { type : 'image/png;BASE64'})
  58. // let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
  59. // RNTest.prop('firebase-image', testImage)
  60. // // start test after Blob created
  61. // blob.onCreated(() => {
  62. // let storage = firebase.storage().ref('rnfbtest')
  63. // let task = storage
  64. // .child(RNTest.prop('firebase-image'))
  65. // .put(blob, { contentType : 'image/png' })
  66. // .then((snapshot) => {
  67. // console.log(snapshot.metadata)
  68. // report(<Assert key="upload success"
  69. // expect={true}
  70. // actual={true}/>,
  71. // <Info key="uploaded file stat" >
  72. // <Text>{snapshot.totalBytes}</Text>
  73. // <Text>{JSON.stringify(snapshot.metadata)}</Text>
  74. // </Info>)
  75. // done()
  76. // })
  77. // })
  78. // })
  79. //
  80. // describe('download firebase storage item', (report, done) => {
  81. // let storage = firebase.storage().ref('rnfbtest/' + RNTest.prop('firebase-image'))
  82. // storage.getDownloadURL().then((url) => {
  83. // console.log(url)
  84. // report(<Info key="image viewer">
  85. // <Image style={styles.image} source={{uri : url}}/>
  86. // </Info>)
  87. // done()
  88. // })
  89. // })
  90. //
  91. // let tier2FileName = `firebase-test-${Platform.OS}-github2.jpg`
  92. //
  93. // describe('upload using file path', (report, done) => {
  94. // RNFetchBlob
  95. // .config({ fileCache : true, appendExt : 'jpg' })
  96. // .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
  97. // .then((resp) => {
  98. // report(<Info key="test image">
  99. // <Image style={styles.image} source={{uri : prefix + resp.path()}}/>
  100. // </Info>)
  101. // let blob = new Blob(RNFetchBlob.wrap(resp.path()), { type : 'image/jpg' })
  102. // blob.onCreated(() => {
  103. // firebase.storage().ref('rnfbtest')
  104. // .child(tier2FileName)
  105. // .put(blob, { contentType : 'image/jpg' })
  106. // .then(() => {
  107. // report(<Assert key="upload finished" />)
  108. // done()
  109. // })
  110. // })
  111. // })
  112. // })
  113. //
  114. // let directURL = null
  115. //
  116. // describe('verify uploaded file', (report, done) => {
  117. // firebase.storage().ref('rnfbtest/' + tier2FileName)
  118. // .getDownloadURL()
  119. // .then((url) => {
  120. // directURL = url
  121. // report(
  122. // <Info key="image viewer">
  123. // <Image style={styles.image} source={{uri : url}}/>
  124. // </Info>)
  125. // done()
  126. // })
  127. // })
  128. //
  129. // describe('download to base64', (report, done) => {
  130. // RNFetchBlob.fetch('GET', directURL).then((resp) => {
  131. // report(
  132. // <Info key="image data">
  133. // <Image
  134. // style={styles.image}
  135. // source={{uri : 'data:image/jpg;base64 ,'+ resp.base64()}}/>
  136. // </Info>)
  137. // done()
  138. // })
  139. // })