| 
				
			 | 
			
			
				@@ -18,14 +18,37 @@ const { Assert, Comparer, Info, prop } = RNTest 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				18
			 | 
			
			
				 const describe = RNTest.config({ 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				19
			 | 
			
			
				   group : '0.6.2', 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				20
			 | 
			
			
				   run : true, 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				-  expand : true, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+  expand : false, 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				22
			 | 
			
			
				   timeout : 12000, 
			 | 
		
	
		
			
			| 
				23
			 | 
			
				23
			 | 
			
			
				 }) 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				
			 | 
			
			
				-const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+const { TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop() 
			 | 
		
	
		
			
			| 
				25
			 | 
			
				25
			 | 
			
			
				 const  dirs = RNFetchBlob.fs.dirs 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				26
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				27
			 | 
			
				27
			 | 
			
			
				 let prefix = ((Platform.OS === 'android') ? 'file://' : '') 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				28
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+describe('upload asset from camera roll', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+  let imgName = `image-from-camera-roll-${Platform.OS}.jpg` 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+  CameraRoll.getPhotos({first : 10}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    .then((resp) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+      let url = resp.edges[0].node.image.uri 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+      return fs.readFile(url, 'base64') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+    .then((data) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+      return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+        Authorization : `Bearer ${DROPBOX_TOKEN}`, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+        'Dropbox-API-Arg': `{\"path\": \"/rn-upload/${imgName}\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+        'Content-Type' : 'application/octet-stream', 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+      }, data) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+    .then((resp) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+      resp = resp.json() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+      report( 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+        <Assert key="confirm the file has been uploaded" expect={imgName} actual={resp.name}/> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+      ) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+      done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				52
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				30
			 | 
			
				53
			 | 
			
			
				 describe('access assets from camera roll', (report, done) => { 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				54
			 | 
			
			
				   let photo = null 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -48,7 +71,7 @@ describe('access assets from camera roll', (report, done) => { 
			 | 
		
	
		
			
			| 
				48
			 | 
			
				71
			 | 
			
			
				 }) 
			 | 
		
	
		
			
			| 
				49
			 | 
			
				72
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				50
			 | 
			
				73
			 | 
			
			
				 describe('read asset in app bundle',(report, done) => { 
			 | 
		
	
		
			
			| 
				51
			 | 
			
				
			 | 
			
			
				-  let target = 'bundle-assets://test-asset2.png' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+  let target = fs.asset('test-asset2.png') 
			 | 
		
	
		
			
			| 
				52
			 | 
			
				75
			 | 
			
			
				   fs.readFile(target, 'base64') 
			 | 
		
	
		
			
			| 
				53
			 | 
			
				76
			 | 
			
			
				   .then((data) => { 
			 | 
		
	
		
			
			| 
				54
			 | 
			
				77
			 | 
			
			
				     report(<Info key="asset image"> 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -56,7 +79,7 @@ describe('read asset in app bundle',(report, done) => { 
			 | 
		
	
		
			
			| 
				56
			 | 
			
				79
			 | 
			
			
				         style={styles.image} 
			 | 
		
	
		
			
			| 
				57
			 | 
			
				80
			 | 
			
			
				         source={{uri: `data:image/png;base64, ${data}`}}/> 
			 | 
		
	
		
			
			| 
				58
			 | 
			
				81
			 | 
			
			
				     </Info>) 
			 | 
		
	
		
			
			| 
				59
			 | 
			
				
			 | 
			
			
				-    return fs.readFile('bundle-assets://test-asset1.json', 'utf8') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+    return fs.readFile(fs.asset('test-asset1.json'), 'utf8') 
			 | 
		
	
		
			
			| 
				60
			 | 
			
				83
			 | 
			
			
				   }) 
			 | 
		
	
		
			
			| 
				61
			 | 
			
				84
			 | 
			
			
				   .then((resp) => { 
			 | 
		
	
		
			
			| 
				62
			 | 
			
				85
			 | 
			
			
				     report( 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -66,3 +89,34 @@ describe('read asset in app bundle',(report, done) => { 
			 | 
		
	
		
			
			| 
				66
			 | 
			
				89
			 | 
			
			
				       done() 
			 | 
		
	
		
			
			| 
				67
			 | 
			
				90
			 | 
			
			
				   }) 
			 | 
		
	
		
			
			| 
				68
			 | 
			
				91
			 | 
			
			
				 }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+describe('stat assets in app', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+  fs.stat(fs.asset('test-asset2.png')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+    .then((data) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+      report(<Info key="list of assets"> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+        <Text>{JSON.stringify(data)}</Text> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				98
			 | 
			
			
				+      </Info>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+      done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				101
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				103
			 | 
			
			
				+describe('copy asset', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				104
			 | 
			
			
				+  let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json` 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+  fs.cp(fs.asset('test-asset1.json'), dest) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+    .then(() => fs.readFile(dest, 'utf8')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				107
			 | 
			
			
				+    .then((data) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				108
			 | 
			
			
				+      report(<Assert key="asset copied correctly" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				109
			 | 
			
			
				+        expect={'asset#1'} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+        actual={JSON.parse(data).secret}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+      return fs.stat(fs.asset('test-asset1.json')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				113
			 | 
			
			
				+    .then((stat) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				114
			 | 
			
			
				+      report(<Assert key="file size check" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				115
			 | 
			
			
				+        expect={27} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+        actual={Math.floor(stat.size)}/>, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+      <Info key="dest file info"> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				+        <Text>{JSON.stringify(stat)}</Text> 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+      </Info>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				120
			 | 
			
			
				+      done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				122
			 | 
			
			
				+}) 
			 |