Browse Source

trying all sorts of different layout strategies

Daniel Zlotin 7 years ago
parent
commit
447916eaea

+ 0
- 1
src/commands/Commands.test.js View File

7
       startApp: jest.fn()
7
       startApp: jest.fn()
8
     };
8
     };
9
     require('react-native').NativeModules.NativeNavigation = mockNativeNavigation;
9
     require('react-native').NativeModules.NativeNavigation = mockNativeNavigation;
10
-    jest.mock('../providers/UniqueIdProvider');
11
     uut = require('./Commands');
10
     uut = require('./Commands');
12
   });
11
   });
13
 
12
 

+ 4
- 1
src/commands/LayoutBuilder.js View File

2
 import {uniqueId} from '../providers/UniqueIdProvider';
2
 import {uniqueId} from '../providers/UniqueIdProvider';
3
 
3
 
4
 export function parse(params) {
4
 export function parse(params) {
5
-  const layout = _.assign({}, params);
5
+  const layout = _.merge({}, params);
6
   if (layout.container) {
6
   if (layout.container) {
7
     layout.container.id = uniqueId(`container`);
7
     layout.container.id = uniqueId(`container`);
8
   }
8
   }
14
       layout.sideMenu.right.id = uniqueId(`container`);
14
       layout.sideMenu.right.id = uniqueId(`container`);
15
     }
15
     }
16
   }
16
   }
17
+  if (layout.tabs) {
18
+    _.forEach(layout.tabs, (t) => t.container.id = uniqueId(`container`));
19
+  }
17
   return layout;
20
   return layout;
18
 }
21
 }

+ 78
- 16
src/commands/LayoutBuilder.test.js View File

