yogevbd 6 years ago
parent
commit
dfa6ba6c4d

+ 30
- 1
lib/src/events/ComponentEventsObserver.test.tsx View File

5
 
5
 
6
 describe('ComponentEventsObserver', () => {
6
 describe('ComponentEventsObserver', () => {
7
   const mockEventsReceiver = new NativeEventsReceiver();
7
   const mockEventsReceiver = new NativeEventsReceiver();
8
-  const uut = new ComponentEventsObserver(mockEventsReceiver);
8
+  let uut;
9
   const didAppearFn = jest.fn();
9
   const didAppearFn = jest.fn();
10
   const didDisappearFn = jest.fn();
10
   const didDisappearFn = jest.fn();
11
   const didMountFn = jest.fn();
11
   const didMountFn = jest.fn();
65
     }
65
     }
66
   }
66
   }
67
 
67
 
68
+  beforeEach(() => {
69
+    uut = new ComponentEventsObserver(mockEventsReceiver);
70
+  });
71
+
68
   it(`bindComponent expects a component with componentId`, () => {
72
   it(`bindComponent expects a component with componentId`, () => {
69
     const tree = renderer.create(<SimpleScreen />);
73
     const tree = renderer.create(<SimpleScreen />);
70
     expect(() => uut.bindComponent(tree.getInstance() as any)).toThrow('');
74
     expect(() => uut.bindComponent(tree.getInstance() as any)).toThrow('');
187
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
191
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
188
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledTimes(1);
192
     expect(mockEventsReceiver.registerSearchBarCancelPressedListener).toHaveBeenCalledTimes(1);
189
   });
193
   });
194
+
195
+  it(`warn when button event is not getting handled`, () => {
196
+    const tree1 = renderer.create(<SimpleScreen componentId={'myCompId'} />);
197
+    const instance1 = tree1.getInstance() as any;
198
+    console.warn = jest.fn();
199
+    uut.bindComponent(instance1);
200
+
201
+    uut.notifyNavigationButtonPressed({ componentId: 'myCompId', buttonId: 'myButtonId' });
202
+
203
+    expect(console.warn).toHaveBeenCalledTimes(1);
204
+    expect(console.warn).toHaveBeenCalledWith(`navigationButtonPressed for button 'myButtonId' was not handled`);
205
+  });
206
+
207
+  it(`doesn't warn when button event is getting handled`, () => {
208
+    const tree1 = renderer.create(<SimpleScreen componentId={'myCompId'} />);
209
+    const instance1 = tree1.getInstance() as any;
210
+    console.warn = jest.fn();
211
+    
212
+    instance1.navigationButtonPressed = jest.fn();
213
+    uut.bindComponent(instance1);
214
+
215
+    uut.notifyNavigationButtonPressed({ componentId: 'myCompId', buttonId: 'myButtonId' });
216
+
217
+    expect(console.warn).toHaveBeenCalledTimes(0);
218
+  });
190
 });
219
 });

+ 9
- 1
lib/src/events/ComponentEventsObserver.ts View File

62
   }
62
   }
63
 
63
 
64
   notifyNavigationButtonPressed(event: NavigationButtonPressedEvent) {
64
   notifyNavigationButtonPressed(event: NavigationButtonPressedEvent) {
65
-    this.triggerOnAllListenersByComponentId(event, 'navigationButtonPressed');
65
+    const listenersTriggered = this.triggerOnAllListenersByComponentId(event, 'navigationButtonPressed');
66
+    if (listenersTriggered === 0) {
67
+      // tslint:disable-next-line:no-console
68
+      console.warn(`navigationButtonPressed for button '${event.buttonId}' was not handled`);
69
+    }
66
   }
70
   }
67
 
71
 
68
   notifyModalDismissed(event: ModalDismissedEvent) {
72
   notifyModalDismissed(event: ModalDismissedEvent) {
78
   }
82
   }
79
 
83
 
80
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
84
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
85
+    let listenersTriggered = 0;
81
     _.forEach(this.listeners[event.componentId], (component) => {
86
     _.forEach(this.listeners[event.componentId], (component) => {
82
       if (_.isObject(component) && _.isFunction(component[method])) {
87
       if (_.isObject(component) && _.isFunction(component[method])) {
83
         component[method](event);
88
         component[method](event);
89
+        listenersTriggered++;
84
       }
90
       }
85
     });
91
     });
92
+
93
+    return listenersTriggered;
86
   }
94
   }
87
 }
95
 }

+ 8
- 1
wallaby.js View File

13
       'package.json',
13
       'package.json',
14
       'lib/src/**/*.js',
14
       'lib/src/**/*.js',
15
       'lib/src/**/*.ts',
15
       'lib/src/**/*.ts',
16
+      'lib/src/**/*.tsx',
17
+      '!lib/src/**/*.test.tsx',
16
       '!lib/src/**/*.test.js',
18
       '!lib/src/**/*.test.js',
17
       '!lib/src/**/*.test.ts',
19
       '!lib/src/**/*.test.ts',
18
       'integration/**/*.js',
20
       'integration/**/*.js',
22
     tests: [
24
     tests: [
23
       'lib/src/**/*.test.js',
25
       'lib/src/**/*.test.js',
24
       'lib/src/**/*.test.ts',
26
       'lib/src/**/*.test.ts',
27
+      'lib/src/**/*.test.tsx',
25
       'integration/**/*.test.js'
28
       'integration/**/*.test.js'
26
     ],
29
     ],
27
 
30
 
28
     compilers: {
31
     compilers: {
29
-      '**/*.js': wallaby.compilers.babel(babelOptions)
32
+      '**/*.js': wallaby.compilers.babel(babelOptions),
33
+      '**/*.ts?(x)': wallaby.compilers.typeScript({
34
+        module: 'commonjs',
35
+        jsx: 'React'
36
+      })
30
     },
37
     },
31
 
38
 
32
     setup: (w) => {
39
     setup: (w) => {