|
@@ -1,7 +1,6 @@
|
1
|
1
|
import * as _ from 'lodash';
|
2
|
2
|
import { LayoutTreeParser } from './LayoutTreeParser';
|
3
|
|
-import { LayoutTypes } from './LayoutTypes';
|
4
|
|
-import { Examples } from './LayoutExamples';
|
|
3
|
+import { LayoutType } from './values/LayoutType';
|
5
|
4
|
|
6
|
5
|
describe('LayoutTreeParser', () => {
|
7
|
6
|
let uut;
|
|
@@ -16,9 +15,9 @@ describe('LayoutTreeParser', () => {
|
16
|
15
|
});
|
17
|
16
|
|
18
|
17
|
it('single component', () => {
|
19
|
|
- expect(uut.parse(Examples.singleComponent)).toEqual({
|
20
|
|
- type: LayoutTypes.Component,
|
21
|
|
- data: { name: 'MyReactComponent', options: Examples.options, passProps: Examples.passProps },
|
|
18
|
+ expect(uut.parse(LayoutExamples.singleComponent)).toEqual({
|
|
19
|
+ type: LayoutType.Component,
|
|
20
|
+ data: { name: 'MyReactComponent', options: LayoutExamples.options, passProps: LayoutExamples.passProps },
|
22
|
21
|
children: []
|
23
|
22
|
});
|
24
|
23
|
});
|
|
@@ -27,33 +26,33 @@ describe('LayoutTreeParser', () => {
|
27
|
26
|
const result = uut.parse({
|
28
|
27
|
component: {
|
29
|
28
|
name: 'MyScreen',
|
30
|
|
- passProps: Examples.passProps
|
|
29
|
+ passProps: LayoutExamples.passProps
|
31
|
30
|
}
|
32
|
31
|
});
|
33
|
32
|
expect(result).toEqual({
|
34
|
|
- type: LayoutTypes.Component,
|
35
|
|
- data: { name: 'MyScreen', passProps: Examples.passProps },
|
|
33
|
+ type: LayoutType.Component,
|
|
34
|
+ data: { name: 'MyScreen', passProps: LayoutExamples.passProps },
|
36
|
35
|
children: []
|
37
|
36
|
});
|
38
|
|
- expect(result.data.passProps).toBe(Examples.passProps);
|
|
37
|
+ expect(result.data.passProps).toBe(LayoutExamples.passProps);
|
39
|
38
|
expect(result.data.passProps.fnProp()).toEqual('Hello from a function');
|
40
|
39
|
});
|
41
|
40
|
|
42
|
41
|
it('stack of components with top bar', () => {
|
43
|
|
- expect(uut.parse(Examples.stackWithTopBar)).toEqual({
|
44
|
|
- type: LayoutTypes.Stack,
|
|
42
|
+ expect(uut.parse(LayoutExamples.stackWithTopBar)).toEqual({
|
|
43
|
+ type: LayoutType.Stack,
|
45
|
44
|
data: {
|
46
|
|
- options: Examples.options
|
|
45
|
+ options: LayoutExamples.options
|
47
|
46
|
},
|
48
|
47
|
children: [
|
49
|
48
|
{
|
50
|
|
- type: LayoutTypes.Component,
|
|
49
|
+ type: LayoutType.Component,
|
51
|
50
|
data: { name: 'MyReactComponent1' },
|
52
|
51
|
children: []
|
53
|
52
|
},
|
54
|
53
|
{
|
55
|
|
- type: LayoutTypes.Component,
|
56
|
|
- data: { name: 'MyReactComponent2', options: Examples.options },
|
|
54
|
+ type: LayoutType.Component,
|
|
55
|
+ data: { name: 'MyReactComponent2', options: LayoutExamples.options },
|
57
|
56
|
children: []
|
58
|
57
|
}
|
59
|
58
|
]
|
|
@@ -61,31 +60,31 @@ describe('LayoutTreeParser', () => {
|
61
|
60
|
});
|
62
|
61
|
|
63
|
62
|
it('bottom tabs', () => {
|
64
|
|
- const result = uut.parse(Examples.bottomTabs);
|
|
63
|
+ const result = uut.parse(LayoutExamples.bottomTabs);
|
65
|
64
|
expect(_.keys(result)).toEqual(['type', 'data', 'children']);
|
66
|
|
- expect(result.type).toEqual(LayoutTypes.BottomTabs);
|
|
65
|
+ expect(result.type).toEqual(LayoutType.BottomTabs);
|
67
|
66
|
expect(result.data).toEqual({});
|
68
|
67
|
expect(result.children.length).toEqual(3);
|
69
|
|
- expect(result.children[0].type).toEqual(LayoutTypes.Stack);
|
70
|
|
- expect(result.children[1].type).toEqual(LayoutTypes.Stack);
|
71
|
|
- expect(result.children[2].type).toEqual(LayoutTypes.Component);
|
|
68
|
+ expect(result.children[0].type).toEqual(LayoutType.Stack);
|
|
69
|
+ expect(result.children[1].type).toEqual(LayoutType.Stack);
|
|
70
|
+ expect(result.children[2].type).toEqual(LayoutType.Component);
|
72
|
71
|
});
|
73
|
72
|
|
74
|
73
|
it('side menus', () => {
|
75
|
|
- const result = uut.parse(Examples.sideMenu);
|
|
74
|
+ const result = uut.parse(LayoutExamples.sideMenu);
|
76
|
75
|
expect(_.keys(result)).toEqual(['type', 'data', 'children']);
|
77
|
|
- expect(result.type).toEqual(LayoutTypes.SideMenuRoot);
|
|
76
|
+ expect(result.type).toEqual(LayoutType.SideMenuRoot);
|
78
|
77
|
expect(result.data).toEqual({});
|
79
|
78
|
expect(result.children.length).toEqual(3);
|
80
|
|
- expect(result.children[0].type).toEqual(LayoutTypes.SideMenuLeft);
|
81
|
|
- expect(result.children[1].type).toEqual(LayoutTypes.SideMenuCenter);
|
82
|
|
- expect(result.children[2].type).toEqual(LayoutTypes.SideMenuRight);
|
|
79
|
+ expect(result.children[0].type).toEqual(LayoutType.SideMenuLeft);
|
|
80
|
+ expect(result.children[1].type).toEqual(LayoutType.SideMenuCenter);
|
|
81
|
+ expect(result.children[2].type).toEqual(LayoutType.SideMenuRight);
|
83
|
82
|
expect(result.children[0].children.length).toEqual(1);
|
84
|
|
- expect(result.children[0].children[0].type).toEqual(LayoutTypes.Component);
|
|
83
|
+ expect(result.children[0].children[0].type).toEqual(LayoutType.Component);
|
85
|
84
|
expect(result.children[1].children.length).toEqual(1);
|
86
|
|
- expect(result.children[1].children[0].type).toEqual(LayoutTypes.Stack);
|
|
85
|
+ expect(result.children[1].children[0].type).toEqual(LayoutType.Stack);
|
87
|
86
|
expect(result.children[2].children.length).toEqual(1);
|
88
|
|
- expect(result.children[2].children[0].type).toEqual(LayoutTypes.Component);
|
|
87
|
+ expect(result.children[2].children[0].type).toEqual(LayoutType.Component);
|
89
|
88
|
});
|
90
|
89
|
|
91
|
90
|
it('side menu center is require', () => {
|
|
@@ -93,20 +92,20 @@ describe('LayoutTreeParser', () => {
|
93
|
92
|
});
|
94
|
93
|
|
95
|
94
|
it('top tabs', () => {
|
96
|
|
- const result = uut.parse(Examples.topTabs);
|
|
95
|
+ const result = uut.parse(LayoutExamples.topTabs);
|
97
|
96
|
expect(_.keys(result)).toEqual(['type', 'data', 'children']);
|
98
|
|
- expect(result.type).toEqual(LayoutTypes.TopTabs);
|
99
|
|
- expect(result.data).toEqual({ options: Examples.options });
|
|
97
|
+ expect(result.type).toEqual(LayoutType.TopTabs);
|
|
98
|
+ expect(result.data).toEqual({ options: LayoutExamples.options });
|
100
|
99
|
expect(result.children.length).toEqual(5);
|
101
|
|
- expect(result.children[0].type).toEqual(LayoutTypes.Component);
|
102
|
|
- expect(result.children[1].type).toEqual(LayoutTypes.Component);
|
103
|
|
- expect(result.children[2].type).toEqual(LayoutTypes.Component);
|
104
|
|
- expect(result.children[3].type).toEqual(LayoutTypes.Component);
|
105
|
|
- expect(result.children[4].type).toEqual(LayoutTypes.Stack);
|
|
100
|
+ expect(result.children[0].type).toEqual(LayoutType.Component);
|
|
101
|
+ expect(result.children[1].type).toEqual(LayoutType.Component);
|
|
102
|
+ expect(result.children[2].type).toEqual(LayoutType.Component);
|
|
103
|
+ expect(result.children[3].type).toEqual(LayoutType.Component);
|
|
104
|
+ expect(result.children[4].type).toEqual(LayoutType.Stack);
|
106
|
105
|
});
|
107
|
106
|
|
108
|
107
|
it('complex layout example', () => {
|
109
|
|
- const result = uut.parse(Examples.complexLayout);
|
|
108
|
+ const result = uut.parse(LayoutExamples.complexLayout);
|
110
|
109
|
expect(result.type).toEqual('SideMenuRoot');
|
111
|
110
|
expect(result.children[1].type).toEqual('SideMenuCenter');
|
112
|
111
|
expect(result.children[1].children[0].type).toEqual('BottomTabs');
|
|
@@ -127,3 +126,121 @@ describe('LayoutTreeParser', () => {
|
127
|
126
|
expect(uut.parse({ sideMenu: { options, center: { component: {} } } }).data.options).toBe(options);
|
128
|
127
|
});
|
129
|
128
|
});
|
|
129
|
+
|
|
130
|
+const LayoutExamples = {
|
|
131
|
+ passProps: {
|
|
132
|
+ strProp: 'string prop',
|
|
133
|
+ numProp: 12345,
|
|
134
|
+ objProp: { inner: { foo: 'bar' } },
|
|
135
|
+ fnProp: () => 'Hello from a function'
|
|
136
|
+ },
|
|
137
|
+
|
|
138
|
+ options: {
|
|
139
|
+ topBar: {
|
|
140
|
+ title: 'Hello1'
|
|
141
|
+ }
|
|
142
|
+ },
|
|
143
|
+
|
|
144
|
+ singleComponent: {
|
|
145
|
+ component: {
|
|
146
|
+ name: 'MyReactComponent',
|
|
147
|
+ options: this.options,
|
|
148
|
+ passProps: this.passProps
|
|
149
|
+ }
|
|
150
|
+ },
|
|
151
|
+
|
|
152
|
+ stackWithTopBar: {
|
|
153
|
+ stack: {
|
|
154
|
+ children: [
|
|
155
|
+ {
|
|
156
|
+ component: {
|
|
157
|
+ name: 'MyReactComponent1'
|
|
158
|
+ }
|
|
159
|
+ },
|
|
160
|
+ {
|
|
161
|
+ component: {
|
|
162
|
+ name: 'MyReactComponent2',
|
|
163
|
+ options: this.options
|
|
164
|
+ }
|
|
165
|
+ }
|
|
166
|
+ ],
|
|
167
|
+ options: this.options
|
|
168
|
+ }
|
|
169
|
+ },
|
|
170
|
+
|
|
171
|
+ bottomTabs: {
|
|
172
|
+ bottomTabs: {
|
|
173
|
+ children: [
|
|
174
|
+ { ...this.stackWithTopBar },
|
|
175
|
+ { ...this.stackWithTopBar },
|
|
176
|
+ {
|
|
177
|
+ component: {
|
|
178
|
+ name: 'MyReactComponent1'
|
|
179
|
+ }
|
|
180
|
+ }
|
|
181
|
+ ]
|
|
182
|
+ }
|
|
183
|
+ },
|
|
184
|
+
|
|
185
|
+ sideMenu: {
|
|
186
|
+ sideMenu: {
|
|
187
|
+ left: { ...this.singleComponent },
|
|
188
|
+ center: { ...this.stackWithTopBar },
|
|
189
|
+ right: { ...this.singleComponent }
|
|
190
|
+ }
|
|
191
|
+ },
|
|
192
|
+
|
|
193
|
+ topTabs: {
|
|
194
|
+ topTabs: {
|
|
195
|
+ children: [
|
|
196
|
+ { ...this.singleComponent },
|
|
197
|
+ { ...this.singleComponent },
|
|
198
|
+ { ...this.singleComponent },
|
|
199
|
+ { ...this.singleComponent },
|
|
200
|
+ { ...this.stackWithTopBar }
|
|
201
|
+ ],
|
|
202
|
+ options: this.options
|
|
203
|
+ }
|
|
204
|
+ },
|
|
205
|
+
|
|
206
|
+ complexLayout: {
|
|
207
|
+ sideMenu: {
|
|
208
|
+ left: { ...this.singleComponent },
|
|
209
|
+ center: {
|
|
210
|
+ bottomTabs: {
|
|
211
|
+ children: [
|
|
212
|
+ { ...this.stackWithTopBar },
|
|
213
|
+ { ...this.stackWithTopBar },
|
|
214
|
+ {
|
|
215
|
+ stack: {
|
|
216
|
+ children: [
|
|
217
|
+ {
|
|
218
|
+ topTabs: {
|
|
219
|
+ children: [
|
|
220
|
+ { ...this.stackWithTopBar },
|
|
221
|
+ { ...this.stackWithTopBar },
|
|
222
|
+ {
|
|
223
|
+ topTabs: {
|
|
224
|
+ options: this.options,
|
|
225
|
+ children: [
|
|
226
|
+ { ...this.singleComponent },
|
|
227
|
+ { ...this.singleComponent },
|
|
228
|
+ { ...this.singleComponent },
|
|
229
|
+ { ...this.singleComponent },
|
|
230
|
+ { ...this.stackWithTopBar }
|
|
231
|
+ ]
|
|
232
|
+ }
|
|
233
|
+ }
|
|
234
|
+ ]
|
|
235
|
+ }
|
|
236
|
+ }
|
|
237
|
+ ]
|
|
238
|
+ }
|
|
239
|
+ }
|
|
240
|
+ ]
|
|
241
|
+ }
|
|
242
|
+ }
|
|
243
|
+ }
|
|
244
|
+ }
|
|
245
|
+}
|
|
246
|
+
|