|
@@ -12,96 +12,88 @@ describe('EventsRegistry', () => {
|
12
|
12
|
uut = new EventsRegistry(mockNativeEventsReceiver, commandsObserver);
|
13
|
13
|
});
|
14
|
14
|
|
15
|
|
- it('exposes onAppLaunched event', () => {
|
|
15
|
+ it('exposes appLaunched event', () => {
|
16
|
16
|
const subscription = {};
|
17
|
17
|
const cb = jest.fn();
|
18
|
|
- mockNativeEventsReceiver.registerOnAppLaunched.mockReturnValueOnce(subscription);
|
|
18
|
+ mockNativeEventsReceiver.registerAppLaunchedListener.mockReturnValueOnce(subscription);
|
19
|
19
|
|
20
|
|
- const result = uut.onAppLaunched(cb);
|
|
20
|
+ const result = uut.registerAppLaunchedListener(cb);
|
21
|
21
|
|
22
|
22
|
expect(result).toBe(subscription);
|
23
|
|
- expect(mockNativeEventsReceiver.registerOnAppLaunched).toHaveBeenCalledTimes(1);
|
24
|
|
- expect(mockNativeEventsReceiver.registerOnAppLaunched).toHaveBeenCalledWith(cb);
|
|
23
|
+ expect(mockNativeEventsReceiver.registerAppLaunchedListener).toHaveBeenCalledTimes(1);
|
|
24
|
+ expect(mockNativeEventsReceiver.registerAppLaunchedListener).toHaveBeenCalledWith(cb);
|
25
|
25
|
});
|
26
|
26
|
|
27
|
27
|
it('exposes componentDidAppear event', () => {
|
28
|
28
|
const subscription = {};
|
29
|
29
|
const cb = jest.fn();
|
30
|
|
- mockNativeEventsReceiver.registerComponentDidAppear.mockReturnValueOnce(subscription);
|
|
30
|
+ mockNativeEventsReceiver.registerComponentDidAppearListener.mockReturnValueOnce(subscription);
|
31
|
31
|
|
32
|
|
- const result = uut.componentDidAppear(cb);
|
|
32
|
+ const result = uut.registerComponentDidAppearListener(cb);
|
33
|
33
|
|
34
|
34
|
expect(result).toBe(subscription);
|
35
|
|
- expect(mockNativeEventsReceiver.registerComponentDidAppear).toHaveBeenCalledTimes(1);
|
|
35
|
+ expect(mockNativeEventsReceiver.registerComponentDidAppearListener).toHaveBeenCalledTimes(1);
|
36
|
36
|
|
37
|
|
- mockNativeEventsReceiver.registerComponentDidAppear.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
|
|
37
|
+ mockNativeEventsReceiver.registerComponentDidAppearListener.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
|
38
|
38
|
expect(cb).toHaveBeenCalledWith('theId', 'theName');
|
39
|
39
|
});
|
40
|
40
|
|
41
|
41
|
it('exposes componentDidDisappear event', () => {
|
42
|
42
|
const subscription = {};
|
43
|
43
|
const cb = jest.fn();
|
44
|
|
- mockNativeEventsReceiver.registerComponentDidDisappear.mockReturnValueOnce(subscription);
|
|
44
|
+ mockNativeEventsReceiver.registerComponentDidDisappearListener.mockReturnValueOnce(subscription);
|
45
|
45
|
|
46
|
|
- const result = uut.componentDidDisappear(cb);
|
|
46
|
+ const result = uut.registerComponentDidDisappearListener(cb);
|
47
|
47
|
|
48
|
48
|
expect(result).toBe(subscription);
|
49
|
|
- expect(mockNativeEventsReceiver.registerComponentDidDisappear).toHaveBeenCalledTimes(1);
|
|
49
|
+ expect(mockNativeEventsReceiver.registerComponentDidDisappearListener).toHaveBeenCalledTimes(1);
|
50
|
50
|
|
51
|
|
- mockNativeEventsReceiver.registerComponentDidDisappear.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
|
|
51
|
+ mockNativeEventsReceiver.registerComponentDidDisappearListener.mock.calls[0][0]({ componentId: 'theId', componentName: 'theName' });
|
52
|
52
|
expect(cb).toHaveBeenCalledWith('theId', 'theName');
|
53
|
53
|
});
|
54
|
54
|
|
55
|
|
- it('exposes onNavigationButtonPressed event', () => {
|
56
|
|
- const subscription = {};
|
|
55
|
+ it('exposes registerCommandListener registers listener to commandObserver', () => {
|
57
|
56
|
const cb = jest.fn();
|
58
|
|
- mockNativeEventsReceiver.registerOnNavigationButtonPressed.mockReturnValueOnce(subscription);
|
59
|
|
-
|
60
|
|
- const result = uut.onNavigationButtonPressed(cb);
|
61
|
|
-
|
62
|
|
- expect(result).toBe(subscription);
|
63
|
|
- expect(mockNativeEventsReceiver.registerOnNavigationButtonPressed).toHaveBeenCalledTimes(1);
|
64
|
|
-
|
65
|
|
- mockNativeEventsReceiver.registerOnNavigationButtonPressed.mock.calls[0][0]({ componentId: 'theId', buttonId: 'theBtnId' });
|
66
|
|
- expect(cb).toHaveBeenCalledWith('theId', 'theBtnId');
|
67
|
|
- });
|
68
|
|
-
|
69
|
|
- it('exposes onNavigationCommand registers listener to commandObserver', () => {
|
70
|
|
- const cb = jest.fn();
|
71
|
|
- const result = uut.onNavigationCommand(cb);
|
|
57
|
+ const result = uut.registerCommandListener(cb);
|
72
|
58
|
expect(result).toBeDefined();
|
73
|
59
|
commandsObserver.notify('theCommandName', { x: 1 });
|
74
|
60
|
expect(cb).toHaveBeenCalledTimes(1);
|
75
|
61
|
expect(cb).toHaveBeenCalledWith('theCommandName', { x: 1 });
|
76
|
62
|
});
|
77
|
63
|
|
78
|
|
- it('onNavigationCommand unregister', () => {
|
|
64
|
+ it('registerCommandListener unregister', () => {
|
79
|
65
|
const cb = jest.fn();
|
80
|
|
- const result = uut.onNavigationCommand(cb);
|
|
66
|
+ const result = uut.registerCommandListener(cb);
|
81
|
67
|
result.remove();
|
82
|
68
|
commandsObserver.notify('theCommandName', { x: 1 });
|
83
|
69
|
expect(cb).not.toHaveBeenCalled();
|
84
|
70
|
});
|
85
|
71
|
|
86
|
|
- it('onNavigationEvent', () => {
|
|
72
|
+ it('registerCommandCompletedListener', () => {
|
87
|
73
|
const subscription = {};
|
88
|
74
|
const cb = jest.fn();
|
89
|
|
- mockNativeEventsReceiver.registerOnNavigationEvent.mockReturnValueOnce(subscription);
|
|
75
|
+ mockNativeEventsReceiver.registerCommandCompletedListener.mockReturnValueOnce(subscription);
|
90
|
76
|
|
91
|
|
- const result = uut.onNavigationEvent(cb);
|
|
77
|
+ const result = uut.registerCommandCompletedListener(cb);
|
92
|
78
|
|
93
|
79
|
expect(result).toBe(subscription);
|
94
|
|
- expect(mockNativeEventsReceiver.registerOnNavigationEvent).toHaveBeenCalledTimes(1);
|
|
80
|
+ expect(mockNativeEventsReceiver.registerCommandCompletedListener).toHaveBeenCalledTimes(1);
|
95
|
81
|
|
96
|
|
- mockNativeEventsReceiver.registerOnNavigationEvent.mock.calls[0][0]({ name: 'the event name', params: { a: 1 } });
|
97
|
|
- expect(cb).toHaveBeenCalledWith('the event name', { a: 1 });
|
|
82
|
+ mockNativeEventsReceiver.registerCommandCompletedListener.mock.calls[0][0]({ commandId: 'theCommandId', completionTime: 12345, params: { a: 1 } });
|
|
83
|
+ expect(cb).toHaveBeenCalledWith('theCommandId', 12345, { a: 1 });
|
98
|
84
|
});
|
99
|
85
|
|
100
|
|
- it('onNavigationEvent unregister', () => {
|
|
86
|
+ it('registerNativeEventListener', () => {
|
101
|
87
|
const subscription = {};
|
102
|
88
|
const cb = jest.fn();
|
103
|
|
- mockNativeEventsReceiver.registerOnNavigationEvent.mockReturnValueOnce(subscription);
|
104
|
|
- const result = uut.onNavigationEvent(cb);
|
|
89
|
+ mockNativeEventsReceiver.registerNativeEventListener.mockReturnValueOnce(subscription);
|
|
90
|
+
|
|
91
|
+ const result = uut.registerNativeEventListener(cb);
|
|
92
|
+
|
105
|
93
|
expect(result).toBe(subscription);
|
|
94
|
+ expect(mockNativeEventsReceiver.registerNativeEventListener).toHaveBeenCalledTimes(1);
|
|
95
|
+
|
|
96
|
+ mockNativeEventsReceiver.registerNativeEventListener.mock.calls[0][0]({ name: 'the event name', params: { a: 1 } });
|
|
97
|
+ expect(cb).toHaveBeenCalledWith('the event name', { a: 1 });
|
106
|
98
|
});
|
107
|
99
|
});
|