|
@@ -6,6 +6,7 @@ describe('ComponentRegistry', () => {
|
6
|
6
|
let uut;
|
7
|
7
|
let myContainerRef;
|
8
|
8
|
let testParentRef;
|
|
9
|
+ let containerStore;
|
9
|
10
|
|
10
|
11
|
class MyContainer extends Component {
|
11
|
12
|
constructor(props) {
|
|
@@ -36,6 +37,7 @@ describe('ComponentRegistry', () => {
|
36
|
37
|
|
37
|
38
|
beforeEach(() => {
|
38
|
39
|
uut = require('./ContainerRegistry');
|
|
40
|
+ containerStore = require('./ContainerStore');
|
39
|
41
|
});
|
40
|
42
|
|
41
|
43
|
afterEach(() => {
|
|
@@ -44,8 +46,11 @@ describe('ComponentRegistry', () => {
|
44
|
46
|
});
|
45
|
47
|
|
46
|
48
|
describe('registerContainer', () => {
|
47
|
|
- it('registers container component by containerKey into AppRegistry', () => {
|
|
49
|
+ beforeEach(() => {
|
48
|
50
|
AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
|
|
51
|
+ });
|
|
52
|
+
|
|
53
|
+ it('registers container component by containerKey into AppRegistry', () => {
|
49
|
54
|
expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
|
50
|
55
|
uut.registerContainer('example.MyContainer.key', () => MyContainer);
|
51
|
56
|
expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
|
|
@@ -53,7 +58,6 @@ describe('ComponentRegistry', () => {
|
53
|
58
|
});
|
54
|
59
|
|
55
|
60
|
it('resulting in a normal component', () => {
|
56
|
|
- AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
|
57
|
61
|
uut.registerContainer('example.MyContainer.key', () => MyContainer);
|
58
|
62
|
const Container = AppRegistry.registerComponent.mock.calls[0][1]();
|
59
|
63
|
const tree = renderer.create(<Container screenId="123"/>);
|
|
@@ -61,35 +65,36 @@ describe('ComponentRegistry', () => {
|
61
|
65
|
});
|
62
|
66
|
});
|
63
|
67
|
|
64
|
|
- describe('wrapping NavigationContainer', () => {
|
|
68
|
+ describe('NavigationContainer wrapping', () => {
|
65
|
69
|
const containerKey = 'example.MyContainer';
|
66
|
70
|
|
67
|
71
|
beforeEach(() => {
|
68
|
72
|
uut.registerContainer(containerKey, () => MyContainer);
|
69
|
73
|
});
|
70
|
74
|
|
71
|
|
- it('asserts has screenId as prop', () => {
|
72
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
75
|
+ it('must have screenId as prop', () => {
|
|
76
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
73
|
77
|
expect(() => {
|
74
|
78
|
renderer.create(<NavigationContainer/>);
|
75
|
79
|
}).toThrow(new Error('Screen example.MyContainer does not have a screenId!'));
|
76
|
80
|
});
|
77
|
81
|
|
78
|
82
|
it('wraps the container and saves to store', () => {
|
79
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
83
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
|
84
|
+ expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
|
80
|
85
|
const tree = renderer.create(<NavigationContainer screenId={'screen1'}/>);
|
81
|
86
|
expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
82
|
87
|
expect(myContainerRef).toBeInstanceOf(MyContainer);
|
83
|
88
|
});
|
84
|
89
|
|
85
|
90
|
it('injects props from wrapper into original container', () => {
|
86
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
91
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
87
|
92
|
renderer.create(<NavigationContainer screenId={'screen1'} myProp={'yo'}/>);
|
88
|
93
|
expect(myContainerRef.props.myProp).toEqual('yo');
|
89
|
94
|
});
|
90
|
95
|
|
91
|
96
|
it('updates props from wrapper into original container', () => {
|
92
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
97
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
93
|
98
|
renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
94
|
99
|
expect(myContainerRef.props.foo).toEqual(undefined);
|
95
|
100
|
testParentRef.setState({propsFromState: {foo: 'yo'}});
|
|
@@ -98,13 +103,13 @@ describe('ComponentRegistry', () => {
|
98
|
103
|
|
99
|
104
|
it('pulls props from the PropsStore and injects them into the inner container', () => {
|
100
|
105
|
require('./PropsStore').setPropsForScreenId('screen123', {numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
|
101
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
106
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
102
|
107
|
renderer.create(<NavigationContainer screenId={'screen123'}/>);
|
103
|
108
|
expect(myContainerRef.props).toEqual({screenId: 'screen123', numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
|
104
|
109
|
});
|
105
|
110
|
|
106
|
111
|
it('updates props from PropsStore into inner container', () => {
|
107
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
112
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
108
|
113
|
renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
109
|
114
|
require('./PropsStore').setPropsForScreenId('screen1', {myProp: 'hello'});
|
110
|
115
|
expect(myContainerRef.props.foo).toEqual(undefined);
|
|
@@ -115,7 +120,7 @@ describe('ComponentRegistry', () => {
|
115
|
120
|
});
|
116
|
121
|
|
117
|
122
|
it('protects screenId from change', () => {
|
118
|
|
- const NavigationContainer = uut.getRegisteredContainer(containerKey);
|
|
123
|
+ const NavigationContainer = containerStore.getContainerClass(containerKey);
|
119
|
124
|
renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
120
|
125
|
expect(myContainerRef.props.screenId).toEqual('screen1');
|
121
|
126
|
testParentRef.setState({propsFromState: {screenId: 'ERROR'}});
|