Skip to content

Commit

Permalink
Use scopedHistoryMock in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Feb 28, 2020
1 parent 7707b8b commit 86cc53e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

jest.mock('./account_management_page');

import { AppMount, AppNavLinkStatus } from 'src/core/public';
import { AppMount, AppNavLinkStatus, ScopedHistory } from 'src/core/public';
import { UserAPIClient } from '../management';
import { accountManagementApp } from './account_management_app';

import { coreMock } from '../../../../../src/core/public/mocks';
import { coreMock, scopedHistoryMock } from '../../../../../src/core/public/mocks';
import { securityMock } from '../mocks';

describe('accountManagementApp', () => {
Expand Down Expand Up @@ -50,7 +50,12 @@ describe('accountManagementApp', () => {
});

const [[{ mount }]] = coreSetupMock.application.register.mock.calls;
await (mount as AppMount)({ element: containerMock, appBasePath: '', onAppLeave: jest.fn() });
await (mount as AppMount)({
element: containerMock,
appBasePath: '',
onAppLeave: jest.fn(),
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

expect(coreStartMock.chrome.setBreadcrumbs).toHaveBeenCalledTimes(1);
expect(coreStartMock.chrome.setBreadcrumbs).toHaveBeenCalledWith([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

jest.mock('./logged_out_page');

import { AppMount } from 'src/core/public';
import { AppMount, ScopedHistory } from 'src/core/public';
import { loggedOutApp } from './logged_out_app';

import { coreMock } from '../../../../../../src/core/public/mocks';
import { coreMock, scopedHistoryMock } from '../../../../../../src/core/public/mocks';

describe('loggedOutApp', () => {
it('properly registers application', () => {
Expand Down Expand Up @@ -42,7 +42,12 @@ describe('loggedOutApp', () => {
loggedOutApp.create(coreSetupMock);

const [[{ mount }]] = coreSetupMock.application.register.mock.calls;
await (mount as AppMount)({ element: containerMock, appBasePath: '', onAppLeave: jest.fn() });
await (mount as AppMount)({
element: containerMock,
appBasePath: '',
onAppLeave: jest.fn(),
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

const mockRenderApp = jest.requireMock('./logged_out_page').renderLoggedOutPage;
expect(mockRenderApp).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

jest.mock('./login_page');

import { AppMount } from 'src/core/public';
import { AppMount, ScopedHistory } from 'src/core/public';
import { loginApp } from './login_app';

import { coreMock } from '../../../../../../src/core/public/mocks';
import { coreMock, scopedHistoryMock } from '../../../../../../src/core/public/mocks';

describe('loginApp', () => {
it('properly registers application', () => {
Expand Down Expand Up @@ -48,7 +48,12 @@ describe('loginApp', () => {
});

const [[{ mount }]] = coreSetupMock.application.register.mock.calls;
await (mount as AppMount)({ element: containerMock, appBasePath: '', onAppLeave: jest.fn() });
await (mount as AppMount)({
element: containerMock,
appBasePath: '',
onAppLeave: jest.fn(),
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

expect(coreStartMock.injectedMetadata.getInjectedVar).toHaveBeenCalledTimes(1);
expect(coreStartMock.injectedMetadata.getInjectedVar).toHaveBeenCalledWith('secureCookies');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AppMount } from 'src/core/public';
import { AppMount, ScopedHistory } from 'src/core/public';
import { logoutApp } from './logout_app';

import { coreMock } from '../../../../../../src/core/public/mocks';
import { coreMock, scopedHistoryMock } from '../../../../../../src/core/public/mocks';

describe('logoutApp', () => {
beforeAll(() => {
Expand Down Expand Up @@ -53,7 +53,12 @@ describe('logoutApp', () => {
logoutApp.create(coreSetupMock);

const [[{ mount }]] = coreSetupMock.application.register.mock.calls;
await (mount as AppMount)({ element: containerMock, appBasePath: '', onAppLeave: jest.fn() });
await (mount as AppMount)({
element: containerMock,
appBasePath: '',
onAppLeave: jest.fn(),
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

expect(window.sessionStorage.clear).toHaveBeenCalledTimes(1);
expect(window.location.href).toBe('/mock-base-path/api/security/logout?arg=true');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

jest.mock('./overwritten_session_page');

import { AppMount } from 'src/core/public';
import { AppMount, ScopedHistory } from 'src/core/public';
import { overwrittenSessionApp } from './overwritten_session_app';

import { coreMock } from '../../../../../../src/core/public/mocks';
import { coreMock, scopedHistoryMock } from '../../../../../../src/core/public/mocks';
import { securityMock } from '../../mocks';

describe('overwrittenSessionApp', () => {
Expand Down Expand Up @@ -49,7 +49,12 @@ describe('overwrittenSessionApp', () => {
});

const [[{ mount }]] = coreSetupMock.application.register.mock.calls;
await (mount as AppMount)({ element: containerMock, appBasePath: '', onAppLeave: jest.fn() });
await (mount as AppMount)({
element: containerMock,
appBasePath: '',
onAppLeave: jest.fn(),
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

const mockRenderApp = jest.requireMock('./overwritten_session_page')
.renderOverwrittenSessionPage;
Expand Down

0 comments on commit 86cc53e

Please sign in to comment.