forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutTreeCrawler.test.ts
55 lines (50 loc) · 1.76 KB
/
LayoutTreeCrawler.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { LayoutType } from './LayoutType';
import { LayoutTreeCrawler } from './LayoutTreeCrawler';
import { Store } from '../components/Store';
import { mock, instance, verify, deepEqual } from 'ts-mockito';
import { OptionsProcessor } from './OptionsProcessor';
import { CommandName } from '../interfaces/CommandName';
describe('LayoutTreeCrawler', () => {
let uut: LayoutTreeCrawler;
let mockedStore: Store;
let mockedOptionsProcessor: OptionsProcessor;
beforeEach(() => {
mockedStore = mock(Store);
mockedOptionsProcessor = mock(OptionsProcessor);
uut = new LayoutTreeCrawler(instance(mockedStore), instance(mockedOptionsProcessor));
});
it('saves passProps into store for Component nodes', () => {
const node = {
id: 'testId',
type: LayoutType.BottomTabs,
children: [
{
id: 'testId',
type: LayoutType.Component,
data: { name: 'the name', passProps: { myProp: 123 } },
children: [],
},
],
data: {},
};
uut.crawl(node, CommandName.SetRoot);
verify(mockedStore.setPendingProps('testId', deepEqual({ myProp: 123 }))).called();
});
it('Components: must contain data name', () => {
const node = { type: LayoutType.Component, data: {}, children: [], id: 'testId' };
expect(() => uut.crawl(node, CommandName.SetRoot)).toThrowError('Missing component data.name');
});
it('Components: omits passProps after processing so they are not passed over the bridge', () => {
const node = {
id: 'testId',
type: LayoutType.Component,
data: {
name: 'compName',
passProps: { someProp: 'here' },
},
children: [],
};
uut.crawl(node, CommandName.SetRoot);
expect(node.data.passProps).toBeUndefined();
});
});