Daniel Zlotin преди 7 години
родител
ревизия
dc2afc5963
променени са 4 файла, в които са добавени 52 реда и са изтрити 36 реда
  1. 1
    2
      src/commands/Commands.js
  2. 0
    32
      src/commands/Commands.test.js
  3. 5
    2
      src/commands/LayoutBuilder.js
  4. 46
    0
      src/commands/LayoutBuilder.test.js

+ 1
- 2
src/commands/Commands.js Целия файл

@@ -4,8 +4,7 @@ const {NativeNavigation} = NativeModules;
4 4
 import * as LayoutBuilder from './LayoutBuilder';
5 5
 
6 6
 export function startApp(params) {
7
-  const layout = LayoutBuilder.parse(params);
8
-  NativeNavigation.startApp(layout);
7
+  NativeNavigation.startApp(LayoutBuilder.parse(params));
9 8
 }
10 9
 //
11 10
 //function parseParams(params) {

+ 0
- 32
src/commands/Commands.test.js Целия файл

@@ -36,37 +36,5 @@ describe('Commands', () => {
36 36
       });
37 37
     });
38 38
 
39
-    it('adds uniqueId to passed sideMenu', () => {
40
-      uut.startApp({
41
-        container: {
42
-          key: 'com.example.MyScreen'
43
-        },
44
-        sideMenu: {
45
-          left: {
46
-            key: 'com.example.SideMenu1'
47
-          },
48
-          right: {
49
-            key: 'com.example.SideMenu2'
50
-          }
51
-        }
52
-      });
53
-
54
-      expect(mockNativeNavigation.startApp).toHaveBeenCalledWith({
55
-        container: {
56
-          key: 'com.example.MyScreen',
57
-          id: 'container123'
58
-        },
59
-        sideMenu: {
60
-          left: {
61
-            key: 'com.example.SideMenu1',
62
-            id: 'container123'
63
-          },
64
-          right: {
65
-            key: 'com.example.SideMenu2',
66
-            id: 'container123'
67
-          }
68
-        }
69
-      });
70
-    });
71 39
   });
72 40
 });

+ 5
- 2
src/commands/LayoutBuilder.js Целия файл

@@ -1,8 +1,11 @@
1
+import _ from 'lodash';
1 2
 import {uniqueId} from '../providers/UniqueIdProvider';
2 3
 
3 4
 export function parse(params) {
4
-  const layout = params;
5
-  layout.container.id = uniqueId(`container`);
5
+  const layout = _.assign({}, params);
6
+  if (layout.container) {
7
+    layout.container.id = uniqueId(`container`);
8
+  }
6 9
   if (layout.sideMenu) {
7 10
     if (layout.sideMenu.left) {
8 11
       layout.sideMenu.left.id = uniqueId(`container`);

+ 46
- 0
src/commands/LayoutBuilder.test.js Целия файл

@@ -0,0 +1,46 @@
1
+describe('LayoutBuilder', () => {
2
+  let uut;
3
+
4
+  beforeEach(() => {
5
+    jest.mock('../providers/UniqueIdProvider');
6
+    uut = require('./LayoutBuilder');
7
+  });
8
+
9
+  describe('parse', () => {
10
+    it('returns a new object', () => {
11
+      const input = {};
12
+      expect(uut.parse(input)).not.toBe(input);
13
+    });
14
+
15
+    it('adds uniqueId to passed sideMenu', () => {
16
+      expect(uut.parse({
17
+        container: {
18
+          key: 'com.example.MyScreen'
19
+        },
20
+        sideMenu: {
21
+          left: {
22
+            key: 'com.example.SideMenu1'
23
+          },
24
+          right: {
25
+            key: 'com.example.SideMenu2'
26
+          }
27
+        }
28
+      })).toEqual({
29
+        container: {
30
+          key: 'com.example.MyScreen',
31
+          id: 'container123'
32
+        },
33
+        sideMenu: {
34
+          left: {
35
+            key: 'com.example.SideMenu1',
36
+            id: 'container123'
37
+          },
38
+          right: {
39
+            key: 'com.example.SideMenu2',
40
+            id: 'container123'
41
+          }
42
+        }
43
+      });
44
+    });
45
+  });
46
+});