|
@@ -1,7 +1,7 @@
|
1
|
1
|
const LayoutTreeParser = require('./LayoutTreeParser');
|
2
|
|
-const Examples = require('./Examples');
|
3
|
2
|
const LayoutTypes = require('./LayoutTypes');
|
4
|
3
|
const _ = require('lodash');
|
|
4
|
+const Examples = require('./LayoutExamples');
|
5
|
5
|
|
6
|
6
|
describe('LayoutTreeParser', () => {
|
7
|
7
|
let uut;
|
|
@@ -18,7 +18,7 @@ describe('LayoutTreeParser', () => {
|
18
|
18
|
it('single component', () => {
|
19
|
19
|
expect(uut.parse(Examples.singleComponent)).toEqual({
|
20
|
20
|
type: LayoutTypes.Component,
|
21
|
|
- data: { name: 'MyReactComponent' },
|
|
21
|
+ data: { name: 'MyReactComponent', options: Examples.options, passProps: Examples.passProps },
|
22
|
22
|
children: []
|
23
|
23
|
});
|
24
|
24
|
});
|
|
@@ -40,9 +40,11 @@ describe('LayoutTreeParser', () => {
|
40
|
40
|
});
|
41
|
41
|
|
42
|
42
|
it('stack of components with top bar', () => {
|
43
|
|
- expect(uut.parse(Examples.stackOfComponentsWithTopBar)).toEqual({
|
44
|
|
- type: LayoutTypes.ComponentStack,
|
45
|
|
- data: {},
|
|
43
|
+ expect(uut.parse(Examples.stackWithTopBar)).toEqual({
|
|
44
|
+ type: LayoutTypes.Stack,
|
|
45
|
+ data: {
|
|
46
|
+ options: Examples.options
|
|
47
|
+ },
|
46
|
48
|
children: [
|
47
|
49
|
{
|
48
|
50
|
type: LayoutTypes.Component,
|
|
@@ -51,7 +53,7 @@ describe('LayoutTreeParser', () => {
|
51
|
53
|
},
|
52
|
54
|
{
|
53
|
55
|
type: LayoutTypes.Component,
|
54
|
|
- data: { name: 'MyReactComponent2', options: Examples.topBarOptions },
|
|
56
|
+ data: { name: 'MyReactComponent2', options: Examples.options },
|
55
|
57
|
children: []
|
56
|
58
|
}
|
57
|
59
|
]
|
|
@@ -64,8 +66,8 @@ describe('LayoutTreeParser', () => {
|
64
|
66
|
expect(result.type).toEqual(LayoutTypes.BottomTabs);
|
65
|
67
|
expect(result.data).toEqual({});
|
66
|
68
|
expect(result.children.length).toEqual(3);
|
67
|
|
- expect(result.children[0].type).toEqual(LayoutTypes.ComponentStack);
|
68
|
|
- expect(result.children[1].type).toEqual(LayoutTypes.ComponentStack);
|
|
69
|
+ expect(result.children[0].type).toEqual(LayoutTypes.Stack);
|
|
70
|
+ expect(result.children[1].type).toEqual(LayoutTypes.Stack);
|
69
|
71
|
expect(result.children[2].type).toEqual(LayoutTypes.Component);
|
70
|
72
|
});
|
71
|
73
|
|
|
@@ -81,7 +83,7 @@ describe('LayoutTreeParser', () => {
|
81
|
83
|
expect(result.children[0].children.length).toEqual(1);
|
82
|
84
|
expect(result.children[0].children[0].type).toEqual(LayoutTypes.Component);
|
83
|
85
|
expect(result.children[1].children.length).toEqual(1);
|
84
|
|
- expect(result.children[1].children[0].type).toEqual(LayoutTypes.ComponentStack);
|
|
86
|
+ expect(result.children[1].children[0].type).toEqual(LayoutTypes.Stack);
|
85
|
87
|
expect(result.children[2].children.length).toEqual(1);
|
86
|
88
|
expect(result.children[2].children[0].type).toEqual(LayoutTypes.Component);
|
87
|
89
|
});
|
|
@@ -94,13 +96,13 @@ describe('LayoutTreeParser', () => {
|
94
|
96
|
const result = uut.parse(Examples.topTabs);
|
95
|
97
|
expect(_.keys(result)).toEqual(['type', 'data', 'children']);
|
96
|
98
|
expect(result.type).toEqual(LayoutTypes.TopTabs);
|
97
|
|
- expect(result.data).toEqual({});
|
|
99
|
+ expect(result.data).toEqual({ options: Examples.options });
|
98
|
100
|
expect(result.children.length).toEqual(5);
|
99
|
101
|
expect(result.children[0].type).toEqual(LayoutTypes.Component);
|
100
|
102
|
expect(result.children[1].type).toEqual(LayoutTypes.Component);
|
101
|
103
|
expect(result.children[2].type).toEqual(LayoutTypes.Component);
|
102
|
104
|
expect(result.children[3].type).toEqual(LayoutTypes.Component);
|
103
|
|
- expect(result.children[4].type).toEqual(LayoutTypes.ComponentStack);
|
|
105
|
+ expect(result.children[4].type).toEqual(LayoutTypes.Stack);
|
104
|
106
|
});
|
105
|
107
|
|
106
|
108
|
it('complex layout example', () => {
|
|
@@ -108,11 +110,20 @@ describe('LayoutTreeParser', () => {
|
108
|
110
|
expect(result.type).toEqual('SideMenuRoot');
|
109
|
111
|
expect(result.children[1].type).toEqual('SideMenuCenter');
|
110
|
112
|
expect(result.children[1].children[0].type).toEqual('BottomTabs');
|
111
|
|
- expect(result.children[1].children[0].children[2].type).toEqual('ComponentStack');
|
|
113
|
+ expect(result.children[1].children[0].children[2].type).toEqual('Stack');
|
112
|
114
|
expect(result.children[1].children[0].children[2].children[0].type).toEqual('TopTabs');
|
113
|
115
|
expect(result.children[1].children[0].children[2].children[0].children[2].type).toEqual('TopTabs');
|
114
|
|
- expect(result.children[1].children[0].children[2].children[0].children[2].children[4].type).toEqual('ComponentStack');
|
115
|
|
- // expect(result.children[1].children[0].children[2].children[0].children[2].data).toEqual({ options: {} });
|
|
116
|
+ expect(result.children[1].children[0].children[2].children[0].children[2].children[4].type).toEqual('Stack');
|
|
117
|
+ expect(result.children[1].children[0].children[2].children[0].children[2].data).toEqual({ options: { topBar: { title: 'Hello1' } } });
|
116
|
118
|
});
|
117
|
119
|
});
|
|
120
|
+
|
|
121
|
+ it('options for all containing types', () => {
|
|
122
|
+ const options = {};
|
|
123
|
+ expect(uut.parse({ component: { options } }).data.options).toBe(options);
|
|
124
|
+ expect(uut.parse({ stack: { options } }).data.options).toBe(options);
|
|
125
|
+ expect(uut.parse({ bottomTabs: { options } }).data.options).toBe(options);
|
|
126
|
+ expect(uut.parse({ topTabs: { options } }).data.options).toBe(options);
|
|
127
|
+ expect(uut.parse({ sideMenu: { options, center: { component: {} } } }).data.options).toBe(options);
|
|
128
|
+ });
|
118
|
129
|
});
|