From 3c9fcd5bb327c19a9d6c976e6e456398f9993e63 Mon Sep 17 00:00:00 2001 From: Spencer Date: Tue, 11 Sep 2018 18:28:49 -0700 Subject: [PATCH] [6.x] [core/public] stop loadingCount, improve stop() tests (#22937) (#22948) Backports the following commits to 6.x: - [core/public] stop loadingCount, improve stop() tests (#22937) --- 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 64f71cd4fb00ce..e5c5319fb85ed4 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 05c00e5a633aa9..5d39a883e39f83 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 = ''; } }