Browse Source

Add test cases

Ben Hsieh 7 years ago
parent
commit
f92cfb62d6
2 changed files with 41 additions and 67 deletions
  1. 3
    67
      test/test-0.10.0.js
  2. 38
    0
      test/test-nedb.js

+ 3
- 67
test/test-0.10.0.js View File

@@ -10,13 +10,7 @@ import {
10 10
   Dimensions,
11 11
   Image,
12 12
 } from 'react-native';
13
-
14
-// window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
15
-// window.Blob = RNFetchBlob.polyfill.Blob
16
-// window.fetch = new RNFetchBlob.polyfill.Fetch({
17
-//   auto : true,
18
-//   binaryContentTypes : ['image/', 'video/', 'audio/']
19
-// }).build()
13
+import DataStore from 'nedb'
20 14
 
21 15
 const fs = RNFetchBlob.fs
22 16
 const { Assert, Comparer, Info, prop } = RNTest
@@ -30,66 +24,8 @@ const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles }
30 24
 const dirs = RNFetchBlob.fs.dirs
31 25
 
32 26
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
27
+const db = new DataStore()
33 28
 
34
-describe('test', (report, done) => {
35
-
36
-  console.log('start')
37
-
38
-  let image = RNTest.prop('image')
39
-  let form = new FormData()
40
-  form.append("FormData", true)
41
-  form.append("access_token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjU3YjgyZGQ2MTEwZDcwYmEwYjUxZjM5YyIsImlzTWVkaWMiOnRydWUsImlhdCI6MTQ3MTY4ODE1MiwiZXhwIjoxNDcxNzA2MTUyfQ.gPeql5g66Am4Txl1WqnbvOWJaD8srTK_6vihOJ6kFbY")
42
-  form.append("Content-Type", "image/jpg")
43
-  form.append('image', {
44
-    uri : `data:image/png;base64, ${image}`,
45
-    type : 'image/png'
46
-  })
47
-
48
-  let xhr = new XMLHttpRequest()
49
-  xhr.open('post', `${TEST_SERVER_URL}/upload-form`)
50
-  xhr.send(form)
51
-  console.log(form)
52
-  xhr.onerror = function(e) {
53
-    console.log('err', e)
54
-  }
55
-  xhr.onreadystatechange = function() {
56
-    console.log('changed')
57
-    if(this.readyState === this.DONE) {
58
-      console.log(this.response)
59
-    }
60
-  }
61
-  // fetch(`${TEST_SERVER_URL}/upload-form`, {
62
-  //   method : 'POST',
63
-  //   body : form
64
-  // })
65
-  // .then((res) => res.text())
66
-  // .then((data) => {
67
-  //   console.log(data)
68
-  // })
69
-
70
-  // let filename = 'test-from-storage-img-'+Date.now()+'.png'
71
-  // RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
72
-  //     'Content-Type' : 'multipart/form-data',
73
-  //   }, [
74
-  //     { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
75
-  //     { name : 'field1', data : 'hello !!'},
76
-  //     { name : 'field2', data : 'hello2 !!'}
77
-  //   ])
78
-  // .then((resp) => {
79
-  //   resp = resp.json()
80
-  //   report(
81
-  //     <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
82
-  //     <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
83
-  //   )
84
-  //   return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
85
-  // })
86
-  // .then((resp) => {
87
-  //   report(<Info key="uploaded image">
88
-  //     <Image
89
-  //       style={styles.image}
90
-  //       source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
91
-  //   </Info>)
92
-  //   done()
93
-  // })
29
+describe('nedb constructor test', (report, done) =>{
94 30
 
95 31
 })

+ 38
- 0
test/test-nedb.js View File

@@ -0,0 +1,38 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import RNFetchBlob from 'react-native-fetch-blob'
4
+import {
5
+  StyleSheet,
6
+  Text,
7
+  View,
8
+  ScrollView,
9
+  Platform,
10
+  Dimensions,
11
+  Image,
12
+} from 'react-native';
13
+import DataStore from 'nedb'
14
+
15
+const fs = RNFetchBlob.fs
16
+const { Assert, Comparer, Info, prop } = RNTest
17
+const describe = RNTest.config({
18
+  group : '0.10.0',
19
+  run : true,
20
+  expand : true,
21
+  timeout : 20000,
22
+})
23
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
24
+const dirs = RNFetchBlob.fs.dirs
25
+
26
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
27
+const DB_PATH = fs.dirs.documentDir + `/nedb/test-db-${Date.now()}.db`
28
+const dbs = []
29
+
30
+describe('nedb persistant constructor test', (report, done) =>{
31
+
32
+  let db = new DataStore(DB_PATH)
33
+  db.loadDatabase(function(err) {
34
+    report(<Assert key="database should created" expect={null} actual={err}/>)
35
+    done()
36
+  })
37
+
38
+})