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