From e2c8b8abd14cfd9d3445edb2b7d71942efa5b7a2 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 11 Sep 2018 09:19:41 -0700 Subject: [PATCH] [core/public] stop loadingCount, improve stop() tests --- src/core/public/core_system.test.ts | 41 ++++++++++++++++++++++++++--- src/core/public/core_system.ts | 1 + 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index 64f71cd4fb00c..e5c5319fb85ed 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -73,6 +73,7 @@ const MockLoadingCountService = jest.fn(function _MockNotif this: any ) { this.start = jest.fn().mockReturnValue(mockLoadingCountContract); + this.stop = jest.fn(); }); jest.mock('./loading_count', () => ({ LoadingCountService: MockLoadingCountService, @@ -197,17 +198,51 @@ describe('constructor', () => { }); describe('#stop', () => { - it('call legacyPlatform.stop()', () => { + it('calls legacyPlatform.stop()', () => { const coreSystem = new CoreSystem({ ...defaultCoreSystemParams, }); - const legacyPlatformService = MockLegacyPlatformService.mock.instances[0]; - + const [legacyPlatformService] = MockLegacyPlatformService.mock.instances; expect(legacyPlatformService.stop).not.toHaveBeenCalled(); coreSystem.stop(); expect(legacyPlatformService.stop).toHaveBeenCalled(); }); + + it('calls notifications.stop()', () => { + const coreSystem = new CoreSystem({ + ...defaultCoreSystemParams, + }); + + const [notificationsService] = MockNotificationsService.mock.instances; + expect(notificationsService.stop).not.toHaveBeenCalled(); + coreSystem.stop(); + expect(notificationsService.stop).toHaveBeenCalled(); + }); + + it('calls loadingCount.stop()', () => { + const coreSystem = new CoreSystem({ + ...defaultCoreSystemParams, + }); + + const [loadingCountService] = MockLoadingCountService.mock.instances; + expect(loadingCountService.stop).not.toHaveBeenCalled(); + coreSystem.stop(); + expect(loadingCountService.stop).toHaveBeenCalled(); + }); + + it('clears the rootDomElement', () => { + const rootDomElement = document.createElement('div'); + const coreSystem = new CoreSystem({ + ...defaultCoreSystemParams, + rootDomElement, + }); + + coreSystem.start(); + expect(rootDomElement.innerHTML).not.toBe(''); + coreSystem.stop(); + expect(rootDomElement.innerHTML).toBe(''); + }); }); describe('#start()', () => { diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 05c00e5a633aa..5d39a883e39f8 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -122,6 +122,7 @@ export class CoreSystem { public stop() { this.legacyPlatform.stop(); this.notifications.stop(); + this.loadingCount.stop(); this.rootDomElement.textContent = ''; } }