| 
				
			 | 
			
			
				@@ -0,0 +1,62 @@ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				1
			 | 
			
			
				+import RNTest from './react-native-testkit/' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				2
			 | 
			
			
				+import React from 'react' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+import RNFetchBlob from 'react-native-fetch-blob' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+import { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				6
			 | 
			
			
				+  StyleSheet, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+  Text, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+  View, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+  ScrollView, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+  Platform, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+  Dimensions, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+  Image, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+} from 'react-native'; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+const fs = RNFetchBlob.fs 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+const { Assert, Comparer, Info, prop } = RNTest 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+const describe = RNTest.config({ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+  group : '0.6.0', 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+  run : true, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+  expand : false, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+  timeout : 10000, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+const  dirs = RNFetchBlob.fs.dirs 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+let prefix = ((Platform.OS === 'android') ? 'file://' : '') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+describe('writeFile test', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+  let path = dirs.DocumentDir + '/0.6.0-'+Date.now()+'/writeFileTest'+Date.now() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+  let data = 'hellofrom'+Date.now() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+  fs.writeFile(path, 'utf8', data) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    .then(() => fs.readFile(path, 'utf8')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+    .then((actual) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+      report(<Assert key="utf8 content should correct" expect={data} actual={actual}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+      data += 'base64' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+      return fs.writeFile(path, 'base64', RNFetchBlob.base64.encode(data)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+    .then(() => fs.readFile(path, 'base64')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+    .then((actual) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+      report(<Assert key="base64 content should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+        expect={RNFetchBlob.base64.decode(RNFetchBlob.base64.encode(data))} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+        actual={RNFetchBlob.base64.decode(actual)}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+      data += 'ascii' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+      return fs.writeFile(path, 'ascii', getASCIIArray(data)); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+    .then(() => fs.readFile(path, 'ascii')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+    .then((actual) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+      report(<Assert key="ascii content should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+        expect={getASCIIArray(data)} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+        comparer={Comparer.equalToArray} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+        actual={actual}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+      done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+function getASCIIArray(str) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+  let r = [] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+  for(let i=0;i<str.length;i++) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+    r.push(str[i].charCodeAt(0)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+  } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+  return r 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+} 
			 |