|
@@ -5,7 +5,6 @@ import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
|
5
|
5
|
|
6
|
6
|
describe('ComponentEventsObserver', () => {
|
7
|
7
|
const mockEventsReceiver = new NativeEventsReceiver();
|
8
|
|
- const uut = new ComponentEventsObserver(mockEventsReceiver);
|
9
|
8
|
const didAppearFn = jest.fn();
|
10
|
9
|
const didDisappearFn = jest.fn();
|
11
|
10
|
const didMountFn = jest.fn();
|
|
@@ -16,6 +15,7 @@ describe('ComponentEventsObserver', () => {
|
16
|
15
|
const previewCompletedFn = jest.fn();
|
17
|
16
|
const modalDismissedFn = jest.fn();
|
18
|
17
|
let subscription;
|
|
18
|
+ let uut;
|
19
|
19
|
|
20
|
20
|
class SimpleScreen extends React.Component<any, any> {
|
21
|
21
|
render() {
|
|
@@ -23,6 +23,52 @@ describe('ComponentEventsObserver', () => {
|
23
|
23
|
}
|
24
|
24
|
}
|
25
|
25
|
|
|
26
|
+ class UnboundScreen extends React.Component<any, any> {
|
|
27
|
+ constructor(props) {
|
|
28
|
+ super(props);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ componentDidMount() {
|
|
32
|
+ didMountFn();
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ componentWillUnmount() {
|
|
36
|
+ willUnmountFn();
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ componentDidAppear() {
|
|
40
|
+ didAppearFn();
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ componentDidDisappear() {
|
|
44
|
+ didDisappearFn();
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ navigationButtonPressed(event) {
|
|
48
|
+ navigationButtonPressedFn(event);
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ modalDismissed(event) {
|
|
52
|
+ modalDismissedFn(event);
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ searchBarUpdated(event) {
|
|
56
|
+ searchBarUpdatedFn(event);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ searchBarCancelPressed(event) {
|
|
60
|
+ searchBarCancelPressedFn(event);
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ previewCompleted(event) {
|
|
64
|
+ previewCompletedFn(event);
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ render() {
|
|
68
|
+ return 'Hello';
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
26
|
72
|
class BoundScreen extends React.Component<any, any> {
|
27
|
73
|
constructor(props) {
|
28
|
74
|
super(props);
|
|
@@ -70,6 +116,11 @@ describe('ComponentEventsObserver', () => {
|
70
|
116
|
}
|
71
|
117
|
}
|
72
|
118
|
|
|
119
|
+ beforeEach(() => {
|
|
120
|
+ jest.clearAllMocks();
|
|
121
|
+ uut = new ComponentEventsObserver(mockEventsReceiver);
|
|
122
|
+ });
|
|
123
|
+
|
73
|
124
|
it(`bindComponent expects a component with componentId`, () => {
|
74
|
125
|
const tree = renderer.create(<SimpleScreen />);
|
75
|
126
|
expect(() => uut.bindComponent(tree.getInstance() as any)).toThrow('');
|
|
@@ -77,6 +128,31 @@ describe('ComponentEventsObserver', () => {
|
77
|
128
|
expect(() => uut.bindComponent(tree2.getInstance() as any)).toThrow('');
|
78
|
129
|
});
|
79
|
130
|
|
|
131
|
+ it(`bindComponent accepts an optional componentId`, () => {
|
|
132
|
+ const tree = renderer.create(<UnboundScreen />);
|
|
133
|
+ uut.bindComponent(tree.getInstance() as any, 'myCompId')
|
|
134
|
+
|
|
135
|
+ expect(tree.toJSON()).toBeDefined();
|
|
136
|
+ expect(didAppearFn).not.toHaveBeenCalled();
|
|
137
|
+
|
|
138
|
+ uut.notifyComponentDidAppear({ componentId: 'myCompId', componentName: 'doesnt matter' });
|
|
139
|
+ expect(didAppearFn).toHaveBeenCalledTimes(1);
|
|
140
|
+ });
|
|
141
|
+
|
|
142
|
+ it(`bindComponent should use optional componentId if component has a componentId in props`, () => {
|
|
143
|
+ const tree = renderer.create(<UnboundScreen componentId={'doNotUseThisId'} />);
|
|
144
|
+ uut.bindComponent(tree.getInstance() as any, 'myCompId')
|
|
145
|
+
|
|
146
|
+ expect(tree.toJSON()).toBeDefined();
|
|
147
|
+
|
|
148
|
+ uut.notifyComponentDidAppear({ componentId: 'dontUseThisId', componentName: 'doesnt matter' });
|
|
149
|
+ expect(didAppearFn).not.toHaveBeenCalled();
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+ uut.notifyComponentDidAppear({ componentId: 'myCompId', componentName: 'doesnt matter' });
|
|
153
|
+ expect(didAppearFn).toHaveBeenCalledTimes(1);
|
|
154
|
+ });
|
|
155
|
+
|
80
|
156
|
it(`bindComponent notifies listeners by componentId on events`, () => {
|
81
|
157
|
const tree = renderer.create(<BoundScreen componentId={'myCompId'} />);
|
82
|
158
|
expect(tree.toJSON()).toBeDefined();
|