Browse Source

side menus

Daniel Zlotin 8 years ago
parent
commit
3142e59ba2

+ 15
- 0
integration/env.test.js View File

1
+import * as _ from 'lodash';
1
 describe('test environment', () => {
2
 describe('test environment', () => {
2
   it('handles object spread', () => {
3
   it('handles object spread', () => {
3
     const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
4
     const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
10
     const result = await new Promise((r) => r('hello'));
11
     const result = await new Promise((r) => r('hello'));
11
     expect(result).toEqual('hello');
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 View File

8
   });
8
   });
9
 
9
 
10
   it('switch to tab based app', () => {
10
   it('switch to tab based app', () => {
11
-    elementByLabel('Switch to tab based app').tap();
11
+    elementById('btnSwitchToTabs').tap();
12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
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
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
17
     // expect(elementByLabel('This is a tab screen')).toBeVisible();
18
   });
18
   });
19
 });
19
 });
21
 function elementByLabel(label) {
21
 function elementByLabel(label) {
22
   return element(by.label(label));
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 View File

4
 import Navigation from 'react-native-navigation';
4
 import Navigation from 'react-native-navigation';
5
 
5
 
6
 class WelcomeScreen extends Component {
6
 class WelcomeScreen extends Component {
7
+  constructor(props) {
8
+    super(props);
9
+  }
10
+
7
   render() {
11
   render() {
8
     return (
12
     return (
9
       <View style={styles.root}>
13
       <View style={styles.root}>
10
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
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
       </View>
25
       </View>
14
     );
26
     );
15
   }
27
   }

+ 62
- 6
src/commands/LayoutTreeParser.js View File

1
-import _ from 'lodash';
1
+import * as _ from 'lodash';
2
 
2
 
3
 export default class LayoutTreeParser {
3
 export default class LayoutTreeParser {
4
   constructor(uniqueIdProvider) {
4
   constructor(uniqueIdProvider) {
6
   }
6
   }
7
 
7
 
8
   parseFromSimpleJSON(simpleJsonApi) {
8
   parseFromSimpleJSON(simpleJsonApi) {
9
-    if (simpleJsonApi.tabs) {
9
+    // TOOD deepclone
10
+
11
+    if (simpleJsonApi.sideMenu) {
10
       return {
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
     return this.createContainerStackWithContainer(simpleJsonApi.container);
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
   createContainerStackWithContainer(container) {
75
   createContainerStackWithContainer(container) {
20
     return {
76
     return {
21
       type: 'ContainerStack',
77
       type: 'ContainerStack',
28
 
84
 
29
   createContainer(container) {
85
   createContainer(container) {
30
     return {
86
     return {
31
-      data: _.merge({}, container),
87
+      data: container,
32
       type: 'Container',
88
       type: 'Container',
33
       id: this.uniqueIdProvider.generate(`Container`),
89
       id: this.uniqueIdProvider.generate(`Container`),
34
       children: []
90
       children: []

+ 25
- 13
src/commands/LayoutTreeParser.test.js View File

127
   xit('parses side menus', () => {
127
   xit('parses side menus', () => {
128
     expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
128
     expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
129
       .toEqual({
129
       .toEqual({
130
-        type: 'SideMenus',
131
-        id: 'SideMenus+UNIQUE_ID',
130
+        type: 'SideMenuRoot',
131
+        id: 'SideMenuRoot+UNIQUE_ID',
132
         children: [
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
             children: [
136
             children: [
145
               {
137
               {
146
                 type: 'Container',
138
                 type: 'Container',
147
                 id: 'Container+UNIQUE_ID',
139
                 id: 'Container+UNIQUE_ID',
148
                 data: {
140
                 data: {
149
-                  name: 'com.example.MyScreen'
141
+                  name: 'com.example.SideMenu'
150
                 },
142
                 },
151
                 children: []
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 View File

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