1
 describe('LayoutBuilder', () => {
1
 describe('LayoutBuilder', () => {
2
-  let uut;
2
+  let LayoutBuilder;
3
 
3
 
4
   beforeEach(() => {
4
   beforeEach(() => {
5
     jest.mock('../providers/UniqueIdProvider');
5
     jest.mock('../providers/UniqueIdProvider');
6
-    uut = require('./LayoutBuilder');
6
+    LayoutBuilder = require('./LayoutBuilder');
7
   });
7
   });
8
 
8
 
9
   describe('parse', () => {
9
   describe('parse', () => {
10
-    it('returns a new object', () => {
11
-      const input = {};
12
-      expect(uut.parse(input)).not.toBe(input);
10
+    it('deeply clones input params', () => {
11
+      const input = {inner: {value: 1}};
12
+      expect(LayoutBuilder.parse(input)).not.toBe(input);
13
+      expect(LayoutBuilder.parse(input).inner).not.toBe(input.inner);
14
+    });
15
+
16
+    it('adds uniqueId to passed container', () => {
17
+      expect(LayoutBuilder.parse({
18
+        container: {
19
+          key: 'com.example.MyScreen'
20
+        }
21
+      })).toEqual({
22
+        container: {
23
+          key: 'com.example.MyScreen',
24
+          id: 'containerUNIQUE'
25
+        }
26
+      });
13
     });
27
     });
14
 
28
 
15
     it('adds uniqueId to passed sideMenu', () => {
29
     it('adds uniqueId to passed sideMenu', () => {
16
-      expect(uut.parse({
30
+      expect(LayoutBuilder.parse({
17
         container: {
31
         container: {
18
           key: 'com.example.MyScreen'
32
           key: 'com.example.MyScreen'
19
         },
33
         },
28
       })).toEqual({
42
       })).toEqual({
29
         container: {
43
         container: {
30
           key: 'com.example.MyScreen',
44
           key: 'com.example.MyScreen',
31
-          id: 'container123'
45
+          id: 'containerUNIQUE'
32
         },
46
         },
33
         sideMenu: {
47
         sideMenu: {
34
           left: {
48
           left: {
35
             key: 'com.example.SideMenu1',
49
             key: 'com.example.SideMenu1',
36
-            id: 'container123'
50
+            id: 'containerUNIQUE'
37
           },
51
           },
38
           right: {
52
           right: {
39
             key: 'com.example.SideMenu2',
53
             key: 'com.example.SideMenu2',
40
-            id: 'container123'
54
+            id: 'containerUNIQUE'
41
           }
55
           }
42
         }
56
         }
43
       });
57
       });
44
     });
58
     });
45
 
59
 
46
-    it('adds uniqueId to passed container', () => {
47
-      expect(uut.parse({
48
-        container: {
49
-          key: 'com.example.MyScreen'
60
+    it('adds uniqueId to passed tabs', () => {
61
+      expect(LayoutBuilder.parse({
62
+        tabs: [
63
+          {
64
+            container: {
65
+              key: 'com.example.FirstTab'
66
+            }
67
+          },
68
+          {
69
+            container: {
70
+              key: 'com.example.SecondTab'
71
+            }
72
+          },
73
+          {
74
+            container: {
75
+              key: 'com.example.FirstTab'
76
+            }
77
+          }
78
+        ],
79
+        sideMenu: {
80
+          left: {
81
+            key: 'com.example.Menu1'
82
+          },
83
+          right: {
84
+            key: 'com.example.Menu2'
85
+          }
50
         }
86
         }
51
       })).toEqual({
87
       })).toEqual({
52
-        container: {
53
-          key: 'com.example.MyScreen',
54
-          id: 'container123'
88
+        tabs: [
89
+          {
90
+            container: {
91
+              key: 'com.example.FirstTab',
92
+              id: 'containerUNIQUE'
93
+            }
94
+          },
95
+          {
96
+            container: {
97
+              key: 'com.example.SecondTab',
98
+              id: 'containerUNIQUE'
99
+            }
100
+          },
101
+          {
102
+            container: {
103
+              key: 'com.example.FirstTab',
104
+              id: 'containerUNIQUE'
105
+            }
106
+          }
107
+        ],
108
+        sideMenu: {
109
+          left: {
110
+            key: 'com.example.Menu1',
111
+            id: 'containerUNIQUE'
112
+          },
113
+          right: {
114
+            key: 'com.example.Menu2',
115
+            id: 'containerUNIQUE'
116
+          }
55
         }
117
         }
56
       });
118
       });
57
     });
119
     });

src/commands/ValidCommands.test.js → src/commands/ValidCommands.js View File

1
-describe('valid commands', () => {
2
-  it('just works', () => {
3
-    //
4
-  });
5
-});
6
-
7
-const singleContainerApp = {
1
+export const singleScreenApp = {
8
   container: {
2
   container: {
9
-    key: 'com.example.FirstTabContainer'
3
+    key: 'com.example.MyScreen'
10
   }
4
   }
11
 };
5
 };
12
 
6
 
13
-const tabBasedApp = {
7
+export const tabBasedApp = {
14
   tabs: [
8
   tabs: [
15
     {
9
     {
16
       container: {
10
       container: {
17
-        key: 'com.example.FirstTabContainer'
11
+        key: 'com.example.FirstTab'
18
       }
12
       }
19
     },
13
     },
20
     {
14
     {
21
       container: {
15
       container: {
22
-        key: 'com.example.SecondTabContainer'
16
+        key: 'com.example.SecondTab'
23
       }
17
       }
24
     },
18
     },
25
     {
19
     {
26
       container: {
20
       container: {
27
-        key: 'com.example.FirstTabContainer'
21
+        key: 'com.example.FirstTab'
28
       }
22
       }
29
     }
23
     }
30
   ]
24
   ]
31
 };
25
 };
32
 
26
 
33
-const singleWithSideMenu = {
27
+export const singleWithSideMenu = {
34
   container: {
28
   container: {
35
-    key: 'com.example.MyContainer'
29
+    key: 'com.example.MyScreen'
36
   },
30
   },
37
   sideMenu: {
31
   sideMenu: {
38
     left: {
32
     left: {
41
   }
35
   }
42
 };
36
 };
43
 
37
 
44
-const singleWithRightSideMenu = {
38
+export const singleWithRightSideMenu = {
45
   container: {
39
   container: {
46
-    key: 'com.example.MyContainer'
40
+    key: 'com.example.MyScreen'
47
   },
41
   },
48
   sideMenu: {
42
   sideMenu: {
49
     right: {
43
     right: {
52
   }
46
   }
53
 };
47
 };
54
 
48
 
55
-const singleWithBothMenus = {
49
+export const singleWithBothMenus = {
56
   container: {
50
   container: {
57
-    key: 'com.example.MyContainer'
51
+    key: 'com.example.MyScreen'
58
   },
52
   },
59
   sideMenu: {
53
   sideMenu: {
60
     left: {
54
     left: {
66
   }
60
   }
67
 };
61
 };
68
 
62
 
69
-const tabBasedWithSideMenu = {
63
+export const tabBasedWithSideMenu = {
70
   tabs: [
64
   tabs: [
71
     {
65
     {
72
       container: {
66
       container: {
73
-        key: 'com.example.FirstTabContainer'
67
+        key: 'com.example.FirstTab'
74
       }
68
       }
75
     },
69
     },
76
     {
70
     {
77
       container: {
71
       container: {
78
-        key: 'com.example.SecondTabContainer'
72
+        key: 'com.example.SecondTab'
79
       }
73
       }
80
     },
74
     },
81
     {
75
     {
82
       container: {
76
       container: {
83
-        key: 'com.example.FirstTabContainer'
77
+        key: 'com.example.FirstTab'
84
       }
78
       }
85
     }
79
     }
86
   ],
80
   ],

+ 1
- 1
src/providers/__mocks__/UniqueIdProvider.js View File

1
 export function uniqueId(prefix) {
1
 export function uniqueId(prefix) {
2
-  return `${prefix}123`;
2
+  return `${prefix}UNIQUE`;
3
 }
3
 }