|
@@ -4,45 +4,17 @@ describe('LayoutTreeParser', () => {
|
4
|
4
|
let uut;
|
5
|
5
|
|
6
|
6
|
beforeEach(() => {
|
7
|
|
- const uniqueIdProvider = { generate: (prefix) => `${prefix}+UNIQUE_ID` };
|
8
|
7
|
const LayoutTreeParser = require('./LayoutTreeParser').default;
|
9
|
|
- uut = new LayoutTreeParser(uniqueIdProvider);
|
10
|
|
- });
|
11
|
|
-
|
12
|
|
- it('adds uniqueId to containers', () => {
|
13
|
|
- const input = { container: {} };
|
14
|
|
- expect(uut.parseFromSimpleJSON(input))
|
15
|
|
- .toEqual({
|
16
|
|
- type: 'ContainerStack',
|
17
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
18
|
|
- children: [
|
19
|
|
- {
|
20
|
|
- type: 'Container',
|
21
|
|
- id: 'Container+UNIQUE_ID',
|
22
|
|
- data: {},
|
23
|
|
- children: []
|
24
|
|
- }
|
25
|
|
- ],
|
26
|
|
- data: {}
|
27
|
|
- });
|
28
|
|
- });
|
29
|
|
-
|
30
|
|
- it('deep clones to avoid mutations', () => {
|
31
|
|
- const obj = {};
|
32
|
|
- const result = uut.parseFromSimpleJSON({ container: { foo: obj } });
|
33
|
|
- expect(result.children[0].data.foo).not.toBe(obj);
|
|
8
|
+ uut = new LayoutTreeParser();
|
34
|
9
|
});
|
35
|
10
|
|
36
|
11
|
it('parses single screen', () => {
|
37
|
12
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenApp))
|
38
|
13
|
.toEqual({
|
39
|
14
|
type: 'ContainerStack',
|
40
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
41
|
|
- data: {},
|
42
|
15
|
children: [
|
43
|
16
|
{
|
44
|
17
|
type: 'Container',
|
45
|
|
- id: 'Container+UNIQUE_ID',
|
46
|
18
|
data: {
|
47
|
19
|
name: 'com.example.MyScreen'
|
48
|
20
|
},
|
|
@@ -56,12 +28,9 @@ describe('LayoutTreeParser', () => {
|
56
|
28
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams))
|
57
|
29
|
.toEqual({
|
58
|
30
|
type: 'ContainerStack',
|
59
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
60
|
|
- data: {},
|
61
|
31
|
children: [
|
62
|
32
|
{
|
63
|
33
|
type: 'Container',
|
64
|
|
- id: 'Container+UNIQUE_ID',
|
65
|
34
|
children: [],
|
66
|
35
|
data: {
|
67
|
36
|
name: 'com.example.MyScreen',
|
|
@@ -82,17 +51,12 @@ describe('LayoutTreeParser', () => {
|
82
|
51
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedApp))
|
83
|
52
|
.toEqual({
|
84
|
53
|
type: 'Tabs',
|
85
|
|
- id: 'Tabs+UNIQUE_ID',
|
86
|
|
- data: {},
|
87
|
54
|
children: [
|
88
|
55
|
{
|
89
|
56
|
type: 'ContainerStack',
|
90
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
91
|
|
- data: {},
|
92
|
57
|
children: [
|
93
|
58
|
{
|
94
|
59
|
type: 'Container',
|
95
|
|
- id: 'Container+UNIQUE_ID',
|
96
|
60
|
children: [],
|
97
|
61
|
data: {
|
98
|
62
|
name: 'com.example.ATab'
|
|
@@ -102,12 +66,9 @@ describe('LayoutTreeParser', () => {
|
102
|
66
|
},
|
103
|
67
|
{
|
104
|
68
|
type: 'ContainerStack',
|
105
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
106
|
|
- data: {},
|
107
|
69
|
children: [
|
108
|
70
|
{
|
109
|
71
|
type: 'Container',
|
110
|
|
- id: 'Container+UNIQUE_ID',
|
111
|
72
|
children: [],
|
112
|
73
|
data: {
|
113
|
74
|
name: 'com.example.SecondTab'
|
|
@@ -117,12 +78,9 @@ describe('LayoutTreeParser', () => {
|
117
|
78
|
},
|
118
|
79
|
{
|
119
|
80
|
type: 'ContainerStack',
|
120
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
121
|
|
- data: {},
|
122
|
81
|
children: [
|
123
|
82
|
{
|
124
|
83
|
type: 'Container',
|
125
|
|
- id: 'Container+UNIQUE_ID',
|
126
|
84
|
children: [],
|
127
|
85
|
data: {
|
128
|
86
|
name: 'com.example.ATab'
|
|
@@ -138,17 +96,12 @@ describe('LayoutTreeParser', () => {
|
138
|
96
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
|
139
|
97
|
.toEqual({
|
140
|
98
|
type: 'SideMenuRoot',
|
141
|
|
- id: 'SideMenuRoot+UNIQUE_ID',
|
142
|
|
- data: {},
|
143
|
99
|
children: [
|
144
|
100
|
{
|
145
|
101
|
type: 'SideMenuLeft',
|
146
|
|
- id: 'SideMenuLeft+UNIQUE_ID',
|
147
|
|
- data: {},
|
148
|
102
|
children: [
|
149
|
103
|
{
|
150
|
104
|
type: 'Container',
|
151
|
|
- id: 'Container+UNIQUE_ID',
|
152
|
105
|
data: {
|
153
|
106
|
name: 'com.example.SideMenu'
|
154
|
107
|
},
|
|
@@ -158,17 +111,12 @@ describe('LayoutTreeParser', () => {
|
158
|
111
|
},
|
159
|
112
|
{
|
160
|
113
|
type: 'SideMenuCenter',
|
161
|
|
- id: 'SideMenuCenter+UNIQUE_ID',
|
162
|
|
- data: {},
|
163
|
114
|
children: [
|
164
|
115
|
{
|
165
|
116
|
type: 'ContainerStack',
|
166
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
167
|
|
- data: {},
|
168
|
117
|
children: [
|
169
|
118
|
{
|
170
|
119
|
type: 'Container',
|
171
|
|
- id: 'Container+UNIQUE_ID',
|
172
|
120
|
data: {
|
173
|
121
|
name: 'com.example.MyScreen'
|
174
|
122
|
},
|
|
@@ -186,22 +134,15 @@ describe('LayoutTreeParser', () => {
|
186
|
134
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithRightSideMenu))
|
187
|
135
|
.toEqual({
|
188
|
136
|
type: 'SideMenuRoot',
|
189
|
|
- id: 'SideMenuRoot+UNIQUE_ID',
|
190
|
|
- data: {},
|
191
|
137
|
children: [
|
192
|
138
|
{
|
193
|
139
|
type: 'SideMenuCenter',
|
194
|
|
- id: 'SideMenuCenter+UNIQUE_ID',
|
195
|
|
- data: {},
|
196
|
140
|
children: [
|
197
|
141
|
{
|
198
|
142
|
type: 'ContainerStack',
|
199
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
200
|
|
- data: {},
|
201
|
143
|
children: [
|
202
|
144
|
{
|
203
|
145
|
type: 'Container',
|
204
|
|
- id: 'Container+UNIQUE_ID',
|
205
|
146
|
data: {
|
206
|
147
|
name: 'com.example.MyScreen'
|
207
|
148
|
},
|
|
@@ -213,12 +154,9 @@ describe('LayoutTreeParser', () => {
|
213
|
154
|
},
|
214
|
155
|
{
|
215
|
156
|
type: 'SideMenuRight',
|
216
|
|
- id: 'SideMenuRight+UNIQUE_ID',
|
217
|
|
- data: {},
|
218
|
157
|
children: [
|
219
|
158
|
{
|
220
|
159
|
type: 'Container',
|
221
|
|
- id: 'Container+UNIQUE_ID',
|
222
|
160
|
data: {
|
223
|
161
|
name: 'com.example.SideMenu'
|
224
|
162
|
},
|
|
@@ -234,17 +172,12 @@ describe('LayoutTreeParser', () => {
|
234
|
172
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithBothMenus))
|
235
|
173
|
.toEqual({
|
236
|
174
|
type: 'SideMenuRoot',
|
237
|
|
- id: 'SideMenuRoot+UNIQUE_ID',
|
238
|
|
- data: {},
|
239
|
175
|
children: [
|
240
|
176
|
{
|
241
|
177
|
type: 'SideMenuLeft',
|
242
|
|
- id: 'SideMenuLeft+UNIQUE_ID',
|
243
|
|
- data: {},
|
244
|
178
|
children: [
|
245
|
179
|
{
|
246
|
180
|
type: 'Container',
|
247
|
|
- id: 'Container+UNIQUE_ID',
|
248
|
181
|
data: {
|
249
|
182
|
name: 'com.example.Menu1'
|
250
|
183
|
},
|
|
@@ -254,17 +187,12 @@ describe('LayoutTreeParser', () => {
|
254
|
187
|
},
|
255
|
188
|
{
|
256
|
189
|
type: 'SideMenuCenter',
|
257
|
|
- id: 'SideMenuCenter+UNIQUE_ID',
|
258
|
|
- data: {},
|
259
|
190
|
children: [
|
260
|
191
|
{
|
261
|
192
|
type: 'ContainerStack',
|
262
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
263
|
|
- data: {},
|
264
|
193
|
children: [
|
265
|
194
|
{
|
266
|
195
|
type: 'Container',
|
267
|
|
- id: 'Container+UNIQUE_ID',
|
268
|
196
|
data: {
|
269
|
197
|
name: 'com.example.MyScreen'
|
270
|
198
|
},
|
|
@@ -276,12 +204,9 @@ describe('LayoutTreeParser', () => {
|
276
|
204
|
},
|
277
|
205
|
{
|
278
|
206
|
type: 'SideMenuRight',
|
279
|
|
- id: 'SideMenuRight+UNIQUE_ID',
|
280
|
|
- data: {},
|
281
|
207
|
children: [
|
282
|
208
|
{
|
283
|
209
|
type: 'Container',
|
284
|
|
- id: 'Container+UNIQUE_ID',
|
285
|
210
|
data: {
|
286
|
211
|
name: 'com.example.Menu2'
|
287
|
212
|
},
|
|
@@ -297,17 +222,12 @@ describe('LayoutTreeParser', () => {
|
297
|
222
|
expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedWithBothSideMenus))
|
298
|
223
|
.toEqual({
|
299
|
224
|
type: 'SideMenuRoot',
|
300
|
|
- id: 'SideMenuRoot+UNIQUE_ID',
|
301
|
|
- data: {},
|
302
|
225
|
children: [
|
303
|
226
|
{
|
304
|
227
|
type: 'SideMenuLeft',
|
305
|
|
- id: 'SideMenuLeft+UNIQUE_ID',
|
306
|
|
- data: {},
|
307
|
228
|
children: [
|
308
|
229
|
{
|
309
|
230
|
type: 'Container',
|
310
|
|
- id: 'Container+UNIQUE_ID',
|
311
|
231
|
data: {
|
312
|
232
|
name: 'com.example.Menu1'
|
313
|
233
|
},
|
|
@@ -317,22 +237,15 @@ describe('LayoutTreeParser', () => {
|
317
|
237
|
},
|
318
|
238
|
{
|
319
|
239
|
type: 'SideMenuCenter',
|
320
|
|
- id: 'SideMenuCenter+UNIQUE_ID',
|
321
|
|
- data: {},
|
322
|
240
|
children: [
|
323
|
241
|
{
|
324
|
242
|
type: 'Tabs',
|
325
|
|
- id: 'Tabs+UNIQUE_ID',
|
326
|
|
- data: {},
|
327
|
243
|
children: [
|
328
|
244
|
{
|
329
|
245
|
type: 'ContainerStack',
|
330
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
331
|
|
- data: {},
|
332
|
246
|
children: [
|
333
|
247
|
{
|
334
|
248
|
type: 'Container',
|
335
|
|
- id: 'Container+UNIQUE_ID',
|
336
|
249
|
data: {
|
337
|
250
|
name: 'com.example.FirstTab'
|
338
|
251
|
},
|
|
@@ -342,12 +255,9 @@ describe('LayoutTreeParser', () => {
|
342
|
255
|
},
|
343
|
256
|
{
|
344
|
257
|
type: 'ContainerStack',
|
345
|
|
- id: 'ContainerStack+UNIQUE_ID',
|
346
|
|
- data: {},
|
347
|
258
|
children: [
|
348
|
259
|
{
|
349
|
260
|
type: 'Container',
|
350
|
|
- id: 'Container+UNIQUE_ID',
|
351
|
261
|
data: {
|
352
|
262
|
name: 'com.example.SecondTab'
|
353
|
263
|
},
|
|
@@ -361,12 +271,9 @@ describe('LayoutTreeParser', () => {
|
361
|
271
|
},
|
362
|
272
|
{
|
363
|
273
|
type: 'SideMenuRight',
|
364
|
|
- id: 'SideMenuRight+UNIQUE_ID',
|
365
|
|
- data: {},
|
366
|
274
|
children: [
|
367
|
275
|
{
|
368
|
276
|
type: 'Container',
|
369
|
|
- id: 'Container+UNIQUE_ID',
|
370
|
277
|
data: {
|
371
|
278
|
name: 'com.example.Menu2'
|
372
|
279
|
},
|