|
@@ -3,9 +3,12 @@ import * as renderer from 'react-test-renderer';
|
3
|
3
|
import { ComponentEventsObserver } from './ComponentEventsObserver';
|
4
|
4
|
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
|
5
|
5
|
import { EventSubscription } from '../interfaces/EventSubscription';
|
|
6
|
+import { Store } from '../components/Store';
|
|
7
|
+import { ComponentDidAppearEvent } from '../interfaces/ComponentEvents';
|
6
|
8
|
|
7
|
9
|
describe('ComponentEventsObserver', () => {
|
8
|
10
|
const mockEventsReceiver = new NativeEventsReceiver();
|
|
11
|
+ const mockStore = new Store();
|
9
|
12
|
const didAppearFn = jest.fn();
|
10
|
13
|
const didDisappearFn = jest.fn();
|
11
|
14
|
const didMountFn = jest.fn();
|
|
@@ -84,8 +87,8 @@ describe('ComponentEventsObserver', () => {
|
84
|
87
|
willUnmountFn();
|
85
|
88
|
}
|
86
|
89
|
|
87
|
|
- componentDidAppear() {
|
88
|
|
- didAppearFn();
|
|
90
|
+ componentDidAppear(event: ComponentDidAppearEvent) {
|
|
91
|
+ didAppearFn(event);
|
89
|
92
|
}
|
90
|
93
|
|
91
|
94
|
componentDidDisappear() {
|
|
@@ -119,7 +122,7 @@ describe('ComponentEventsObserver', () => {
|
119
|
122
|
|
120
|
123
|
beforeEach(() => {
|
121
|
124
|
jest.clearAllMocks();
|
122
|
|
- uut = new ComponentEventsObserver(mockEventsReceiver);
|
|
125
|
+ uut = new ComponentEventsObserver(mockEventsReceiver, mockStore);
|
123
|
126
|
});
|
124
|
127
|
|
125
|
128
|
it(`bindComponent expects a component with componentId`, () => {
|
|
@@ -192,6 +195,23 @@ describe('ComponentEventsObserver', () => {
|
192
|
195
|
expect(willUnmountFn).toHaveBeenCalledTimes(1);
|
193
|
196
|
});
|
194
|
197
|
|
|
198
|
+ it(`componentDidAppear should receive component props from store`, () => {
|
|
199
|
+ const event = {
|
|
200
|
+ componentId: 'myCompId',
|
|
201
|
+ passProps: {
|
|
202
|
+ propA: 'propA'
|
|
203
|
+ },
|
|
204
|
+ componentName: 'doesnt matter'
|
|
205
|
+ }
|
|
206
|
+ renderer.create(<BoundScreen componentId={event.componentId} />);
|
|
207
|
+ mockStore.setPropsForId(event.componentId, event.passProps)
|
|
208
|
+ expect(didAppearFn).not.toHaveBeenCalled();
|
|
209
|
+
|
|
210
|
+ uut.notifyComponentDidAppear({ componentId: 'myCompId', componentName: 'doesnt matter' });
|
|
211
|
+ expect(didAppearFn).toHaveBeenCalledTimes(1);
|
|
212
|
+ expect(didAppearFn).toHaveBeenCalledWith(event);
|
|
213
|
+ });
|
|
214
|
+
|
195
|
215
|
it(`doesnt call other componentIds`, () => {
|
196
|
216
|
renderer.create(<BoundScreen componentId={'myCompId'} />);
|
197
|
217
|
uut.notifyComponentDidAppear({ componentId: 'other', componentName: 'doesnt matter' });
|