Kaynağa Gözat

trying all sorts of different layout strategies

Daniel Zlotin 7 yıl önce
ebeveyn
işleme
447916eaea

+ 0
- 1
src/commands/Commands.test.js Dosyayı Görüntüle

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

+ 4
- 1
src/commands/LayoutBuilder.js Dosyayı Görüntüle

@@ -2,7 +2,7 @@ import _ from 'lodash';
2 2
 import {uniqueId} from '../providers/UniqueIdProvider';
3 3
 
4 4
 export function parse(params) {
5
-  const layout = _.assign({}, params);
5
+  const layout = _.merge({}, params);
6 6
   if (layout.container) {
7 7
     layout.container.id = uniqueId(`container`);
8 8
   }
@@ -14,5 +14,8 @@ export function parse(params) {
14 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 20
   return layout;
18 21
 }

+ 78
- 16
src/commands/LayoutBuilder.test.js Dosyayı Görüntüle

@@ -1,19 +1,33 @@
1 1
 describe('LayoutBuilder', () => {
2
-  let uut;
2
+  let LayoutBuilder;
3 3
 
4 4
   beforeEach(() => {
5 5
     jest.mock('../providers/UniqueIdProvider');
6
-    uut = require('./LayoutBuilder');
6
+    LayoutBuilder = require('./LayoutBuilder');
7 7
   });
8 8
 
9 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 29
     it('adds uniqueId to passed sideMenu', () => {
16
-      expect(uut.parse({
30
+      expect(LayoutBuilder.parse({
17 31
         container: {
18 32
           key: 'com.example.MyScreen'
19 33
         },
@@ -28,30 +42,78 @@ describe('LayoutBuilder', () => {
28 42
       })).toEqual({
29 43
         container: {
30 44
           key: 'com.example.MyScreen',
31
-          id: 'container123'
45
+          id: 'containerUNIQUE'
32 46
         },
33 47
         sideMenu: {
34 48
           left: {
35 49
             key: 'com.example.SideMenu1',
36
-            id: 'container123'
50
+            id: 'containerUNIQUE'
37 51
           },
38 52
           right: {
39 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 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 Dosyayı Görüntüle

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

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