|
@@ -4,34 +4,37 @@ import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts
|
4
|
4
|
import { LayoutTreeParser } from './LayoutTreeParser';
|
5
|
5
|
import { LayoutTreeCrawler } from './LayoutTreeCrawler';
|
6
|
6
|
import { Store } from '../components/Store';
|
7
|
|
-import { UniqueIdProvider } from '../adapters/UniqueIdProvider.mock';
|
8
|
7
|
import { Commands } from './Commands';
|
9
|
8
|
import { CommandsObserver } from '../events/CommandsObserver';
|
10
|
9
|
import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
|
11
|
10
|
import { OptionsProcessor } from './OptionsProcessor';
|
|
11
|
+import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
|
|
12
|
+import { Options } from '../interfaces/Options';
|
12
|
13
|
|
13
|
14
|
describe('Commands', () => {
|
14
|
15
|
let uut: Commands;
|
15
|
16
|
let mockedNativeCommandsSender: NativeCommandsSender;
|
16
|
|
- let nativeCommandsSender: NativeCommandsSender;
|
17
|
|
- let store: Store;
|
|
17
|
+ let mockedStore: Store;
|
18
|
18
|
let commandsObserver: CommandsObserver;
|
|
19
|
+ let mockedUniqueIdProvider: UniqueIdProvider;
|
19
|
20
|
|
20
|
21
|
beforeEach(() => {
|
21
|
|
- store = new Store();
|
22
|
|
- commandsObserver = new CommandsObserver(new UniqueIdProvider());
|
23
|
22
|
mockedNativeCommandsSender = mock(NativeCommandsSender);
|
24
|
|
- nativeCommandsSender = instance(mockedNativeCommandsSender);
|
|
23
|
+ mockedUniqueIdProvider = mock(UniqueIdProvider);
|
|
24
|
+ when(mockedUniqueIdProvider.generate(anything())).thenCall((prefix) => `${prefix}+UNIQUE_ID`);
|
|
25
|
+ const uniqueIdProvider = instance(mockedUniqueIdProvider);
|
|
26
|
+ mockedStore = mock(Store);
|
|
27
|
+ commandsObserver = new CommandsObserver(uniqueIdProvider);
|
25
|
28
|
|
26
|
29
|
const mockedOptionsProcessor = mock(OptionsProcessor);
|
27
|
30
|
const optionsProcessor = instance(mockedOptionsProcessor);
|
28
|
31
|
|
29
|
32
|
uut = new Commands(
|
30
|
|
- nativeCommandsSender,
|
31
|
|
- new LayoutTreeParser(),
|
32
|
|
- new LayoutTreeCrawler(new UniqueIdProvider(), store, optionsProcessor),
|
|
33
|
+ instance(mockedNativeCommandsSender),
|
|
34
|
+ new LayoutTreeParser(uniqueIdProvider),
|
|
35
|
+ new LayoutTreeCrawler(instance(mockedStore), optionsProcessor),
|
33
|
36
|
commandsObserver,
|
34
|
|
- new UniqueIdProvider(),
|
|
37
|
+ uniqueIdProvider,
|
35
|
38
|
optionsProcessor
|
36
|
39
|
);
|
37
|
40
|
});
|
|
@@ -39,146 +42,119 @@ describe('Commands', () => {
|
39
|
42
|
describe('setRoot', () => {
|
40
|
43
|
it('sends setRoot to native after parsing into a correct layout tree', () => {
|
41
|
44
|
uut.setRoot({
|
42
|
|
- root: {
|
43
|
|
- component: {
|
44
|
|
- name: 'com.example.MyScreen'
|
45
|
|
- }
|
46
|
|
- }
|
|
45
|
+ root: { component: { name: 'com.example.MyScreen' } }
|
47
|
46
|
});
|
48
|
|
- verify(mockedNativeCommandsSender.setRoot('setRoot+UNIQUE_ID', deepEqual({
|
49
|
|
- root: {
|
50
|
|
- type: 'Component',
|
51
|
|
- id: 'Component+UNIQUE_ID',
|
52
|
|
- children: [],
|
53
|
|
- data: {
|
54
|
|
- name: 'com.example.MyScreen',
|
55
|
|
- options: {},
|
56
|
|
- passProps: undefined
|
57
|
|
- }
|
58
|
|
- },
|
59
|
|
- modals: [],
|
60
|
|
- overlays: []
|
61
|
|
- }))).called();
|
62
|
|
- });
|
63
|
|
-
|
64
|
|
- it('passProps into components', () => {
|
65
|
|
- const passProps = {
|
66
|
|
- fn: () => 'Hello'
|
67
|
|
- };
|
68
|
|
- expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({});
|
69
|
|
- uut.setRoot({ root: { component: { name: 'asd', passProps } } });
|
70
|
|
- expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual(passProps);
|
71
|
|
- expect(store.getPropsForId('Component+UNIQUE_ID').fn()).toEqual('Hello');
|
|
47
|
+ verify(
|
|
48
|
+ mockedNativeCommandsSender.setRoot(
|
|
49
|
+ 'setRoot+UNIQUE_ID',
|
|
50
|
+ deepEqual({
|
|
51
|
+ root: {
|
|
52
|
+ type: 'Component',
|
|
53
|
+ id: 'Component+UNIQUE_ID',
|
|
54
|
+ children: [],
|
|
55
|
+ data: { name: 'com.example.MyScreen', options: {}, passProps: undefined }
|
|
56
|
+ },
|
|
57
|
+ modals: [],
|
|
58
|
+ overlays: []
|
|
59
|
+ })
|
|
60
|
+ )
|
|
61
|
+ ).called();
|
72
|
62
|
});
|
73
|
63
|
|
74
|
64
|
it('returns a promise with the resolved layout', async () => {
|
75
|
|
- when(mockedNativeCommandsSender.setRoot(anything(), anything())).thenResolve('the resolved layout' as any);
|
|
65
|
+ when(mockedNativeCommandsSender.setRoot(anything(), anything())).thenResolve(
|
|
66
|
+ 'the resolved layout'
|
|
67
|
+ );
|
76
|
68
|
const result = await uut.setRoot({ root: { component: { name: 'com.example.MyScreen' } } });
|
77
|
69
|
expect(result).toEqual('the resolved layout');
|
78
|
70
|
});
|
79
|
71
|
|
80
|
72
|
it('inputs modals and overlays', () => {
|
81
|
73
|
uut.setRoot({
|
82
|
|
- root: {
|
83
|
|
- component: {
|
84
|
|
- name: 'com.example.MyScreen'
|
85
|
|
- }
|
86
|
|
- },
|
87
|
|
- modals: [
|
88
|
|
- {
|
89
|
|
- component: {
|
90
|
|
- name: 'com.example.MyModal'
|
91
|
|
- }
|
92
|
|
- }
|
93
|
|
- ],
|
94
|
|
- overlays: [
|
95
|
|
- {
|
96
|
|
- component: {
|
97
|
|
- name: 'com.example.MyOverlay'
|
98
|
|
- }
|
99
|
|
- }
|
100
|
|
- ]
|
|
74
|
+ root: { component: { name: 'com.example.MyScreen' } },
|
|
75
|
+ modals: [{ component: { name: 'com.example.MyModal' } }],
|
|
76
|
+ overlays: [{ component: { name: 'com.example.MyOverlay' } }]
|
101
|
77
|
});
|
102
|
|
- verify(mockedNativeCommandsSender.setRoot('setRoot+UNIQUE_ID', deepEqual({
|
103
|
|
- root:
|
104
|
|
- {
|
105
|
|
- type: 'Component',
|
106
|
|
- id: 'Component+UNIQUE_ID',
|
107
|
|
- children: [],
|
108
|
|
- data: {
|
109
|
|
- name: 'com.example.MyScreen',
|
110
|
|
- options: {},
|
111
|
|
- passProps: undefined
|
112
|
|
- }
|
113
|
|
- },
|
114
|
|
- modals: [
|
115
|
|
- {
|
116
|
|
- type: 'Component',
|
117
|
|
- id: 'Component+UNIQUE_ID',
|
118
|
|
- children: [],
|
119
|
|
- data: {
|
120
|
|
- name: 'com.example.MyModal',
|
121
|
|
- options: {},
|
122
|
|
- passProps: undefined
|
123
|
|
- }
|
124
|
|
- }
|
125
|
|
- ],
|
126
|
|
- overlays: [
|
127
|
|
- {
|
128
|
|
- type: 'Component',
|
129
|
|
- id: 'Component+UNIQUE_ID',
|
130
|
|
- children: [],
|
131
|
|
- data: {
|
132
|
|
- name: 'com.example.MyOverlay',
|
133
|
|
- options: {},
|
134
|
|
- passProps: undefined
|
135
|
|
- }
|
136
|
|
- }
|
137
|
|
- ]
|
138
|
|
- }))).called();
|
|
78
|
+ verify(
|
|
79
|
+ mockedNativeCommandsSender.setRoot(
|
|
80
|
+ 'setRoot+UNIQUE_ID',
|
|
81
|
+ deepEqual({
|
|
82
|
+ root: {
|
|
83
|
+ type: 'Component',
|
|
84
|
+ id: 'Component+UNIQUE_ID',
|
|
85
|
+ children: [],
|
|
86
|
+ data: {
|
|
87
|
+ name: 'com.example.MyScreen',
|
|
88
|
+ options: {},
|
|
89
|
+ passProps: undefined
|
|
90
|
+ }
|
|
91
|
+ },
|
|
92
|
+ modals: [
|
|
93
|
+ {
|
|
94
|
+ type: 'Component',
|
|
95
|
+ id: 'Component+UNIQUE_ID',
|
|
96
|
+ children: [],
|
|
97
|
+ data: {
|
|
98
|
+ name: 'com.example.MyModal',
|
|
99
|
+ options: {},
|
|
100
|
+ passProps: undefined
|
|
101
|
+ }
|
|
102
|
+ }
|
|
103
|
+ ],
|
|
104
|
+ overlays: [
|
|
105
|
+ {
|
|
106
|
+ type: 'Component',
|
|
107
|
+ id: 'Component+UNIQUE_ID',
|
|
108
|
+ children: [],
|
|
109
|
+ data: {
|
|
110
|
+ name: 'com.example.MyOverlay',
|
|
111
|
+ options: {},
|
|
112
|
+ passProps: undefined
|
|
113
|
+ }
|
|
114
|
+ }
|
|
115
|
+ ]
|
|
116
|
+ })
|
|
117
|
+ )
|
|
118
|
+ ).called();
|
139
|
119
|
});
|
140
|
120
|
});
|
141
|
121
|
|
142
|
122
|
describe('mergeOptions', () => {
|
143
|
123
|
it('passes options for component', () => {
|
144
|
|
- uut.mergeOptions('theComponentId', { title: '1' } as any);
|
145
|
|
- verify(mockedNativeCommandsSender.mergeOptions('theComponentId', deepEqual({title: '1'}))).called();
|
|
124
|
+ uut.mergeOptions('theComponentId', { blurOnUnmount: true });
|
|
125
|
+ verify(
|
|
126
|
+ mockedNativeCommandsSender.mergeOptions(
|
|
127
|
+ 'theComponentId',
|
|
128
|
+ deepEqual({ blurOnUnmount: true })
|
|
129
|
+ )
|
|
130
|
+ ).called();
|
146
|
131
|
});
|
147
|
132
|
});
|
148
|
133
|
|
149
|
134
|
describe('showModal', () => {
|
150
|
135
|
it('sends command to native after parsing into a correct layout tree', () => {
|
151
|
|
- uut.showModal({
|
152
|
|
- component: {
|
153
|
|
- name: 'com.example.MyScreen'
|
154
|
|
- }
|
155
|
|
- });
|
156
|
|
- verify(mockedNativeCommandsSender.showModal('showModal+UNIQUE_ID', deepEqual({
|
157
|
|
- type: 'Component',
|
158
|
|
- id: 'Component+UNIQUE_ID',
|
159
|
|
- data: {
|
160
|
|
- name: 'com.example.MyScreen',
|
161
|
|
- options: {},
|
162
|
|
- passProps: undefined
|
163
|
|
- },
|
164
|
|
- children: []
|
165
|
|
- }))).called();
|
166
|
|
- });
|
167
|
|
-
|
168
|
|
- it('passProps into components', () => {
|
169
|
|
- const passProps = {};
|
170
|
|
- expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual({});
|
171
|
|
- uut.showModal({
|
172
|
|
- component: {
|
173
|
|
- name: 'com.example.MyScreen',
|
174
|
|
- passProps
|
175
|
|
- }
|
176
|
|
- });
|
177
|
|
- expect(store.getPropsForId('Component+UNIQUE_ID')).toEqual(passProps);
|
|
136
|
+ uut.showModal({ component: { name: 'com.example.MyScreen' } });
|
|
137
|
+ verify(
|
|
138
|
+ mockedNativeCommandsSender.showModal(
|
|
139
|
+ 'showModal+UNIQUE_ID',
|
|
140
|
+ deepEqual({
|
|
141
|
+ type: 'Component',
|
|
142
|
+ id: 'Component+UNIQUE_ID',
|
|
143
|
+ data: {
|
|
144
|
+ name: 'com.example.MyScreen',
|
|
145
|
+ options: {},
|
|
146
|
+ passProps: undefined
|
|
147
|
+ },
|
|
148
|
+ children: []
|
|
149
|
+ })
|
|
150
|
+ )
|
|
151
|
+ ).called();
|
178
|
152
|
});
|
179
|
153
|
|
180
|
154
|
it('returns a promise with the resolved layout', async () => {
|
181
|
|
- when(mockedNativeCommandsSender.showModal(anything(), anything())).thenResolve('the resolved layout' as any);
|
|
155
|
+ when(mockedNativeCommandsSender.showModal(anything(), anything())).thenResolve(
|
|
156
|
+ 'the resolved layout'
|
|
157
|
+ );
|
182
|
158
|
const result = await uut.showModal({ component: { name: 'com.example.MyScreen' } });
|
183
|
159
|
expect(result).toEqual('the resolved layout');
|
184
|
160
|
});
|
|
@@ -187,11 +163,19 @@ describe('Commands', () => {
|
187
|
163
|
describe('dismissModal', () => {
|
188
|
164
|
it('sends command to native', () => {
|
189
|
165
|
uut.dismissModal('myUniqueId', {});
|
190
|
|
- verify(mockedNativeCommandsSender.dismissModal('dismissModal+UNIQUE_ID', 'myUniqueId', deepEqual({}))).called();
|
|
166
|
+ verify(
|
|
167
|
+ mockedNativeCommandsSender.dismissModal(
|
|
168
|
+ 'dismissModal+UNIQUE_ID',
|
|
169
|
+ 'myUniqueId',
|
|
170
|
+ deepEqual({})
|
|
171
|
+ )
|
|
172
|
+ ).called();
|
191
|
173
|
});
|
192
|
174
|
|
193
|
175
|
it('returns a promise with the id', async () => {
|
194
|
|
- when(mockedNativeCommandsSender.dismissModal(anyString(), anything(), anything())).thenResolve('the id' as any);
|
|
176
|
+ when(
|
|
177
|
+ mockedNativeCommandsSender.dismissModal(anyString(), anything(), anything())
|
|
178
|
+ ).thenResolve('the id');
|
195
|
179
|
const result = await uut.dismissModal('myUniqueId');
|
196
|
180
|
expect(result).toEqual('the id');
|
197
|
181
|
});
|
|
@@ -200,11 +184,15 @@ describe('Commands', () => {
|
200
|
184
|
describe('dismissAllModals', () => {
|
201
|
185
|
it('sends command to native', () => {
|
202
|
186
|
uut.dismissAllModals({});
|
203
|
|
- verify(mockedNativeCommandsSender.dismissAllModals('dismissAllModals+UNIQUE_ID', deepEqual({}))).called();
|
|
187
|
+ verify(
|
|
188
|
+ mockedNativeCommandsSender.dismissAllModals('dismissAllModals+UNIQUE_ID', deepEqual({}))
|
|
189
|
+ ).called();
|
204
|
190
|
});
|
205
|
191
|
|
206
|
192
|
it('returns a promise with the id', async () => {
|
207
|
|
- when(mockedNativeCommandsSender.dismissAllModals(anyString(), anything())).thenResolve('the id' as any);
|
|
193
|
+ when(mockedNativeCommandsSender.dismissAllModals(anyString(), anything())).thenResolve(
|
|
194
|
+ 'the id'
|
|
195
|
+ );
|
208
|
196
|
const result = await uut.dismissAllModals();
|
209
|
197
|
expect(result).toEqual('the id');
|
210
|
198
|
});
|
|
@@ -212,55 +200,53 @@ describe('Commands', () => {
|
212
|
200
|
|
213
|
201
|
describe('push', () => {
|
214
|
202
|
it('resolves with the parsed layout', async () => {
|
215
|
|
- when(mockedNativeCommandsSender.push(anyString(), anyString(), anything())).thenResolve('the resolved layout' as any);
|
216
|
|
- const result = await uut.push('theComponentId', { component: { name: 'com.example.MyScreen' } });
|
|
203
|
+ when(mockedNativeCommandsSender.push(anyString(), anyString(), anything())).thenResolve(
|
|
204
|
+ 'the resolved layout'
|
|
205
|
+ );
|
|
206
|
+ const result = await uut.push('theComponentId', {
|
|
207
|
+ component: { name: 'com.example.MyScreen' }
|
|
208
|
+ });
|
217
|
209
|
expect(result).toEqual('the resolved layout');
|
218
|
210
|
});
|
219
|
211
|
|
220
|
212
|
it('parses into correct layout node and sends to native', () => {
|
221
|
213
|
uut.push('theComponentId', { component: { name: 'com.example.MyScreen' } });
|
222
|
|
- verify(mockedNativeCommandsSender.push('push+UNIQUE_ID', 'theComponentId', deepEqual({
|
223
|
|
- type: 'Component',
|
224
|
|
- id: 'Component+UNIQUE_ID',
|
225
|
|
- data: {
|
226
|
|
- name: 'com.example.MyScreen',
|
227
|
|
- options: {},
|
228
|
|
- passProps: undefined
|
229
|
|
- },
|
230
|
|
- children: []
|
231
|
|
- }))).called();
|
232
|
|
- });
|
233
|
|
-
|
234
|
|
- it('calls component generator once', async () => {
|
235
|
|
- const generator = jest.fn(() => {
|
236
|
|
- return {};
|
237
|
|
- });
|
238
|
|
- store.setComponentClassForName('theComponentName', generator);
|
239
|
|
- await uut.push('theComponentId', { component: { name: 'theComponentName' } });
|
240
|
|
- expect(generator).toHaveBeenCalledTimes(1);
|
|
214
|
+ verify(
|
|
215
|
+ mockedNativeCommandsSender.push(
|
|
216
|
+ 'push+UNIQUE_ID',
|
|
217
|
+ 'theComponentId',
|
|
218
|
+ deepEqual({
|
|
219
|
+ type: 'Component',
|
|
220
|
+ id: 'Component+UNIQUE_ID',
|
|
221
|
+ data: {
|
|
222
|
+ name: 'com.example.MyScreen',
|
|
223
|
+ options: {},
|
|
224
|
+ passProps: undefined
|
|
225
|
+ },
|
|
226
|
+ children: []
|
|
227
|
+ })
|
|
228
|
+ )
|
|
229
|
+ ).called();
|
241
|
230
|
});
|
242
|
231
|
});
|
243
|
232
|
|
244
|
233
|
describe('pop', () => {
|
245
|
234
|
it('pops a component, passing componentId', () => {
|
246
|
235
|
uut.pop('theComponentId', {});
|
247
|
|
- verify(mockedNativeCommandsSender.pop('pop+UNIQUE_ID', 'theComponentId', deepEqual({}))).called();
|
|
236
|
+ verify(
|
|
237
|
+ mockedNativeCommandsSender.pop('pop+UNIQUE_ID', 'theComponentId', deepEqual({}))
|
|
238
|
+ ).called();
|
248
|
239
|
});
|
249
|
240
|
it('pops a component, passing componentId and options', () => {
|
250
|
|
- const options = {
|
251
|
|
- customTransition: {
|
252
|
|
- animations: [
|
253
|
|
- { type: 'sharedElement', fromId: 'title2', toId: 'title1', startDelay: 0, springVelocity: 0.2, duration: 0.5 }
|
254
|
|
- ],
|
255
|
|
- duration: 0.8
|
256
|
|
- }
|
257
|
|
- };
|
258
|
|
- uut.pop('theComponentId', options as any);
|
|
241
|
+ const options: Options = { popGesture: true };
|
|
242
|
+ uut.pop('theComponentId', options);
|
259
|
243
|
verify(mockedNativeCommandsSender.pop('pop+UNIQUE_ID', 'theComponentId', options)).called();
|
260
|
244
|
});
|
261
|
245
|
|
262
|
246
|
it('pop returns a promise that resolves to componentId', async () => {
|
263
|
|
- when(mockedNativeCommandsSender.pop(anyString(), anyString(), anything())).thenResolve('theComponentId' as any);
|
|
247
|
+ when(mockedNativeCommandsSender.pop(anyString(), anyString(), anything())).thenResolve(
|
|
248
|
+ 'theComponentId'
|
|
249
|
+ );
|
264
|
250
|
const result = await uut.pop('theComponentId', {});
|
265
|
251
|
expect(result).toEqual('theComponentId');
|
266
|
252
|
});
|
|
@@ -269,11 +255,15 @@ describe('Commands', () => {
|
269
|
255
|
describe('popTo', () => {
|
270
|
256
|
it('pops all components until the passed Id is top', () => {
|
271
|
257
|
uut.popTo('theComponentId', {});
|
272
|
|
- verify(mockedNativeCommandsSender.popTo('popTo+UNIQUE_ID', 'theComponentId', deepEqual({}))).called();
|
|
258
|
+ verify(
|
|
259
|
+ mockedNativeCommandsSender.popTo('popTo+UNIQUE_ID', 'theComponentId', deepEqual({}))
|
|
260
|
+ ).called();
|
273
|
261
|
});
|
274
|
262
|
|
275
|
263
|
it('returns a promise that resolves to targetId', async () => {
|
276
|
|
- when(mockedNativeCommandsSender.popTo(anyString(), anyString(), anything())).thenResolve('theComponentId' as any);
|
|
264
|
+ when(mockedNativeCommandsSender.popTo(anyString(), anyString(), anything())).thenResolve(
|
|
265
|
+ 'theComponentId'
|
|
266
|
+ );
|
277
|
267
|
const result = await uut.popTo('theComponentId');
|
278
|
268
|
expect(result).toEqual('theComponentId');
|
279
|
269
|
});
|
|
@@ -282,11 +272,15 @@ describe('Commands', () => {
|
282
|
272
|
describe('popToRoot', () => {
|
283
|
273
|
it('pops all components to root', () => {
|
284
|
274
|
uut.popToRoot('theComponentId', {});
|
285
|
|
- verify(mockedNativeCommandsSender.popToRoot('popToRoot+UNIQUE_ID', 'theComponentId', deepEqual({}))).called();
|
|
275
|
+ verify(
|
|
276
|
+ mockedNativeCommandsSender.popToRoot('popToRoot+UNIQUE_ID', 'theComponentId', deepEqual({}))
|
|
277
|
+ ).called();
|
286
|
278
|
});
|
287
|
279
|
|
288
|
280
|
it('returns a promise that resolves to targetId', async () => {
|
289
|
|
- when(mockedNativeCommandsSender.popToRoot(anyString(), anyString(), anything())).thenResolve('theComponentId' as any);
|
|
281
|
+ when(mockedNativeCommandsSender.popToRoot(anyString(), anyString(), anything())).thenResolve(
|
|
282
|
+ 'theComponentId'
|
|
283
|
+ );
|
290
|
284
|
const result = await uut.popToRoot('theComponentId');
|
291
|
285
|
expect(result).toEqual('theComponentId');
|
292
|
286
|
});
|
|
@@ -295,42 +289,51 @@ describe('Commands', () => {
|
295
|
289
|
describe('setStackRoot', () => {
|
296
|
290
|
it('parses into correct layout node and sends to native', () => {
|
297
|
291
|
uut.setStackRoot('theComponentId', [{ component: { name: 'com.example.MyScreen' } }]);
|
298
|
|
- verify(mockedNativeCommandsSender.setStackRoot('setStackRoot+UNIQUE_ID', 'theComponentId', deepEqual([
|
299
|
|
- {
|
300
|
|
- type: 'Component',
|
301
|
|
- id: 'Component+UNIQUE_ID',
|
302
|
|
- data: {
|
303
|
|
- name: 'com.example.MyScreen',
|
304
|
|
- options: {},
|
305
|
|
- passProps: undefined
|
306
|
|
- },
|
307
|
|
- children: []
|
308
|
|
- }
|
309
|
|
- ]))).called();
|
|
292
|
+ verify(
|
|
293
|
+ mockedNativeCommandsSender.setStackRoot(
|
|
294
|
+ 'setStackRoot+UNIQUE_ID',
|
|
295
|
+ 'theComponentId',
|
|
296
|
+ deepEqual([
|
|
297
|
+ {
|
|
298
|
+ type: 'Component',
|
|
299
|
+ id: 'Component+UNIQUE_ID',
|
|
300
|
+ data: {
|
|
301
|
+ name: 'com.example.MyScreen',
|
|
302
|
+ options: {},
|
|
303
|
+ passProps: undefined
|
|
304
|
+ },
|
|
305
|
+ children: []
|
|
306
|
+ }
|
|
307
|
+ ])
|
|
308
|
+ )
|
|
309
|
+ ).called();
|
310
|
310
|
});
|
311
|
311
|
});
|
312
|
312
|
|
313
|
313
|
describe('showOverlay', () => {
|
314
|
314
|
it('sends command to native after parsing into a correct layout tree', () => {
|
315
|
|
- uut.showOverlay({
|
316
|
|
- component: {
|
317
|
|
- name: 'com.example.MyScreen'
|
318
|
|
- }
|
319
|
|
- });
|
320
|
|
- verify(mockedNativeCommandsSender.showOverlay('showOverlay+UNIQUE_ID', deepEqual({
|
321
|
|
- type: 'Component',
|
322
|
|
- id: 'Component+UNIQUE_ID',
|
323
|
|
- data: {
|
324
|
|
- name: 'com.example.MyScreen',
|
325
|
|
- options: {},
|
326
|
|
- passProps: undefined
|
327
|
|
- },
|
328
|
|
- children: []
|
329
|
|
- }))).called();
|
|
315
|
+ uut.showOverlay({ component: { name: 'com.example.MyScreen' } });
|
|
316
|
+ verify(
|
|
317
|
+ mockedNativeCommandsSender.showOverlay(
|
|
318
|
+ 'showOverlay+UNIQUE_ID',
|
|
319
|
+ deepEqual({
|
|
320
|
+ type: 'Component',
|
|
321
|
+ id: 'Component+UNIQUE_ID',
|
|
322
|
+ data: {
|
|
323
|
+ name: 'com.example.MyScreen',
|
|
324
|
+ options: {},
|
|
325
|
+ passProps: undefined
|
|
326
|
+ },
|
|
327
|
+ children: []
|
|
328
|
+ })
|
|
329
|
+ )
|
|
330
|
+ ).called();
|
330
|
331
|
});
|
331
|
332
|
|
332
|
333
|
it('resolves with the component id', async () => {
|
333
|
|
- when(mockedNativeCommandsSender.showOverlay(anyString(), anything())).thenResolve('Component1' as any);
|
|
334
|
+ when(mockedNativeCommandsSender.showOverlay(anyString(), anything())).thenResolve(
|
|
335
|
+ 'Component1'
|
|
336
|
+ );
|
334
|
337
|
const result = await uut.showOverlay({ component: { name: 'com.example.MyScreen' } });
|
335
|
338
|
expect(result).toEqual('Component1');
|
336
|
339
|
});
|
|
@@ -338,7 +341,7 @@ describe('Commands', () => {
|
338
|
341
|
|
339
|
342
|
describe('dismissOverlay', () => {
|
340
|
343
|
it('check promise returns true', async () => {
|
341
|
|
- when(mockedNativeCommandsSender.dismissOverlay(anyString(), anyString())).thenResolve(true as any);
|
|
344
|
+ when(mockedNativeCommandsSender.dismissOverlay(anyString(), anyString())).thenResolve(true);
|
342
|
345
|
const result = await uut.dismissOverlay('Component1');
|
343
|
346
|
verify(mockedNativeCommandsSender.dismissOverlay(anyString(), anyString())).called();
|
344
|
347
|
expect(result).toEqual(true);
|
|
@@ -346,27 +349,36 @@ describe('Commands', () => {
|
346
|
349
|
|
347
|
350
|
it('send command to native with componentId', () => {
|
348
|
351
|
uut.dismissOverlay('Component1');
|
349
|
|
- verify(mockedNativeCommandsSender.dismissOverlay('dismissOverlay+UNIQUE_ID', 'Component1')).called();
|
|
352
|
+ verify(
|
|
353
|
+ mockedNativeCommandsSender.dismissOverlay('dismissOverlay+UNIQUE_ID', 'Component1')
|
|
354
|
+ ).called();
|
350
|
355
|
});
|
351
|
356
|
});
|
352
|
357
|
|
353
|
358
|
describe('notifies commandsObserver', () => {
|
354
|
359
|
let cb: any;
|
|
360
|
+ let mockedLayoutTreeParser: LayoutTreeParser;
|
|
361
|
+ let mockedLayoutTreeCrawler: LayoutTreeCrawler;
|
|
362
|
+ let anotherMockedUniqueIdProvider: UniqueIdProvider;
|
355
|
363
|
|
356
|
364
|
beforeEach(() => {
|
357
|
365
|
cb = jest.fn();
|
358
|
|
- const mockParser = { parse: () => 'parsed' };
|
359
|
|
- const mockCrawler = { crawl: (x: any) => x, processOptions: (x: any) => x };
|
|
366
|
+ mockedLayoutTreeParser = mock(LayoutTreeParser);
|
|
367
|
+ mockedLayoutTreeCrawler = mock(LayoutTreeCrawler);
|
360
|
368
|
commandsObserver.register(cb);
|
361
|
369
|
const mockedOptionsProcessor = mock(OptionsProcessor);
|
362
|
|
- const optionsProcessor = instance(mockedOptionsProcessor);
|
|
370
|
+ anotherMockedUniqueIdProvider = mock(UniqueIdProvider);
|
|
371
|
+ when(anotherMockedUniqueIdProvider.generate(anything())).thenCall(
|
|
372
|
+ (prefix) => `${prefix}+UNIQUE_ID`
|
|
373
|
+ );
|
|
374
|
+
|
363
|
375
|
uut = new Commands(
|
364
|
376
|
mockedNativeCommandsSender,
|
365
|
|
- mockParser as any,
|
366
|
|
- mockCrawler as any,
|
|
377
|
+ instance(mockedLayoutTreeParser),
|
|
378
|
+ instance(mockedLayoutTreeCrawler),
|
367
|
379
|
commandsObserver,
|
368
|
|
- new UniqueIdProvider(),
|
369
|
|
- optionsProcessor
|
|
380
|
+ instance(anotherMockedUniqueIdProvider),
|
|
381
|
+ instance(mockedOptionsProcessor)
|
370
|
382
|
);
|
371
|
383
|
});
|
372
|
384
|
|
|
@@ -377,29 +389,6 @@ describe('Commands', () => {
|
377
|
389
|
return methods;
|
378
|
390
|
}
|
379
|
391
|
|
380
|
|
- // function getAllMethodsOfNativeCommandsSender() {
|
381
|
|
- // const nativeCommandsSenderFns = _.functions(mockedNativeCommandsSender);
|
382
|
|
- // expect(nativeCommandsSenderFns.length).toBeGreaterThan(1);
|
383
|
|
- // return nativeCommandsSenderFns;
|
384
|
|
- // }
|
385
|
|
-
|
386
|
|
- // it('always call last, when nativeCommand fails, dont notify listeners', () => {
|
387
|
|
- // // expect(getAllMethodsOfUut().sort()).toEqual(getAllMethodsOfNativeCommandsSender().sort());
|
388
|
|
-
|
389
|
|
- // // call all commands on uut, all should throw, no commandObservers called
|
390
|
|
- // _.forEach(getAllMethodsOfUut(), (m) => {
|
391
|
|
- // expect(() => uut[m]()).toThrow();
|
392
|
|
- // expect(cb).not.toHaveBeenCalled();
|
393
|
|
- // });
|
394
|
|
- // });
|
395
|
|
-
|
396
|
|
- // it('notify on all commands', () => {
|
397
|
|
- // _.forEach(getAllMethodsOfUut(), (m) => {
|
398
|
|
- // uut[m]({});
|
399
|
|
- // });
|
400
|
|
- // expect(cb).toHaveBeenCalledTimes(getAllMethodsOfUut().length);
|
401
|
|
- // });
|
402
|
|
-
|
403
|
392
|
describe('passes correct params', () => {
|
404
|
393
|
const argsForMethodName: Record<string, any[]> = {
|
405
|
394
|
setRoot: [{}],
|
|
@@ -418,20 +407,27 @@ describe('Commands', () => {
|
418
|
407
|
getLaunchArgs: ['id']
|
419
|
408
|
};
|
420
|
409
|
const paramsForMethodName: Record<string, object> = {
|
421
|
|
- setRoot: { commandId: 'setRoot+UNIQUE_ID', layout: { root: 'parsed', modals: [], overlays: [] } },
|
|
410
|
+ setRoot: {
|
|
411
|
+ commandId: 'setRoot+UNIQUE_ID',
|
|
412
|
+ layout: { root: null, modals: [], overlays: [] }
|
|
413
|
+ },
|
422
|
414
|
setDefaultOptions: { options: {} },
|
423
|
415
|
mergeOptions: { componentId: 'id', options: {} },
|
424
|
|
- showModal: { commandId: 'showModal+UNIQUE_ID', layout: 'parsed' },
|
|
416
|
+ showModal: { commandId: 'showModal+UNIQUE_ID', layout: null },
|
425
|
417
|
dismissModal: { commandId: 'dismissModal+UNIQUE_ID', componentId: 'id', mergeOptions: {} },
|
426
|
418
|
dismissAllModals: { commandId: 'dismissAllModals+UNIQUE_ID', mergeOptions: {} },
|
427
|
|
- push: { commandId: 'push+UNIQUE_ID', componentId: 'id', layout: 'parsed' },
|
|
419
|
+ push: { commandId: 'push+UNIQUE_ID', componentId: 'id', layout: null },
|
428
|
420
|
pop: { commandId: 'pop+UNIQUE_ID', componentId: 'id', mergeOptions: {} },
|
429
|
421
|
popTo: { commandId: 'popTo+UNIQUE_ID', componentId: 'id', mergeOptions: {} },
|
430
|
422
|
popToRoot: { commandId: 'popToRoot+UNIQUE_ID', componentId: 'id', mergeOptions: {} },
|
431
|
|
- setStackRoot: { commandId: 'setStackRoot+UNIQUE_ID', componentId: 'id', layout: ['parsed'] },
|
432
|
|
- showOverlay: { commandId: 'showOverlay+UNIQUE_ID', layout: 'parsed' },
|
|
423
|
+ setStackRoot: {
|
|
424
|
+ commandId: 'setStackRoot+UNIQUE_ID',
|
|
425
|
+ componentId: 'id',
|
|
426
|
+ layout: [null]
|
|
427
|
+ },
|
|
428
|
+ showOverlay: { commandId: 'showOverlay+UNIQUE_ID', layout: null },
|
433
|
429
|
dismissOverlay: { commandId: 'dismissOverlay+UNIQUE_ID', componentId: 'id' },
|
434
|
|
- getLaunchArgs: { commandId: 'getLaunchArgs+UNIQUE_ID' },
|
|
430
|
+ getLaunchArgs: { commandId: 'getLaunchArgs+UNIQUE_ID' }
|
435
|
431
|
};
|
436
|
432
|
_.forEach(getAllMethodsOfUut(), (m) => {
|
437
|
433
|
it(`for ${m}`, () => {
|