yogevbd 6 yıl önce
ebeveyn
işleme
dfa6ba6c4d

+ 30
- 1
lib/src/events/ComponentEventsObserver.test.tsx Dosyayı Görüntüle

@@ -5,7 +5,7 @@ import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
5 5
 
6 6
 describe('ComponentEventsObserver', () => {
7 7
   const mockEventsReceiver = new NativeEventsReceiver();
8
-  const uut = new ComponentEventsObserver(mockEventsReceiver);
8
+  let uut;
9 9
   const didAppearFn = jest.fn();
10 10
   const didDisappearFn = jest.fn();
11 11
   const didMountFn = jest.fn();
@@ -65,6 +65,10 @@ describe('ComponentEventsObserver', () => {
65 65
     }
66 66
   }
67 67
 
68
+  beforeEach(() => {
69
+    uut = new ComponentEventsObserver(mockEventsReceiver);
70
+  });
71
+
68 72
   it(`bindComponent expects a component with componentId`, () => {
69 73
     const tree = renderer.create(<SimpleScreen />);
70 74
     expect(() => uut.bindComponent(tree.getInstance() as any)).toThrow('');
@@ -187,4 +191,29 @@ describe('ComponentEventsObserver', () => {
187 191
     expect(mockEventsReceiver.registerSearchBarUpdatedListener).toHaveBeenCalledTimes(1);
188 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 Dosyayı Görüntüle

@@ -62,7 +62,11 @@ export class ComponentEventsObserver {
62 62
   }
63 63
 
64 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 72
   notifyModalDismissed(event: ModalDismissedEvent) {
@@ -78,10 +82,14 @@ export class ComponentEventsObserver {
78 82
   }
79 83
 
80 84
   private triggerOnAllListenersByComponentId(event: ComponentEvent, method: string) {
85
+    let listenersTriggered = 0;
81 86
     _.forEach(this.listeners[event.componentId], (component) => {
82 87
       if (_.isObject(component) && _.isFunction(component[method])) {
83 88
         component[method](event);
89
+        listenersTriggered++;
84 90
       }
85 91
     });
92
+
93
+    return listenersTriggered;
86 94
   }
87 95
 }

+ 8
- 1
wallaby.js Dosyayı Görüntüle

@@ -13,6 +13,8 @@ module.exports = function (wallaby) {
13 13
       'package.json',
14 14
       'lib/src/**/*.js',
15 15
       'lib/src/**/*.ts',
16
+      'lib/src/**/*.tsx',
17
+      '!lib/src/**/*.test.tsx',
16 18
       '!lib/src/**/*.test.js',
17 19
       '!lib/src/**/*.test.ts',
18 20
       'integration/**/*.js',
@@ -22,11 +24,16 @@ module.exports = function (wallaby) {
22 24
     tests: [
23 25
       'lib/src/**/*.test.js',
24 26
       'lib/src/**/*.test.ts',
27
+      'lib/src/**/*.test.tsx',
25 28
       'integration/**/*.test.js'
26 29
     ],
27 30
 
28 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 39
     setup: (w) => {