|
@@ -1,287 +1,295 @@
|
1
|
1
|
import * as SimpleLayouts from './SimpleLayouts';
|
|
2
|
+import LayoutTreeParser from './LayoutTreeParser';
|
2
|
3
|
|
3
|
4
|
describe('LayoutTreeParser', () => {
|
4
|
5
|
let uut;
|
5
|
6
|
|
6
|
7
|
beforeEach(() => {
|
7
|
|
- const LayoutTreeParser = require('./LayoutTreeParser').default;
|
8
|
8
|
uut = new LayoutTreeParser();
|
9
|
9
|
});
|
10
|
10
|
|
11
|
|
- it('parses single screen', () => {
|
12
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenApp))
|
13
|
|
- .toEqual({
|
14
|
|
- type: 'ContainerStack',
|
15
|
|
- children: [
|
16
|
|
- {
|
17
|
|
- type: 'Container',
|
18
|
|
- data: {
|
19
|
|
- name: 'com.example.MyScreen'
|
20
|
|
- },
|
21
|
|
- children: []
|
22
|
|
- }
|
23
|
|
- ]
|
24
|
|
- });
|
25
|
|
- });
|
|
11
|
+ describe('parseFromSimpleJSON', () => {
|
|
12
|
+ it('parses single screen', () => {
|
|
13
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenApp))
|
|
14
|
+ .toEqual({
|
|
15
|
+ type: 'ContainerStack',
|
|
16
|
+ children: [
|
|
17
|
+ {
|
|
18
|
+ type: 'Container',
|
|
19
|
+ data: {
|
|
20
|
+ name: 'com.example.MyScreen'
|
|
21
|
+ },
|
|
22
|
+ children: []
|
|
23
|
+ }
|
|
24
|
+ ]
|
|
25
|
+ });
|
|
26
|
+ });
|
26
|
27
|
|
27
|
|
- it('parses single screen with props', () => {
|
28
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams))
|
29
|
|
- .toEqual({
|
30
|
|
- type: 'ContainerStack',
|
31
|
|
- children: [
|
32
|
|
- {
|
33
|
|
- type: 'Container',
|
34
|
|
- children: [],
|
35
|
|
- data: {
|
36
|
|
- name: 'com.example.MyScreen',
|
37
|
|
- passProps: SimpleLayouts.passProps,
|
38
|
|
- style: {},
|
39
|
|
- buttons: {}
|
|
28
|
+ it('parses single screen with props', () => {
|
|
29
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams))
|
|
30
|
+ .toEqual({
|
|
31
|
+ type: 'ContainerStack',
|
|
32
|
+ children: [
|
|
33
|
+ {
|
|
34
|
+ type: 'Container',
|
|
35
|
+ children: [],
|
|
36
|
+ data: {
|
|
37
|
+ name: 'com.example.MyScreen',
|
|
38
|
+ passProps: SimpleLayouts.passProps,
|
|
39
|
+ style: {},
|
|
40
|
+ buttons: {}
|
|
41
|
+ }
|
40
|
42
|
}
|
41
|
|
- }
|
42
|
|
- ]
|
43
|
|
- });
|
44
|
|
- const parsedPropsFn = uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams)
|
45
|
|
- .children[0].data.passProps.fnProp;
|
46
|
|
- expect(parsedPropsFn).toBe(SimpleLayouts.passProps.fnProp);
|
47
|
|
- expect(parsedPropsFn()).toEqual('Hello from a function');
|
48
|
|
- });
|
|
43
|
+ ]
|
|
44
|
+ });
|
|
45
|
+ const parsedPropsFn = uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams)
|
|
46
|
+ .children[0].data.passProps.fnProp;
|
|
47
|
+ expect(parsedPropsFn).toBe(SimpleLayouts.passProps.fnProp);
|
|
48
|
+ expect(parsedPropsFn()).toEqual('Hello from a function');
|
|
49
|
+ });
|
49
|
50
|
|
50
|
|
- it('parses tab based', () => {
|
51
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedApp))
|
52
|
|
- .toEqual({
|
53
|
|
- type: 'Tabs',
|
54
|
|
- children: [
|
55
|
|
- {
|
56
|
|
- type: 'ContainerStack',
|
57
|
|
- children: [
|
58
|
|
- {
|
59
|
|
- type: 'Container',
|
60
|
|
- children: [],
|
61
|
|
- data: {
|
62
|
|
- name: 'com.example.ATab'
|
|
51
|
+ it('parses tab based', () => {
|
|
52
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedApp))
|
|
53
|
+ .toEqual({
|
|
54
|
+ type: 'Tabs',
|
|
55
|
+ children: [
|
|
56
|
+ {
|
|
57
|
+ type: 'ContainerStack',
|
|
58
|
+ children: [
|
|
59
|
+ {
|
|
60
|
+ type: 'Container',
|
|
61
|
+ children: [],
|
|
62
|
+ data: {
|
|
63
|
+ name: 'com.example.ATab'
|
|
64
|
+ }
|
63
|
65
|
}
|
64
|
|
- }
|
65
|
|
- ]
|
66
|
|
- },
|
67
|
|
- {
|
68
|
|
- type: 'ContainerStack',
|
69
|
|
- children: [
|
70
|
|
- {
|
71
|
|
- type: 'Container',
|
72
|
|
- children: [],
|
73
|
|
- data: {
|
74
|
|
- name: 'com.example.SecondTab'
|
|
66
|
+ ]
|
|
67
|
+ },
|
|
68
|
+ {
|
|
69
|
+ type: 'ContainerStack',
|
|
70
|
+ children: [
|
|
71
|
+ {
|
|
72
|
+ type: 'Container',
|
|
73
|
+ children: [],
|
|
74
|
+ data: {
|
|
75
|
+ name: 'com.example.SecondTab'
|
|
76
|
+ }
|
75
|
77
|
}
|
76
|
|
- }
|
77
|
|
- ]
|
78
|
|
- },
|
79
|
|
- {
|
80
|
|
- type: 'ContainerStack',
|
81
|
|
- children: [
|
82
|
|
- {
|
83
|
|
- type: 'Container',
|
84
|
|
- children: [],
|
85
|
|
- data: {
|
86
|
|
- name: 'com.example.ATab'
|
|
78
|
+ ]
|
|
79
|
+ },
|
|
80
|
+ {
|
|
81
|
+ type: 'ContainerStack',
|
|
82
|
+ children: [
|
|
83
|
+ {
|
|
84
|
+ type: 'Container',
|
|
85
|
+ children: [],
|
|
86
|
+ data: {
|
|
87
|
+ name: 'com.example.ATab'
|
|
88
|
+ }
|
87
|
89
|
}
|
88
|
|
- }
|
89
|
|
- ]
|
90
|
|
- }
|
91
|
|
- ]
|
92
|
|
- });
|
93
|
|
- });
|
|
90
|
+ ]
|
|
91
|
+ }
|
|
92
|
+ ]
|
|
93
|
+ });
|
|
94
|
+ });
|
94
|
95
|
|
95
|
|
- it('parses side menus', () => {
|
96
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
|
97
|
|
- .toEqual({
|
98
|
|
- type: 'SideMenuRoot',
|
99
|
|
- children: [
|
100
|
|
- {
|
101
|
|
- type: 'SideMenuLeft',
|
102
|
|
- children: [
|
103
|
|
- {
|
104
|
|
- type: 'Container',
|
105
|
|
- data: {
|
106
|
|
- name: 'com.example.SideMenu'
|
107
|
|
- },
|
108
|
|
- children: []
|
109
|
|
- }
|
110
|
|
- ]
|
111
|
|
- },
|
112
|
|
- {
|
113
|
|
- type: 'SideMenuCenter',
|
114
|
|
- children: [
|
115
|
|
- {
|
116
|
|
- type: 'ContainerStack',
|
117
|
|
- children: [
|
118
|
|
- {
|
119
|
|
- type: 'Container',
|
120
|
|
- data: {
|
121
|
|
- name: 'com.example.MyScreen'
|
122
|
|
- },
|
123
|
|
- children: []
|
124
|
|
- }
|
125
|
|
- ]
|
126
|
|
- }
|
127
|
|
- ]
|
128
|
|
- }
|
129
|
|
- ]
|
130
|
|
- });
|
131
|
|
- });
|
|
96
|
+ it('parses side menus', () => {
|
|
97
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
|
|
98
|
+ .toEqual({
|
|
99
|
+ type: 'SideMenuRoot',
|
|
100
|
+ children: [
|
|
101
|
+ {
|
|
102
|
+ type: 'SideMenuLeft',
|
|
103
|
+ children: [
|
|
104
|
+ {
|
|
105
|
+ type: 'Container',
|
|
106
|
+ data: {
|
|
107
|
+ name: 'com.example.SideMenu'
|
|
108
|
+ },
|
|
109
|
+ children: []
|
|
110
|
+ }
|
|
111
|
+ ]
|
|
112
|
+ },
|
|
113
|
+ {
|
|
114
|
+ type: 'SideMenuCenter',
|
|
115
|
+ children: [
|
|
116
|
+ {
|
|
117
|
+ type: 'ContainerStack',
|
|
118
|
+ children: [
|
|
119
|
+ {
|
|
120
|
+ type: 'Container',
|
|
121
|
+ data: {
|
|
122
|
+ name: 'com.example.MyScreen'
|
|
123
|
+ },
|
|
124
|
+ children: []
|
|
125
|
+ }
|
|
126
|
+ ]
|
|
127
|
+ }
|
|
128
|
+ ]
|
|
129
|
+ }
|
|
130
|
+ ]
|
|
131
|
+ });
|
|
132
|
+ });
|
132
|
133
|
|
133
|
|
- it('parses side menu right', () => {
|
134
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithRightSideMenu))
|
135
|
|
- .toEqual({
|
136
|
|
- type: 'SideMenuRoot',
|
137
|
|
- children: [
|
138
|
|
- {
|
139
|
|
- type: 'SideMenuCenter',
|
140
|
|
- children: [
|
141
|
|
- {
|
142
|
|
- type: 'ContainerStack',
|
143
|
|
- children: [
|
144
|
|
- {
|
145
|
|
- type: 'Container',
|
146
|
|
- data: {
|
147
|
|
- name: 'com.example.MyScreen'
|
148
|
|
- },
|
149
|
|
- children: []
|
150
|
|
- }
|
151
|
|
- ]
|
152
|
|
- }
|
153
|
|
- ]
|
154
|
|
- },
|
155
|
|
- {
|
156
|
|
- type: 'SideMenuRight',
|
157
|
|
- children: [
|
158
|
|
- {
|
159
|
|
- type: 'Container',
|
160
|
|
- data: {
|
161
|
|
- name: 'com.example.SideMenu'
|
162
|
|
- },
|
163
|
|
- children: []
|
164
|
|
- }
|
165
|
|
- ]
|
166
|
|
- }
|
167
|
|
- ]
|
168
|
|
- });
|
169
|
|
- });
|
|
134
|
+ it('parses side menu right', () => {
|
|
135
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithRightSideMenu))
|
|
136
|
+ .toEqual({
|
|
137
|
+ type: 'SideMenuRoot',
|
|
138
|
+ children: [
|
|
139
|
+ {
|
|
140
|
+ type: 'SideMenuCenter',
|
|
141
|
+ children: [
|
|
142
|
+ {
|
|
143
|
+ type: 'ContainerStack',
|
|
144
|
+ children: [
|
|
145
|
+ {
|
|
146
|
+ type: 'Container',
|
|
147
|
+ data: {
|
|
148
|
+ name: 'com.example.MyScreen'
|
|
149
|
+ },
|
|
150
|
+ children: []
|
|
151
|
+ }
|
|
152
|
+ ]
|
|
153
|
+ }
|
|
154
|
+ ]
|
|
155
|
+ },
|
|
156
|
+ {
|
|
157
|
+ type: 'SideMenuRight',
|
|
158
|
+ children: [
|
|
159
|
+ {
|
|
160
|
+ type: 'Container',
|
|
161
|
+ data: {
|
|
162
|
+ name: 'com.example.SideMenu'
|
|
163
|
+ },
|
|
164
|
+ children: []
|
|
165
|
+ }
|
|
166
|
+ ]
|
|
167
|
+ }
|
|
168
|
+ ]
|
|
169
|
+ });
|
|
170
|
+ });
|
170
|
171
|
|
171
|
|
- it('parses both side menus', () => {
|
172
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithBothMenus))
|
173
|
|
- .toEqual({
|
174
|
|
- type: 'SideMenuRoot',
|
175
|
|
- children: [
|
176
|
|
- {
|
177
|
|
- type: 'SideMenuLeft',
|
178
|
|
- children: [
|
179
|
|
- {
|
180
|
|
- type: 'Container',
|
181
|
|
- data: {
|
182
|
|
- name: 'com.example.Menu1'
|
183
|
|
- },
|
184
|
|
- children: []
|
185
|
|
- }
|
186
|
|
- ]
|
187
|
|
- },
|
188
|
|
- {
|
189
|
|
- type: 'SideMenuCenter',
|
190
|
|
- children: [
|
191
|
|
- {
|
192
|
|
- type: 'ContainerStack',
|
193
|
|
- children: [
|
194
|
|
- {
|
195
|
|
- type: 'Container',
|
196
|
|
- data: {
|
197
|
|
- name: 'com.example.MyScreen'
|
|
172
|
+ it('parses both side menus', () => {
|
|
173
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithBothMenus))
|
|
174
|
+ .toEqual({
|
|
175
|
+ type: 'SideMenuRoot',
|
|
176
|
+ children: [
|
|
177
|
+ {
|
|
178
|
+ type: 'SideMenuLeft',
|
|
179
|
+ children: [
|
|
180
|
+ {
|
|
181
|
+ type: 'Container',
|
|
182
|
+ data: {
|
|
183
|
+ name: 'com.example.Menu1'
|
|
184
|
+ },
|
|
185
|
+ children: []
|
|
186
|
+ }
|
|
187
|
+ ]
|
|
188
|
+ },
|
|
189
|
+ {
|
|
190
|
+ type: 'SideMenuCenter',
|
|
191
|
+ children: [
|
|
192
|
+ {
|
|
193
|
+ type: 'ContainerStack',
|
|
194
|
+ children: [
|
|
195
|
+ {
|
|
196
|
+ type: 'Container',
|
|
197
|
+ data: {
|
|
198
|
+ name: 'com.example.MyScreen'
|
|
199
|
+ },
|
|
200
|
+ children: []
|
|
201
|
+ }
|
|
202
|
+ ]
|
|
203
|
+ }
|
|
204
|
+ ]
|
|
205
|
+ },
|
|
206
|
+ {
|
|
207
|
+ type: 'SideMenuRight',
|
|
208
|
+ children: [
|
|
209
|
+ {
|
|
210
|
+ type: 'Container',
|
|
211
|
+ data: {
|
|
212
|
+ name: 'com.example.Menu2'
|
|
213
|
+ },
|
|
214
|
+ children: []
|
|
215
|
+ }
|
|
216
|
+ ]
|
|
217
|
+ }
|
|
218
|
+ ]
|
|
219
|
+ });
|
|
220
|
+ });
|
|
221
|
+
|
|
222
|
+ it('parses tabs with side menus', () => {
|
|
223
|
+ expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedWithBothSideMenus))
|
|
224
|
+ .toEqual({
|
|
225
|
+ type: 'SideMenuRoot',
|
|
226
|
+ children: [
|
|
227
|
+ {
|
|
228
|
+ type: 'SideMenuLeft',
|
|
229
|
+ children: [
|
|
230
|
+ {
|
|
231
|
+ type: 'Container',
|
|
232
|
+ data: {
|
|
233
|
+ name: 'com.example.Menu1'
|
|
234
|
+ },
|
|
235
|
+ children: []
|
|
236
|
+ }
|
|
237
|
+ ]
|
|
238
|
+ },
|
|
239
|
+ {
|
|
240
|
+ type: 'SideMenuCenter',
|
|
241
|
+ children: [
|
|
242
|
+ {
|
|
243
|
+ type: 'Tabs',
|
|
244
|
+ children: [
|
|
245
|
+ {
|
|
246
|
+ type: 'ContainerStack',
|
|
247
|
+ children: [
|
|
248
|
+ {
|
|
249
|
+ type: 'Container',
|
|
250
|
+ data: {
|
|
251
|
+ name: 'com.example.FirstTab'
|
|
252
|
+ },
|
|
253
|
+ children: []
|
|
254
|
+ }
|
|
255
|
+ ]
|
198
|
256
|
},
|
199
|
|
- children: []
|
200
|
|
- }
|
201
|
|
- ]
|
202
|
|
- }
|
203
|
|
- ]
|
204
|
|
- },
|
205
|
|
- {
|
206
|
|
- type: 'SideMenuRight',
|
207
|
|
- children: [
|
208
|
|
- {
|
209
|
|
- type: 'Container',
|
210
|
|
- data: {
|
211
|
|
- name: 'com.example.Menu2'
|
212
|
|
- },
|
213
|
|
- children: []
|
214
|
|
- }
|
215
|
|
- ]
|
216
|
|
- }
|
217
|
|
- ]
|
218
|
|
- });
|
|
257
|
+ {
|
|
258
|
+ type: 'ContainerStack',
|
|
259
|
+ children: [
|
|
260
|
+ {
|
|
261
|
+ type: 'Container',
|
|
262
|
+ data: {
|
|
263
|
+ name: 'com.example.SecondTab'
|
|
264
|
+ },
|
|
265
|
+ children: []
|
|
266
|
+ }
|
|
267
|
+ ]
|
|
268
|
+ }
|
|
269
|
+ ]
|
|
270
|
+ }
|
|
271
|
+ ]
|
|
272
|
+ },
|
|
273
|
+ {
|
|
274
|
+ type: 'SideMenuRight',
|
|
275
|
+ children: [
|
|
276
|
+ {
|
|
277
|
+ type: 'Container',
|
|
278
|
+ data: {
|
|
279
|
+ name: 'com.example.Menu2'
|
|
280
|
+ },
|
|
281
|
+ children: []
|
|
282
|
+ }
|
|
283
|
+ ]
|
|
284
|
+ }
|
|
285
|
+ ]
|
|
286
|
+ });
|
|
287
|
+ });
|
219
|
288
|
});
|
220
|
289
|
|
221
|
|
- it('parses tabs with side menus', () => {
|
222
|
|
- expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedWithBothSideMenus))
|
223
|
|
- .toEqual({
|
224
|
|
- type: 'SideMenuRoot',
|
225
|
|
- children: [
|
226
|
|
- {
|
227
|
|
- type: 'SideMenuLeft',
|
228
|
|
- children: [
|
229
|
|
- {
|
230
|
|
- type: 'Container',
|
231
|
|
- data: {
|
232
|
|
- name: 'com.example.Menu1'
|
233
|
|
- },
|
234
|
|
- children: []
|
235
|
|
- }
|
236
|
|
- ]
|
237
|
|
- },
|
238
|
|
- {
|
239
|
|
- type: 'SideMenuCenter',
|
240
|
|
- children: [
|
241
|
|
- {
|
242
|
|
- type: 'Tabs',
|
243
|
|
- children: [
|
244
|
|
- {
|
245
|
|
- type: 'ContainerStack',
|
246
|
|
- children: [
|
247
|
|
- {
|
248
|
|
- type: 'Container',
|
249
|
|
- data: {
|
250
|
|
- name: 'com.example.FirstTab'
|
251
|
|
- },
|
252
|
|
- children: []
|
253
|
|
- }
|
254
|
|
- ]
|
255
|
|
- },
|
256
|
|
- {
|
257
|
|
- type: 'ContainerStack',
|
258
|
|
- children: [
|
259
|
|
- {
|
260
|
|
- type: 'Container',
|
261
|
|
- data: {
|
262
|
|
- name: 'com.example.SecondTab'
|
263
|
|
- },
|
264
|
|
- children: []
|
265
|
|
- }
|
266
|
|
- ]
|
267
|
|
- }
|
268
|
|
- ]
|
269
|
|
- }
|
270
|
|
- ]
|
271
|
|
- },
|
272
|
|
- {
|
273
|
|
- type: 'SideMenuRight',
|
274
|
|
- children: [
|
275
|
|
- {
|
276
|
|
- type: 'Container',
|
277
|
|
- data: {
|
278
|
|
- name: 'com.example.Menu2'
|
279
|
|
- },
|
280
|
|
- children: []
|
281
|
|
- }
|
282
|
|
- ]
|
283
|
|
- }
|
284
|
|
- ]
|
285
|
|
- });
|
|
290
|
+ describe('createContainer', () => {
|
|
291
|
+ it('creates container object with passed data', () => {
|
|
292
|
+ expect(uut.createContainer({ foo: 'bar' })).toEqual({ type: 'Container', data: { foo: 'bar' }, children: [] });
|
|
293
|
+ });
|
286
|
294
|
});
|
287
|
295
|
});
|