Няма описание

test-firebase.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { Assert, Comparer, Info, prop } = RNTest
  18. const describe = RNTest.config({
  19. group : 'firebase',
  20. run : true,
  21. expand : true,
  22. timeout : 300000000,
  23. })
  24. const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
  25. const dirs = RNFetchBlob.fs.dirs
  26. let prefix = ((Platform.OS === 'android') ? 'file://' : '')
  27. let file = RNTest.prop('image')
  28. // Initialize Firebase
  29. var config = {
  30. apiKey: "AIzaSyCnoNvJu2tYYHe87Sm-FrW7j-G-c0MPWGQ",
  31. authDomain: "rnfb-test-app.firebaseapp.com",
  32. databaseURL: "https://rnfb-test-app.firebaseio.com",
  33. storageBucket: "rnfb-test-app.appspot.com",
  34. };
  35. firebase.initializeApp(config);
  36. describe('firebase login', (report, done) => {
  37. firebase.auth().signInWithEmailAndPassword('xeiyan@gmail.com', 'rnfbtest1024')
  38. .catch((err) => {
  39. console.log('firebase sigin failed', err)
  40. })
  41. firebase.auth().onAuthStateChanged((user) => {
  42. report(<Assert key="login success"
  43. expect={user !== undefined}
  44. actual={user}/>,
  45. <Info key="user content">
  46. <Text>{JSON.stringify(user)}</Text>
  47. </Info>)
  48. done()
  49. })
  50. })
  51. describe('upload file to firebase', (report, done) => {
  52. try {
  53. let storage = firebase.storage().ref()
  54. let task = storage.file(`testdata/firebase-test-${Platform.OS}.png`).put(webFile, metadata)
  55. task.on('state_change', null, (err) => {
  56. }, () => {
  57. report(<Assert key="upload success"
  58. expect={true}
  59. actual={true}/>,
  60. <Info key="uploaded file stat" >
  61. <Text>{task.snapshot.totalBytes}</Text>
  62. <Text>{JSON.stringify(task.snapshot.metadata)}</Text>
  63. </Info>)
  64. })
  65. } catch(ex) {
  66. console.log('firebase polyfill error', ex)
  67. }
  68. })