|
@@ -34,7 +34,7 @@ describe('ContainerWrapper', () => {
|
34
|
34
|
render() {
|
35
|
35
|
const Child = this.ChildClass;
|
36
|
36
|
return (
|
37
|
|
- <Child id="container1" {...this.state.propsFromState} />
|
|
37
|
+ <Child containerId="container1" {...this.state.propsFromState} />
|
38
|
38
|
);
|
39
|
39
|
}
|
40
|
40
|
}
|
|
@@ -43,27 +43,27 @@ describe('ContainerWrapper', () => {
|
43
|
43
|
store = new Store();
|
44
|
44
|
});
|
45
|
45
|
|
46
|
|
- it('must have id as prop', () => {
|
|
46
|
+ it('must have containerId as prop', () => {
|
47
|
47
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
48
|
48
|
const orig = console.error; //eslint-disable-line
|
49
|
49
|
console.error = (a) => a; //eslint-disable-line
|
50
|
50
|
expect(() => {
|
51
|
51
|
renderer.create(<NavigationContainer />);
|
52
|
|
- }).toThrow(new Error('Container example.MyContainer does not have an id!'));
|
|
52
|
+ }).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
|
53
|
53
|
console.error = orig; //eslint-disable-line
|
54
|
54
|
});
|
55
|
55
|
|
56
|
56
|
it('wraps the container', () => {
|
57
|
57
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
58
|
58
|
expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
|
59
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
59
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
60
|
60
|
expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
61
|
61
|
expect(myContainerRef).toBeInstanceOf(MyContainer);
|
62
|
62
|
});
|
63
|
63
|
|
64
|
64
|
it('injects props from wrapper into original container', () => {
|
65
|
65
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
66
|
|
- renderer.create(<NavigationContainer id={'container1'} myProp={'yo'} />);
|
|
66
|
+ renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
|
67
|
67
|
expect(myContainerRef.props.myProp).toEqual('yo');
|
68
|
68
|
});
|
69
|
69
|
|
|
@@ -78,8 +78,8 @@ describe('ContainerWrapper', () => {
|
78
|
78
|
it('pulls props from the store and injects them into the inner container', () => {
|
79
|
79
|
store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
80
|
80
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
81
|
|
- renderer.create(<NavigationContainer id={'container123'} />);
|
82
|
|
- expect(myContainerRef.props).toEqual({ id: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
|
81
|
+ renderer.create(<NavigationContainer containerId={'container123'} />);
|
|
82
|
+ expect(myContainerRef.props).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
83
|
83
|
});
|
84
|
84
|
|
85
|
85
|
it('updates props from store into inner container', () => {
|
|
@@ -96,42 +96,42 @@ describe('ContainerWrapper', () => {
|
96
|
96
|
it('protects id from change', () => {
|
97
|
97
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
98
|
98
|
renderer.create(<TestParent ChildClass={NavigationContainer} />);
|
99
|
|
- expect(myContainerRef.props.id).toEqual('container1');
|
|
99
|
+ expect(myContainerRef.props.containerId).toEqual('container1');
|
100
|
100
|
testParentRef.setState({ propsFromState: { id: 'ERROR' } });
|
101
|
|
- expect(myContainerRef.props.id).toEqual('container1');
|
|
101
|
+ expect(myContainerRef.props.containerId).toEqual('container1');
|
102
|
102
|
});
|
103
|
103
|
|
104
|
104
|
it('assignes key by id', () => {
|
105
|
105
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
106
|
|
- renderer.create(<NavigationContainer id={'container1'} />);
|
107
|
|
- expect(myContainerRef.props.id).toEqual('container1');
|
|
106
|
+ renderer.create(<NavigationContainer containerId={'container1'} />);
|
|
107
|
+ expect(myContainerRef.props.containerId).toEqual('container1');
|
108
|
108
|
expect(myContainerRef._reactInternalInstance.key).toEqual('container1');
|
109
|
109
|
});
|
110
|
110
|
|
111
|
111
|
it('saves self ref into store', () => {
|
112
|
112
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
113
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
114
|
|
- expect(store.getRefForId('container1')).toBeDefined();
|
115
|
|
- expect(store.getRefForId('container1')).toBe(tree.getInstance());
|
|
113
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
|
114
|
+ expect(store.getRefForContainerId('container1')).toBeDefined();
|
|
115
|
+ expect(store.getRefForContainerId('container1')).toBe(tree.getInstance());
|
116
|
116
|
});
|
117
|
117
|
|
118
|
118
|
it('cleans ref from store on unMount', () => {
|
119
|
119
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
120
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
121
|
|
- expect(store.getRefForId('container1')).toBeDefined();
|
|
120
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
|
121
|
+ expect(store.getRefForContainerId('container1')).toBeDefined();
|
122
|
122
|
tree.unmount();
|
123
|
|
- expect(store.getRefForId('container1')).toBeUndefined();
|
|
123
|
+ expect(store.getRefForContainerId('container1')).toBeUndefined();
|
124
|
124
|
});
|
125
|
125
|
|
126
|
126
|
it('holds ref to OriginalContainer', () => {
|
127
|
127
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
128
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
128
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
129
|
129
|
expect(tree.getInstance().originalContainerRef).toBe(myContainerRef);
|
130
|
130
|
});
|
131
|
131
|
|
132
|
132
|
it('cleans ref to internal container on unount', () => {
|
133
|
133
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
134
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
134
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
135
|
135
|
const instance = tree.getInstance();
|
136
|
136
|
expect(instance.originalContainerRef).toBeInstanceOf(Component);
|
137
|
137
|
tree.unmount();
|
|
@@ -154,14 +154,14 @@ describe('ContainerWrapper', () => {
|
154
|
154
|
|
155
|
155
|
it('onStart and onStop are optional', () => {
|
156
|
156
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
157
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
157
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
158
|
158
|
expect(() => tree.getInstance().onStart()).not.toThrow();
|
159
|
159
|
expect(() => tree.getInstance().onStop()).not.toThrow();
|
160
|
160
|
});
|
161
|
161
|
|
162
|
162
|
it('calls onStart on OriginalContainer', () => {
|
163
|
163
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyLifecycleContainer, store);
|
164
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
164
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
165
|
165
|
expect(onStartCallback).toHaveBeenCalledTimes(0);
|
166
|
166
|
tree.getInstance().onStart();
|
167
|
167
|
expect(onStartCallback).toHaveBeenCalledTimes(1);
|
|
@@ -169,7 +169,7 @@ describe('ContainerWrapper', () => {
|
169
|
169
|
|
170
|
170
|
it('calls onSop on OriginalContainer', () => {
|
171
|
171
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyLifecycleContainer, store);
|
172
|
|
- const tree = renderer.create(<NavigationContainer id={'container1'} />);
|
|
172
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
173
|
173
|
expect(onStopCallback).toHaveBeenCalledTimes(0);
|
174
|
174
|
tree.getInstance().onStop();
|
175
|
175
|
expect(onStopCallback).toHaveBeenCalledTimes(1);
|