| 
				
			 | 
			
			
				@@ -0,0 +1,87 @@ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				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.5.3', 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+  run : true, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+  expand : false, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+let prefix = ((Platform.OS === 'android') ? 'file://' : '') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+describe('GET request with params', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+  let time = Date.now() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+  RNFetchBlob 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+  .config({ fileCache : true, trusty : true }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+    .fetch('GET', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    .then((resp) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+      let file = resp.path() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+      return RNFetchBlob.fs.readStream(resp.path(), 'utf8') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+    .then((stream) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+      let result = '' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+      stream.open() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+      stream.onData((chunk) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+        result += chunk 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+      }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+      stream.onEnd(() => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+        result = JSON.parse(result) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+        report(<Assert key="param#1 should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+          expect={parseInt(time)} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+          actual={parseInt(result.time)}/>, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+        <Assert key="param#2 should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+          expect={'RNFetchBlobParams'} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+          actual={result.name}/>, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+        <Assert key="param contains unicode data should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+          expect={'中文'} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+          actual={result.lang}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+          done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+      }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+}) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+describe('POST request with params', (report, done) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+  let time = Date.now() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+  RNFetchBlob.config({ fileCache : true, trusty : true }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+    .fetch('POST', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+    .then((resp) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+      let file = resp.path() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+      return RNFetchBlob.fs.readStream(resp.path(), 'utf8') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+    .then((stream) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+      let result = '' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+      stream.open() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+      stream.onData((chunk) => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+        result += chunk 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+      }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+      stream.onEnd(() => { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+        result = JSON.parse(result) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+        report(<Assert key="param#1 should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+          expect={parseInt(time)} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+          actual={parseInt(result.time)}/>, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+        <Assert key="param#2 should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+          expect={'RNFetchBlobParams'} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+          actual={result.name}/>, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+        <Assert key="param contains unicode data should correct" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+          expect={'中文'} 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+          actual={result.lang}/>) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+          done() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+      }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+    }) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+}) 
			 |