@@ -61,117 +61,143 @@ describe('firebase login', (report, done) => {
61
61
} )
62
62
} )
63
63
64
- describe ( 'upload file to firebase' , ( report , done ) => {
65
-
66
- let testImage = `firebase-test-${ Platform . OS } -${ Date . now ( ) } .png`
67
- RNTest . prop ( 'firebase-image' , testImage )
68
-
69
- // create Blob from BASE64 data
70
- Blob . build ( RNTest . prop ( 'image' ) , { type : 'image/png;BASE64' } )
71
- . then ( ( blob ) => {
72
- let storage = firebase . storage ( ) . ref ( 'rnfbtest' )
73
- let task = storage
74
- . child ( RNTest . prop ( 'firebase-image' ) )
75
- . put ( blob , { contentType : 'image/png' } )
76
- . then ( ( snapshot ) => {
77
- console . log ( snapshot . metadata )
78
- report ( < Assert key = "upload success"
79
- expect = { true }
80
- actual = { true } /> ,
81
- < Info key = "uploaded file stat" >
82
- < Text > { snapshot . totalBytes } </ Text >
83
- < Text > { JSON . stringify ( snapshot . metadata ) } </ Text >
84
- </ Info > )
85
- done ( )
86
- } )
87
- } )
88
- } )
89
-
90
- describe ( 'download firebase storage item' , ( report , done ) => {
91
- let storage = firebase . storage ( ) . ref ( 'rnfbtest/' + RNTest . prop ( 'firebase-image' ) )
92
- storage . getDownloadURL ( ) . then ( ( url ) => {
93
- console . log ( url )
94
- report ( < Info key = "image viewer" >
95
- < Image style = { styles . image } source = { { uri : url } } />
96
- </ Info > )
97
- done ( )
98
- } )
99
- } )
100
-
101
- let tier2FileName = `firebase-test-${ Platform . OS } -github2.jpg`
102
-
103
- describe ( 'upload using file path' , ( report , done ) => {
104
- RNFetchBlob
105
- . config ( { fileCache : true , appendExt : 'jpg' } )
106
- . fetch ( 'GET' , `${ TEST_SERVER_URL } /public/500k-img-dummy.jpg` )
64
+ // describe('upload file to firebase', (report, done) => {
65
+ //
66
+ // let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
67
+ // RNTest.prop('firebase-image', testImage)
68
+ //
69
+ // // create Blob from BASE64 data
70
+ // Blob.build(RNTest.prop('image'), { type : 'image/png;BASE64'})
71
+ // .then((blob) => {
72
+ // let storage = firebase.storage().ref('rnfbtest')
73
+ // let task = storage
74
+ // .child(RNTest.prop('firebase-image'))
75
+ // .put(blob, { contentType : 'image/png' })
76
+ // .then((snapshot) => {
77
+ // console.log(snapshot.metadata)
78
+ // report(<Assert key="upload success"
79
+ // expect={true}
80
+ // actual={true}/>,
81
+ // <Info key="uploaded file stat" >
82
+ // <Text>{snapshot.totalBytes}</Text>
83
+ // <Text>{JSON.stringify(snapshot.metadata)}</Text>
84
+ // </Info>)
85
+ // done()
86
+ // })
87
+ // })
88
+ // })
89
+ //
90
+ // describe('download firebase storage item', (report, done) => {
91
+ // let storage = firebase.storage().ref('rnfbtest/' + RNTest.prop('firebase-image'))
92
+ // storage.getDownloadURL().then((url) => {
93
+ // console.log(url)
94
+ // report(<Info key="image viewer">
95
+ // <Image style={styles.image} source={{uri : url}}/>
96
+ // </Info>)
97
+ // done()
98
+ // })
99
+ // })
100
+ //
101
+ // let tier2FileName = `firebase-test-${Platform.OS}-github2.jpg`
102
+ //
103
+ // describe('upload using file path', (report, done) => {
104
+ // RNFetchBlob
105
+ // .config({ fileCache : true, appendExt : 'jpg' })
106
+ // .fetch('GET', `${TEST_SERVER_URL}/public/500k-img-dummy.jpg`)
107
+ // .then((resp) => {
108
+ // report(<Info key="test image">
109
+ // <Image style={styles.image} source={{uri : prefix + resp.path()}}/>
110
+ // </Info>)
111
+ // let blob = new Blob(RNFetchBlob.wrap(resp.path()), { type : 'image/jpg' })
112
+ // blob.onCreated(() => {
113
+ // firebase.storage().ref('rnfbtest')
114
+ // .child(tier2FileName)
115
+ // .put(blob, { contentType : 'image/jpg' })
116
+ // .then(() => {
117
+ // report(<Assert key="upload finished" />)
118
+ // done()
119
+ // })
120
+ // })
121
+ // })
122
+ // })
123
+ //
124
+ // let directURL = null
125
+ //
126
+ // describe('verify uploaded file', (report, done) => {
127
+ // firebase.storage().ref('rnfbtest/' + tier2FileName)
128
+ // .getDownloadURL()
129
+ // .then((url) => {
130
+ // directURL = url
131
+ // report(
132
+ // <Info key="image viewer">
133
+ // <Image style={styles.image} source={{uri : url}}/>
134
+ // </Info>)
135
+ // done()
136
+ // })
137
+ // })
138
+ //
139
+ // describe('download to base64', (report, done) => {
140
+ // RNFetchBlob.fetch('GET', directURL).then((resp) => {
141
+ // report(
142
+ // <Info key="image data">
143
+ // <Image
144
+ // style={styles.image}
145
+ // source={{uri : 'data:image/jpg;base64 ,'+ resp.base64()}}/>
146
+ // </Info>)
147
+ // done()
148
+ // })
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
+ // })
178
+
179
+ describe ( 'upload from CameraRoll' , ( report , done ) => {
180
+ let tmp = fs . dirs . DocumentDir + '/tmp' + Date . now ( )
181
+ let blob
182
+ CameraRoll . getPhotos ( { first : 10 } )
107
183
. then ( ( resp ) => {
108
- report ( < Info key = "test image" >
109
- < Image style = { styles . image } source = { { uri : prefix + resp . path ( ) } } />
110
- </ Info > )
111
- let blob = new Blob ( RNFetchBlob . wrap ( resp . path ( ) ) , { type : 'image/jpg' } )
112
- blob . onCreated ( ( ) => {
113
- firebase . storage ( ) . ref ( 'rnfbtest' )
114
- . child ( tier2FileName )
115
- . put ( blob , { contentType : 'image/jpg' } )
116
- . then ( ( ) => {
117
- report ( < Assert key = "upload finished" /> )
118
- done ( )
119
- } )
120
- } )
184
+ let url = resp . edges [ 0 ] . node . image . uri
185
+ console . log ( 'CameraRoll' , url )
186
+ return fs . cp ( url , tmp )
121
187
} )
122
- } )
123
-
124
- let directURL = null
125
-
126
- describe ( 'verify uploaded file' , ( report , done ) => {
127
- firebase . storage ( ) . ref ( 'rnfbtest/' + tier2FileName )
128
- . getDownloadURL ( )
129
- . then ( ( url ) => {
130
- directURL = url
131
- report (
132
- < Info key = "image viewer" >
133
- < Image style = { styles . image } source = { { uri : url } } />
134
- </ Info > )
135
- done ( )
188
+ . then ( ( ) => {
189
+ console . log ( 'cp' , tmp )
190
+ return Blob . build ( RNFetchBlob . wrap ( tmp ) , { type :'image/jpg' } )
136
191
} )
137
- } )
138
-
139
- describe ( 'download to base64' , ( report , done ) => {
140
- RNFetchBlob . fetch ( 'GET' , directURL ) . then ( ( resp ) => {
141
- report (
142
- < Info key = "image data" >
143
- < Image
144
- style = { styles . image }
145
- source = { { uri : 'data:image/jpg;base64 ,' + resp . base64 ( ) } } />
146
- </ Info > )
147
- done ( )
148
- } )
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
- } )
192
+ . then ( ( b ) => {
193
+ blob = b
194
+ return firebase . storage ( )
195
+ . ref ( 'rnfbtest' ) . child ( 'camra-roll.jpg' )
196
+ . put ( b , { contentType : 'image/jpg' } )
197
+ } )
198
+ . then ( ( snapshot ) => {
199
+ report ( < Assert key = "upload sucess" expect = { true } actual = { true } /> )
200
+ blob . close ( )
201
+ done ( )
172
202
} )
173
- }
174
- catch ( err ) {
175
- console . log ( err )
176
- }
177
203
} )
0 commit comments