|
@@ -1,5 +1,5 @@
|
1
|
|
-import React, {Component} from 'react';
|
2
|
|
-import {AppRegistry, Text} from 'react-native';
|
|
1
|
+import React, { Component } from 'react';
|
|
2
|
+import { AppRegistry, Text } from 'react-native';
|
3
|
3
|
import renderer from 'react-test-renderer';
|
4
|
4
|
|
5
|
5
|
describe('ContainerWrapper', () => {
|
|
@@ -25,13 +25,13 @@ describe('ContainerWrapper', () => {
|
25
|
25
|
super(props);
|
26
|
26
|
testParentRef = this; //eslint-disable-line
|
27
|
27
|
this.ChildClass = props.ChildClass;
|
28
|
|
- this.state = {propsFromState: {}};
|
|
28
|
+ this.state = { propsFromState: {} };
|
29
|
29
|
}
|
30
|
30
|
|
31
|
31
|
render() {
|
32
|
32
|
const Child = this.ChildClass;
|
33
|
33
|
return (
|
34
|
|
- <Child containerId="container1" {...this.state.propsFromState}/>
|
|
34
|
+ <Child containerId="container1" {...this.state.propsFromState} />
|
35
|
35
|
);
|
36
|
36
|
}
|
37
|
37
|
}
|
|
@@ -45,55 +45,55 @@ describe('ContainerWrapper', () => {
|
45
|
45
|
it('must have containerId as prop', () => {
|
46
|
46
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
47
|
47
|
expect(() => {
|
48
|
|
- renderer.create(<NavigationContainer/>);
|
|
48
|
+ renderer.create(<NavigationContainer />);
|
49
|
49
|
}).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
|
50
|
50
|
});
|
51
|
51
|
|
52
|
52
|
it('wraps the container and saves to store', () => {
|
53
|
53
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
54
|
54
|
expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
|
55
|
|
- const tree = renderer.create(<NavigationContainer containerId={'container1'}/>);
|
|
55
|
+ const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
|
56
|
56
|
expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
57
|
57
|
expect(myContainerRef).toBeInstanceOf(MyContainer);
|
58
|
58
|
});
|
59
|
59
|
|
60
|
60
|
it('injects props from wrapper into original container', () => {
|
61
|
61
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
62
|
|
- renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'}/>);
|
|
62
|
+ renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
|
63
|
63
|
expect(myContainerRef.props.myProp).toEqual('yo');
|
64
|
64
|
});
|
65
|
65
|
|
66
|
66
|
it('updates props from wrapper into original container', () => {
|
67
|
67
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
68
|
|
- renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
|
68
|
+ renderer.create(<TestParent ChildClass={NavigationContainer} />);
|
69
|
69
|
expect(myContainerRef.props.foo).toEqual(undefined);
|
70
|
|
- testParentRef.setState({propsFromState: {foo: 'yo'}});
|
|
70
|
+ testParentRef.setState({ propsFromState: { foo: 'yo' } });
|
71
|
71
|
expect(myContainerRef.props.foo).toEqual('yo');
|
72
|
72
|
});
|
73
|
73
|
|
74
|
74
|
it('pulls props from the store and injects them into the inner container', () => {
|
75
|
|
- store.setPropsForContainerId('container123', {numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
|
|
75
|
+ store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
76
|
76
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
77
|
|
- renderer.create(<NavigationContainer containerId={'container123'}/>);
|
78
|
|
- expect(myContainerRef.props).toEqual({containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
|
|
77
|
+ renderer.create(<NavigationContainer containerId={'container123'} />);
|
|
78
|
+ expect(myContainerRef.props).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
79
|
79
|
});
|
80
|
80
|
|
81
|
81
|
it('updates props from store into inner container', () => {
|
82
|
82
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
83
|
|
- renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
84
|
|
- store.setPropsForContainerId('container1', {myProp: 'hello'});
|
|
83
|
+ renderer.create(<TestParent ChildClass={NavigationContainer} />);
|
|
84
|
+ store.setPropsForContainerId('container1', { myProp: 'hello' });
|
85
|
85
|
expect(myContainerRef.props.foo).toEqual(undefined);
|
86
|
86
|
expect(myContainerRef.props.myProp).toEqual(undefined);
|
87
|
|
- testParentRef.setState({propsFromState: {foo: 'yo'}});
|
|
87
|
+ testParentRef.setState({ propsFromState: { foo: 'yo' } });
|
88
|
88
|
expect(myContainerRef.props.foo).toEqual('yo');
|
89
|
89
|
expect(myContainerRef.props.myProp).toEqual('hello');
|
90
|
90
|
});
|
91
|
91
|
|
92
|
92
|
it('protects containerId from change', () => {
|
93
|
93
|
const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
|
94
|
|
- renderer.create(<TestParent ChildClass={NavigationContainer}/>);
|
|
94
|
+ renderer.create(<TestParent ChildClass={NavigationContainer} />);
|
95
|
95
|
expect(myContainerRef.props.containerId).toEqual('container1');
|
96
|
|
- testParentRef.setState({propsFromState: {containerId: 'ERROR'}});
|
|
96
|
+ testParentRef.setState({ propsFromState: { containerId: 'ERROR' } });
|
97
|
97
|
expect(myContainerRef.props.containerId).toEqual('container1');
|
98
|
98
|
});
|
99
|
99
|
});
|