Parcourir la source

Add firebase test case

Ben Hsieh il y a 8 ans
Parent
révision
48d1c3f76e
2 fichiers modifiés avec 46 ajouts et 18 suppressions
  1. 32
    4
      test/test-firebase.js
  2. 14
    14
      test/test-init.js

+ 32
- 4
test/test-firebase.js Voir le fichier

@@ -63,12 +63,12 @@ describe('firebase login', (report, done) => {
63 63
 
64 64
 describe('upload file to firebase', (report, done) => {
65 65
 
66
-  // create Blob from BASE64 data
67
-  let blob = new Blob(RNTest.prop('image'), { type : 'image/png;BASE64'})
68 66
   let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
69 67
   RNTest.prop('firebase-image', testImage)
70
-  // start test after Blob created
71
-  blob.onCreated(() => {
68
+
69
+  // create Blob from BASE64 data
70
+  Blob.build(RNTest.prop('image'), { type : 'image/png;BASE64'})
71
+  .then((blob) => {
72 72
     let storage = firebase.storage().ref('rnfbtest')
73 73
     let task = storage
74 74
       .child(RNTest.prop('firebase-image'))
@@ -147,3 +147,31 @@ describe('download to base64', (report, done) => {
147 147
     done()
148 148
   })
149 149
 })
150
+
151
+describe('upload from storage', (report, done) => {
152
+  try {
153
+  let file = fs.dirs.DocumentDir + '/tempimg.png'
154
+  fs.writeFile(file, RNTest.prop('image'), 'base64')
155
+    .then(() => Blob.build(RNFetchBlob.wrap(file), {type : 'image/png'}))
156
+    .then((blob) => {
157
+      let storage = firebase.storage().ref('rnfbtest')
158
+      let task = storage
159
+        .child(`image-from-storage-${Platform.OS}-${Date.now()}.png`)
160
+        .put(blob, { contentType : 'image/png' })
161
+        .then((snapshot) => {
162
+          console.log(snapshot.metadata)
163
+          report(<Assert key="upload success"
164
+            expect={true}
165
+            actual={true}/>,
166
+          <Info key="uploaded file stat" >
167
+            <Text>{snapshot.totalBytes}</Text>
168
+            <Text>{JSON.stringify(snapshot.metadata)}</Text>
169
+          </Info>)
170
+          done()
171
+        })
172
+    })
173
+  }
174
+  catch(err) {
175
+    console.log(err)
176
+  }
177
+})

+ 14
- 14
test/test-init.js Voir le fichier

@@ -59,19 +59,19 @@ describe('GET image from server', (report, done) => {
59 59
 })
60 60
 
61 61
 
62
-// require('./test-0.1.x-0.4.x')
63
-// require('./test-0.5.1')
64
-// require('./test-0.5.2')
65
-// require('./test-0.6.0')
66
-// require('./test-0.6.2')
67
-// require('./test-0.6.3')
68
-// require('./test-0.7.0')
69
-// require('./test-0.8.0')
70
-// require('./test-0.9.0')
71
-// require('./test-fetch')
72
-// require('./test-fs')
62
+require('./test-0.1.x-0.4.x')
63
+require('./test-0.5.1')
64
+require('./test-0.5.2')
65
+require('./test-0.6.0')
66
+require('./test-0.6.2')
67
+require('./test-0.6.3')
68
+require('./test-0.7.0')
69
+require('./test-0.8.0')
70
+require('./test-0.9.0')
71
+require('./test-fetch')
72
+require('./test-fs')
73 73
 require('./test-xmlhttp')
74
-// require('./test-blob')
75
-// require('./test-firebase')
76
-// require('./test-android')
74
+require('./test-blob')
75
+require('./test-firebase')
76
+require('./test-android')
77 77
 // require('./benchmark')