|
@@ -1,41 +1,83 @@
|
|
1
|
+import _ from 'lodash';
|
1
|
2
|
import {AppRegistry, Text} from 'react-native';
|
2
|
3
|
import React, {Component} from 'react';
|
|
4
|
+import renderer from 'react-test-renderer';
|
3
|
5
|
|
4
|
6
|
class MyContainer extends Component {
|
5
|
7
|
render() {
|
|
8
|
+ const txt = `Hello, ${_.get(this.props, 'name', 'World')}!`;
|
6
|
9
|
return (
|
7
|
|
- <Text>{'Hello, World!'}</Text>
|
|
10
|
+ <Text>{txt}</Text>
|
8
|
11
|
);
|
9
|
12
|
}
|
10
|
13
|
}
|
11
|
14
|
|
12
|
|
-import renderer from 'react-test-renderer';
|
13
|
|
-
|
14
|
15
|
describe('ComponentRegistry', () => {
|
15
|
16
|
let uut;
|
16
|
17
|
|
17
|
18
|
beforeEach(() => {
|
18
|
19
|
AppRegistry.registerComponent = jest.fn(AppRegistry.registerComponent);
|
19
|
|
- //jest.mock('react-native', () => ({AppRegistry}));
|
20
|
20
|
uut = require('./ContainerRegistry');
|
21
|
21
|
});
|
22
|
22
|
|
23
|
|
- it('registers container component into AppRegistry', () => {
|
|
23
|
+ function getRegisteredComponentClassFromAppRegistry() {
|
|
24
|
+ return AppRegistry.registerComponent.mock.calls[0][1]();
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ it('registers container component by containerKey into AppRegistry', () => {
|
24
|
28
|
expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
|
25
|
29
|
|
26
|
|
- uut.registerContainer('example.MyContainer', () => MyContainer);
|
|
30
|
+ uut.registerContainer('example.MyContainer.key', () => MyContainer);
|
27
|
31
|
|
28
|
32
|
expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
|
29
|
|
- expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer');
|
|
33
|
+ expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer.key');
|
30
|
34
|
});
|
31
|
35
|
|
32
|
36
|
it('wraps the container', () => {
|
33
|
37
|
uut.registerContainer('example.MyContainer', () => MyContainer);
|
34
|
38
|
|
35
|
|
- const WrappedClass = AppRegistry.registerComponent.mock.calls[0][1]();
|
|
39
|
+ const NavigationContainer = getRegisteredComponentClassFromAppRegistry();
|
36
|
40
|
const tree = renderer.create(
|
37
|
|
- <WrappedClass/>
|
|
41
|
+ <NavigationContainer/>
|
38
|
42
|
);
|
39
|
43
|
expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
40
|
44
|
});
|
|
45
|
+
|
|
46
|
+ it('passes props from wrapper into original container', () => {
|
|
47
|
+ uut.registerContainer('example.MyContainer', () => MyContainer);
|
|
48
|
+
|
|
49
|
+ const NavigationContainer = getRegisteredComponentClassFromAppRegistry();
|
|
50
|
+ const tree = renderer.create(
|
|
51
|
+ <NavigationContainer name="Daniel"/>
|
|
52
|
+ );
|
|
53
|
+ expect(tree.toJSON().children).toEqual(['Hello, Daniel!']);
|
|
54
|
+ });
|
|
55
|
+ //
|
|
56
|
+ //xit('updates props into original container', () => {
|
|
57
|
+ //uut.registerContainer('example.MyContainer', () => MyContainer);
|
|
58
|
+ //
|
|
59
|
+ //const NavigationContainer = getRegisteredComponentClassFromAppRegistry();
|
|
60
|
+ //
|
|
61
|
+ //class TestParent extends Component {
|
|
62
|
+ // constructor(props) {
|
|
63
|
+ // super(props);
|
|
64
|
+ // this.state = {};
|
|
65
|
+ // }
|
|
66
|
+ //
|
|
67
|
+ // render() {
|
|
68
|
+ // return (
|
|
69
|
+ // <NavigationContainer/>
|
|
70
|
+ // );
|
|
71
|
+ // }
|
|
72
|
+ //}
|
|
73
|
+ //
|
|
74
|
+ //let navContainerRef;
|
|
75
|
+ //const NavigationContainer = getRegisteredComponentClassFromAppRegistry();
|
|
76
|
+ //const tree = renderer.create(
|
|
77
|
+ // <NavigationContainer ref={(r) => navContainerRef = r} name={_.get(navContainerRef, 'state.name')}/>
|
|
78
|
+ //);
|
|
79
|
+ //expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
|
80
|
+ //navContainerRef.setState({name: 'Gandalf'});
|
|
81
|
+ //expect(tree.toJSON().children).toEqual(['Hello, Gandalf!']);
|
|
82
|
+ //});
|
41
|
83
|
});
|