Skip to content

Commit

Permalink
[6.x] [core/public] stop loadingCount, improve stop() tests (#22937) (#…
Browse files Browse the repository at this point in the history
…22948)

Backports the following commits to 6.x:
 - [core/public] stop loadingCount, improve stop() tests  (#22937)
  • Loading branch information
Spencer committed Sep 12, 2018
1 parent eadf7e8 commit 3c9fcd5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const MockLoadingCountService = jest.fn<LoadingCountService>(function _MockNotif
this: any
) {
this.start = jest.fn().mockReturnValue(mockLoadingCountContract);
this.stop = jest.fn();
});
jest.mock('./loading_count', () => ({
LoadingCountService: MockLoadingCountService,
Expand Down Expand Up @@ -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()', () => {
Expand Down
1 change: 1 addition & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class CoreSystem {
public stop() {
this.legacyPlatform.stop();
this.notifications.stop();
this.loadingCount.stop();
this.rootDomElement.textContent = '';
}
}

0 comments on commit 3c9fcd5

Please sign in to comment.