Daniel Zlotin 8 anos atrás
pai
commit
3142e59ba2

+ 15
- 0
integration/env.test.js Ver arquivo

@@ -1,3 +1,4 @@
1
+import * as _ from 'lodash';
1 2
 describe('test environment', () => {
2 3
   it('handles object spread', () => {
3 4
     const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
@@ -10,4 +11,18 @@ describe('test environment', () => {
10 11
     const result = await new Promise((r) => r('hello'));
11 12
     expect(result).toEqual('hello');
12 13
   });
14
+
15
+  it('lodash equality tests', () => {
16
+    expect(_.eq('hello', 'hello')).toBe(true);
17
+    expect(_.isEqual('hello', 'hello')).toBe(true);
18
+
19
+    expect(_.eq('hello', Object('hello'))).toBe(false);
20
+    expect(_.isEqual('hello', Object('hello'))).toBe(true);
21
+
22
+    const a = {};
23
+    const b = {};
24
+
25
+    expect(_.eq(a, b)).toBe(false);
26
+    expect(_.isEqual(a, b)).toBe(true);
27
+  });
13 28
 });

+ 7
- 3
playground/e2e/app.test.js Ver arquivo

@@ -8,12 +8,12 @@ describe('app', () => {
8 8
   });
9 9
 
10 10
   it('switch to tab based app', () => {
11
-    elementByLabel('Switch to tab based app').tap();
11
+    elementById('btnSwitchToTabs').tap();
12 12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
13 13
   });
14 14
 
15
-  xit('switch to tabs with side menus', () => {
16
-    elementByLabel('Switch to tab based app with side menus').tap();
15
+  it('switch to tabs with side menus', () => {
16
+    elementById('btnSwitchToTabsWithMenus').tap();
17 17
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
18 18
   });
19 19
 });
@@ -21,3 +21,7 @@ describe('app', () => {
21 21
 function elementByLabel(label) {
22 22
   return element(by.label(label));
23 23
 }
24
+
25
+function elementById(id) {
26
+  return element(by.id(id));
27
+}

+ 14
- 2
playground/src/containers/WelcomeScreen.js Ver arquivo

@@ -4,12 +4,24 @@ import { View, Text, Button } from 'react-native';
4 4
 import Navigation from 'react-native-navigation';
5 5
 
6 6
 class WelcomeScreen extends Component {
7
+  constructor(props) {
8
+    super(props);
9
+  }
10
+
7 11
   render() {
8 12
     return (
9 13
       <View style={styles.root}>
10 14
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
11
-        <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
12
-        <Button title="Switch to tab based app with side menus" onPress={this.onClickSwitchToTabsWithSideMenus} />
15
+        <Button
16
+          testId="btnSwitchToTabs"
17
+          title="Switch to tab based app"
18
+          onPress={this.onClickSwitchToTabs}
19
+        />
20
+        <Button
21
+          testId="btnSwitchToTabsWithMenus"
22
+          title="Switch to tab based app with side menus"
23
+          onPress={this.onClickSwitchToTabsWithSideMenus}
24
+        />
13 25
       </View>
14 26
     );
15 27
   }

+ 62
- 6
src/commands/LayoutTreeParser.js Ver arquivo

@@ -1,4 +1,4 @@
1
-import _ from 'lodash';
1
+import * as _ from 'lodash';
2 2
 
3 3
 export default class LayoutTreeParser {
4 4
   constructor(uniqueIdProvider) {
@@ -6,16 +6,72 @@ export default class LayoutTreeParser {
6 6
   }
7 7
 
8 8
   parseFromSimpleJSON(simpleJsonApi) {
9
-    if (simpleJsonApi.tabs) {
9
+    // TOOD deepclone
10
+
11
+    if (simpleJsonApi.sideMenu) {
10 12
       return {
11
-        type: 'Tabs',
12
-        id: this.uniqueIdProvider.generate(`Tabs`),
13
-        children: _.map(simpleJsonApi.tabs, (t) => this.createContainerStackWithContainer(t.container))
13
+        type: 'SideMenuRoot',
14
+        id: this.uniqueIdProvider.generate('SideMenuRoot'),
15
+        children: this.createSideMenuChildren(simpleJsonApi)
14 16
       };
15 17
     }
18
+    if (simpleJsonApi.tabs) {
19
+      return this.createTabs(simpleJsonApi.tabs);
20
+    }
21
+
16 22
     return this.createContainerStackWithContainer(simpleJsonApi.container);
17 23
   }
18 24
 
25
+  createSideMenuChildren(layout) {
26
+    const children = [];
27
+    if (layout.sideMenu.left) {
28
+      children.push({
29
+        type: 'SideMenuLeft',
30
+        id: this.uniqueIdProvider.generate('SideMenuLeft'),
31
+        children: [
32
+          this.createContainer(layout.sideMenu.left)
33
+        ]
34
+      });
35
+    }
36
+    children.push({
37
+      type: 'SideMenuCenter',
38
+      id: this.uniqueIdProvider.generate('SideMenuCenter'),
39
+      children: [
40
+        this.createContainerStackWithContainer(layout.container)
41
+      ]
42
+    });
43
+    return children;
44
+
45
+    // (simpleJsonApi.sideMenu, (v, k) => {
46
+    //       if (_.isEqual(k, 'left')) {
47
+    //         return {
48
+    //           type: 'SideMenuLeft',
49
+    //           id: this.uniqueIdProvider.generate('SideMenuLeft'),
50
+    //           children: [
51
+    //             this.createContainer(v)
52
+    //           ]
53
+    //         };
54
+    //       } else if (_.isEqual(k, 'right')) {
55
+    //         return {
56
+    //           type: 'SideMenuRight',
57
+    //           id: this.uniqueIdProvider.generate('SideMenuRight'),
58
+    //           children: [
59
+    //             this.createContainer(v)
60
+    //           ]
61
+    //         };
62
+    //       }
63
+    //       return undefined;
64
+    //     })
65
+  }
66
+
67
+  createTabs(tabs) {
68
+    return {
69
+      type: 'Tabs',
70
+      id: this.uniqueIdProvider.generate(`Tabs`),
71
+      children: _.map(tabs, (t) => this.createContainerStackWithContainer(t.container))
72
+    };
73
+  }
74
+
19 75
   createContainerStackWithContainer(container) {
20 76
     return {
21 77
       type: 'ContainerStack',
@@ -28,7 +84,7 @@ export default class LayoutTreeParser {
28 84
 
29 85
   createContainer(container) {
30 86
     return {
31
-      data: _.merge({}, container),
87
+      data: container,
32 88
       type: 'Container',
33 89
       id: this.uniqueIdProvider.generate(`Container`),
34 90
       children: []

+ 25
- 13
src/commands/LayoutTreeParser.test.js Ver arquivo

@@ -127,30 +127,42 @@ describe('LayoutTreeParser', () => {
127 127
   xit('parses side menus', () => {
128 128
     expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
129 129
       .toEqual({
130
-        type: 'SideMenus',
131
-        id: 'SideMenus+UNIQUE_ID',
130
+        type: 'SideMenuRoot',
131
+        id: 'SideMenuRoot+UNIQUE_ID',
132 132
         children: [
133 133
           {
134
-            type: 'Container',
135
-            id: 'Container+UNIQUE_ID',
136
-            data: {
137
-              name: 'com.example.SideMenu'
138
-            },
139
-            children: []
140
-          },
141
-          {
142
-            type: 'ContainerStack',
143
-            id: 'ContainerStack+UNIQUE_ID',
134
+            type: 'SideMenuLeft',
135
+            id: 'SideMenuLeft+UNIQUE_ID',
144 136
             children: [
145 137
               {
146 138
                 type: 'Container',
147 139
                 id: 'Container+UNIQUE_ID',
148 140
                 data: {
149
-                  name: 'com.example.MyScreen'
141
+                  name: 'com.example.SideMenu'
150 142
                 },
151 143
                 children: []
152 144
               }
153 145
             ]
146
+          },
147
+          {
148
+            type: 'SideMenuCenter',
149
+            id: 'SideMenuCenter+UNIQUE_ID',
150
+            children: [
151
+              {
152
+                type: 'ContainerStack',
153
+                id: 'ContainerStack+UNIQUE_ID',
154
+                children: [
155
+                  {
156
+                    type: 'Container',
157
+                    id: 'Container+UNIQUE_ID',
158
+                    data: {
159
+                      name: 'com.example.MyScreen'
160
+                    },
161
+                    children: []
162
+                  }
163
+                ]
164
+              }
165
+            ]
154 166
           }
155 167
         ]
156 168
       });

+ 7
- 2
wallaby.js Ver arquivo

@@ -2,13 +2,18 @@
2 2
 'use strict';
3 3
 process.env.BABEL_ENV = 'test';
4 4
 const babelOptions = require('./package.json').babel.env.test;
5
-module.exports = function(wallaby) {
5
+module.exports = function (wallaby) {
6 6
   return {
7 7
     env: {
8 8
       type: 'node',
9 9
       runner: 'node'
10 10
     },
11 11
 
12
+    // workers: {
13
+    //   initial: 1,
14
+    //   regular: 1
15
+    // },
16
+
12 17
     testFramework: 'jest',
13 18
 
14 19
     files: [
@@ -28,7 +33,7 @@ module.exports = function(wallaby) {
28 33
       '**/*.js': wallaby.compilers.babel(babelOptions)
29 34
     },
30 35
 
31
-    setup: function(w) {
36
+    setup: function (w) {
32 37
       require('babel-polyfill');
33 38
       w.testFramework.configure(require('./package.json').jest);
34 39
     }