|
@@ -303,28 +303,43 @@ describe('Commands', () => {
|
303
|
303
|
uut = new Commands(mockCommandsSender, mockParser, mockCrawler, commandsObserver);
|
304
|
304
|
});
|
305
|
305
|
|
306
|
|
- it('always call last', () => {
|
|
306
|
+ function getAllMethodsOfUut() {
|
|
307
|
+ const uutFns = Object.getOwnPropertyNames(Commands.prototype);
|
|
308
|
+ const methods = _.filter(uutFns, (fn) => fn !== 'constructor');
|
|
309
|
+ expect(methods.length).toBeGreaterThan(1);
|
|
310
|
+ return methods;
|
|
311
|
+ }
|
|
312
|
+
|
|
313
|
+ function getAllMethodsOfNativeCommandsSender() {
|
307
|
314
|
const nativeCommandsSenderFns = _.functions(mockCommandsSender);
|
308
|
315
|
expect(nativeCommandsSenderFns.length).toBeGreaterThan(1);
|
|
316
|
+ return nativeCommandsSenderFns;
|
|
317
|
+ }
|
309
|
318
|
|
|
319
|
+ it('always call last, when nativeCommand fails, dont notify listeners', () => {
|
310
|
320
|
// throw when calling any native commands sender
|
311
|
|
- _.forEach(nativeCommandsSenderFns, (fn) => {
|
|
321
|
+ _.forEach(getAllMethodsOfNativeCommandsSender(), (fn) => {
|
312
|
322
|
mockCommandsSender[fn].mockImplementation(() => {
|
313
|
323
|
throw new Error(`throwing from mockNativeCommandsSender`);
|
314
|
324
|
});
|
315
|
325
|
});
|
316
|
326
|
|
317
|
|
- // call all commands on uut, all should throw, no commandObservers called
|
318
|
|
- const uutFns = Object.getOwnPropertyNames(Commands.prototype);
|
319
|
|
- const methods = _.filter(uutFns, (fn) => fn !== 'constructor');
|
320
|
|
- expect(methods.sort()).toEqual(nativeCommandsSenderFns.sort());
|
|
327
|
+ expect(getAllMethodsOfUut().sort()).toEqual(getAllMethodsOfNativeCommandsSender().sort());
|
321
|
328
|
|
322
|
|
- _.forEach(methods, (m) => {
|
|
329
|
+ // call all commands on uut, all should throw, no commandObservers called
|
|
330
|
+ _.forEach(getAllMethodsOfUut(), (m) => {
|
323
|
331
|
expect(() => uut[m]()).toThrow();
|
324
|
332
|
expect(cb).not.toHaveBeenCalled();
|
325
|
333
|
});
|
326
|
334
|
});
|
327
|
335
|
|
|
336
|
+ xit('notify on all commands', () => {
|
|
337
|
+ _.forEach(getAllMethodsOfUut(), (m) => {
|
|
338
|
+ uut[m]();
|
|
339
|
+ });
|
|
340
|
+ expect(cb).toHaveBeenCalledTimes(getAllMethodsOfUut().length);
|
|
341
|
+ });
|
|
342
|
+
|
328
|
343
|
it('setRoot', () => {
|
329
|
344
|
uut.setRoot({});
|
330
|
345
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
@@ -338,11 +353,17 @@ describe('Commands', () => {
|
338
|
353
|
expect(cb).toHaveBeenCalledWith('setDefaultOptions', { options });
|
339
|
354
|
});
|
340
|
355
|
|
341
|
|
- xit('setOptions', () => {
|
|
356
|
+ it('setOptions', () => {
|
342
|
357
|
const options = { x: 1 };
|
343
|
358
|
uut.setOptions('compId', options);
|
344
|
359
|
expect(cb).toHaveBeenCalledTimes(1);
|
345
|
|
- expect(cb).toHaveBeenCalledWith('setOptions', { componentId: 'compId', options: {} });
|
|
360
|
+ expect(cb).toHaveBeenCalledWith('setOptions', { componentId: 'compId', options });
|
|
361
|
+ });
|
|
362
|
+
|
|
363
|
+ it('showModal', () => {
|
|
364
|
+ uut.showModal({});
|
|
365
|
+ expect(cb).toHaveBeenCalledTimes(1);
|
|
366
|
+ expect(cb).toHaveBeenCalledWith('showModal', { layout: 'parsed' });
|
346
|
367
|
});
|
347
|
368
|
});
|
348
|
369
|
});
|