mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Add client side service mocks * remove ab obsolete test snapshot * put back accidentally removed type definition * define MethodKeysOf, PublicMethodsOf on project level * export src/core/public service mocks * export src/core/server service mocks
This commit is contained in:
parent
8b79d02f35
commit
ddae331708
29 changed files with 680 additions and 345 deletions
45
src/core/public/base_path/base_path_service.mock.ts
Normal file
45
src/core/public/base_path/base_path_service.mock.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { BasePathService, BasePathStart } from './base_path_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<BasePathStart> = {
|
||||
get: jest.fn(),
|
||||
addToPath: jest.fn(),
|
||||
removeFromPath: jest.fn(),
|
||||
};
|
||||
startContract.get.mockReturnValue('get');
|
||||
startContract.addToPath.mockReturnValue('addToPath');
|
||||
startContract.removeFromPath.mockReturnValue('removeFromPath');
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type BasePathServiceContract = PublicMethodsOf<BasePathService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<BasePathServiceContract> = {
|
||||
start: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const basePathServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -17,6 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
|
||||
import { BasePathService } from './base_path_service';
|
||||
|
||||
function setup(options: any = {}) {
|
||||
|
@ -25,9 +26,8 @@ function setup(options: any = {}) {
|
|||
|
||||
const service = new BasePathService();
|
||||
|
||||
const injectedMetadata = {
|
||||
getBasePath: jest.fn().mockReturnValue(injectedBasePath),
|
||||
} as any;
|
||||
const injectedMetadata = injectedMetadataServiceMock.createStartContract();
|
||||
injectedMetadata.getBasePath.mockReturnValue(injectedBasePath);
|
||||
|
||||
const start = service.start({
|
||||
injectedMetadata,
|
||||
|
|
60
src/core/public/chrome/chrome_service.mock.ts
Normal file
60
src/core/public/chrome/chrome_service.mock.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Brand, Breadcrumb, ChromeService, ChromeStart } from './chrome_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<ChromeStart> = {
|
||||
setBrand: jest.fn(),
|
||||
getBrand$: jest.fn(),
|
||||
setIsVisible: jest.fn(),
|
||||
getIsVisible$: jest.fn(),
|
||||
setIsCollapsed: jest.fn(),
|
||||
getIsCollapsed$: jest.fn(),
|
||||
addApplicationClass: jest.fn(),
|
||||
removeApplicationClass: jest.fn(),
|
||||
getApplicationClasses$: jest.fn(),
|
||||
getBreadcrumbs$: jest.fn(),
|
||||
setBreadcrumbs: jest.fn(),
|
||||
getHelpExtension$: jest.fn(),
|
||||
setHelpExtension: jest.fn(),
|
||||
};
|
||||
startContract.getBrand$.mockReturnValue(new BehaviorSubject({} as Brand));
|
||||
startContract.getIsVisible$.mockReturnValue(new BehaviorSubject(false));
|
||||
startContract.getIsCollapsed$.mockReturnValue(new BehaviorSubject(false));
|
||||
startContract.getApplicationClasses$.mockReturnValue(new BehaviorSubject(['class-name']));
|
||||
startContract.getBreadcrumbs$.mockReturnValue(new BehaviorSubject([{} as Breadcrumb]));
|
||||
startContract.getHelpExtension$.mockReturnValue(new BehaviorSubject(undefined));
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type ChromeServiceContract = PublicMethodsOf<ChromeService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<ChromeServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const chromeServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -20,6 +20,9 @@
|
|||
import * as Rx from 'rxjs';
|
||||
import { toArray } from 'rxjs/operators';
|
||||
|
||||
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
|
||||
import { notificationServiceMock } from '../notifications/notifications_service.mock';
|
||||
|
||||
const store = new Map();
|
||||
(window as any).localStorage = {
|
||||
setItem: (key: string, value: string) => store.set(String(key), String(value)),
|
||||
|
@ -31,22 +34,8 @@ import { ChromeService } from './chrome_service';
|
|||
|
||||
function defaultStartDeps(): any {
|
||||
return {
|
||||
notifications: {
|
||||
toasts: {
|
||||
addWarning: jest.fn(),
|
||||
},
|
||||
},
|
||||
injectedMetadata: {
|
||||
injectedMetadataStart: true,
|
||||
getCspConfig: jest.fn().mockReturnValue({ warnLegacyBrowsers: true }),
|
||||
getKibanaVersion: jest.fn().mockReturnValue('kibanaVersion'),
|
||||
getLegacyMetadata: jest.fn().mockReturnValue({
|
||||
uiSettings: {
|
||||
defaults: { legacyInjectedUiSettingDefaults: true },
|
||||
user: { legacyInjectedUiSettingUserValues: true },
|
||||
},
|
||||
}),
|
||||
},
|
||||
notifications: notificationServiceMock.createStartContract(),
|
||||
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,118 +17,72 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { BasePathService } from './base_path';
|
||||
import { ChromeService } from './chrome';
|
||||
import { FatalErrorsService } from './fatal_errors';
|
||||
import { HttpService } from './http';
|
||||
import { I18nService } from './i18n';
|
||||
import { InjectedMetadataService } from './injected_metadata';
|
||||
import { LegacyPlatformService } from './legacy';
|
||||
import { NotificationsService } from './notifications';
|
||||
import { UiSettingsService } from './ui_settings';
|
||||
|
||||
const MockLegacyPlatformService = jest.fn<LegacyPlatformService, any>(
|
||||
function _MockLegacyPlatformService(this: any) {
|
||||
this.start = jest.fn();
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
}
|
||||
);
|
||||
import { basePathServiceMock } from './base_path/base_path_service.mock';
|
||||
import { chromeServiceMock } from './chrome/chrome_service.mock';
|
||||
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
|
||||
import { httpServiceMock } from './http/http_service.mock';
|
||||
import { i18nServiceMock } from './i18n/i18n_service.mock';
|
||||
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
|
||||
import { legacyPlatformServiceMock } from './legacy/legacy_service.mock';
|
||||
import { notificationServiceMock } from './notifications/notifications_service.mock';
|
||||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||
|
||||
const MockLegacyPlatformService = legacyPlatformServiceMock.create();
|
||||
const LegacyPlatformServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockLegacyPlatformService);
|
||||
jest.mock('./legacy', () => ({
|
||||
LegacyPlatformService: MockLegacyPlatformService,
|
||||
LegacyPlatformService: LegacyPlatformServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockInjectedMetadataStart = {};
|
||||
const MockInjectedMetadataService = jest.fn<InjectedMetadataService, any>(
|
||||
function _MockInjectedMetadataService(this: any) {
|
||||
this.start = jest.fn().mockReturnValue(mockInjectedMetadataStart);
|
||||
return this;
|
||||
}
|
||||
);
|
||||
const MockInjectedMetadataService = injectedMetadataServiceMock.create();
|
||||
const InjectedMetadataServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockInjectedMetadataService);
|
||||
jest.mock('./injected_metadata', () => ({
|
||||
InjectedMetadataService: MockInjectedMetadataService,
|
||||
InjectedMetadataService: InjectedMetadataServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockFatalErrorsStart = {};
|
||||
const MockFatalErrorsService = jest.fn<FatalErrorsService, any>(function _MockFatalErrorsService(
|
||||
this: any
|
||||
) {
|
||||
this.start = jest.fn().mockReturnValue(mockFatalErrorsStart);
|
||||
this.add = jest.fn();
|
||||
return this;
|
||||
});
|
||||
const MockFatalErrorsService = fatalErrorsServiceMock.create();
|
||||
const FatalErrorsServiceConstructor = jest.fn().mockImplementation(() => MockFatalErrorsService);
|
||||
jest.mock('./fatal_errors', () => ({
|
||||
FatalErrorsService: MockFatalErrorsService,
|
||||
FatalErrorsService: FatalErrorsServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockI18nStart = {};
|
||||
const MockI18nService = jest.fn<I18nService, any>(function _MockI18nService(this: any) {
|
||||
this.start = jest.fn().mockReturnValue(mockI18nStart);
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
});
|
||||
const MockI18nService = i18nServiceMock.create();
|
||||
const I18nServiceConstructor = jest.fn().mockImplementation(() => MockI18nService);
|
||||
jest.mock('./i18n', () => ({
|
||||
I18nService: MockI18nService,
|
||||
I18nService: I18nServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockNotificationStart = {};
|
||||
const MockNotificationsService = jest.fn<NotificationsService, any>(
|
||||
function _MockNotificationsService(this: any) {
|
||||
this.start = jest.fn().mockReturnValue(mockNotificationStart);
|
||||
this.add = jest.fn();
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
}
|
||||
);
|
||||
|
||||
const MockNotificationsService = notificationServiceMock.create();
|
||||
const NotificationServiceConstructor = jest.fn().mockImplementation(() => MockNotificationsService);
|
||||
jest.mock('./notifications', () => ({
|
||||
NotificationsService: MockNotificationsService,
|
||||
NotificationsService: NotificationServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockHttp = {};
|
||||
const MockHttpService = jest.fn<HttpService, any>(function _MockNotificationsService(this: any) {
|
||||
this.start = jest.fn().mockReturnValue(mockHttp);
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
});
|
||||
const MockHttpService = httpServiceMock.create();
|
||||
const HttpServiceConstructor = jest.fn().mockImplementation(() => MockHttpService);
|
||||
jest.mock('./http', () => ({
|
||||
HttpService: MockHttpService,
|
||||
HttpService: HttpServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockBasePathStart = {};
|
||||
const MockBasePathService = jest.fn<BasePathService, any>(function _MockNotificationsService(
|
||||
this: any
|
||||
) {
|
||||
this.start = jest.fn().mockReturnValue(mockBasePathStart);
|
||||
return this;
|
||||
});
|
||||
const MockBasePathService = basePathServiceMock.create();
|
||||
const BasePathServiceConstructor = jest.fn().mockImplementation(() => MockBasePathService);
|
||||
jest.mock('./base_path', () => ({
|
||||
BasePathService: MockBasePathService,
|
||||
BasePathService: BasePathServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockUiSettings = {};
|
||||
const MockUiSettingsService = jest.fn<UiSettingsService, any>(function _MockNotificationsService(
|
||||
this: any
|
||||
) {
|
||||
this.start = jest.fn().mockReturnValue(mockUiSettings);
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
});
|
||||
const MockUiSettingsService = uiSettingsServiceMock.create();
|
||||
const UiSettingsServiceConstructor = jest.fn().mockImplementation(() => MockUiSettingsService);
|
||||
jest.mock('./ui_settings', () => ({
|
||||
UiSettingsService: MockUiSettingsService,
|
||||
UiSettingsService: UiSettingsServiceConstructor,
|
||||
}));
|
||||
|
||||
const mockChromeStart = {};
|
||||
const MockChromeService = jest.fn<ChromeService, any>(function _MockNotificationsService(
|
||||
this: any
|
||||
) {
|
||||
this.start = jest.fn().mockReturnValue(mockChromeStart);
|
||||
this.stop = jest.fn();
|
||||
return this;
|
||||
});
|
||||
const MockChromeService = chromeServiceMock.create();
|
||||
const ChromeServiceConstructor = jest.fn().mockImplementation(() => MockChromeService);
|
||||
jest.mock('./chrome', () => ({
|
||||
ChromeService: MockChromeService,
|
||||
ChromeService: ChromeServiceConstructor,
|
||||
}));
|
||||
|
||||
import { CoreSystem } from './core_system';
|
||||
|
@ -149,52 +103,52 @@ beforeEach(() => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
function createCoreSystem(params = {}) {
|
||||
return new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
describe('constructor', () => {
|
||||
it('creates instances of services', () => {
|
||||
// tslint:disable no-unused-expression
|
||||
new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
createCoreSystem();
|
||||
|
||||
expect(MockInjectedMetadataService).toHaveBeenCalledTimes(1);
|
||||
expect(MockLegacyPlatformService).toHaveBeenCalledTimes(1);
|
||||
expect(MockI18nService).toHaveBeenCalledTimes(1);
|
||||
expect(MockFatalErrorsService).toHaveBeenCalledTimes(1);
|
||||
expect(MockNotificationsService).toHaveBeenCalledTimes(1);
|
||||
expect(MockHttpService).toHaveBeenCalledTimes(1);
|
||||
expect(MockBasePathService).toHaveBeenCalledTimes(1);
|
||||
expect(MockUiSettingsService).toHaveBeenCalledTimes(1);
|
||||
expect(MockChromeService).toHaveBeenCalledTimes(1);
|
||||
expect(InjectedMetadataServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(LegacyPlatformServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(I18nServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(FatalErrorsServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(NotificationServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(HttpServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(BasePathServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(UiSettingsServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(ChromeServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('passes injectedMetadata param to InjectedMetadataService', () => {
|
||||
const injectedMetadata = { injectedMetadata: true } as any;
|
||||
|
||||
// tslint:disable no-unused-expression
|
||||
new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
createCoreSystem({
|
||||
injectedMetadata,
|
||||
});
|
||||
|
||||
expect(MockInjectedMetadataService).toHaveBeenCalledTimes(1);
|
||||
expect(MockInjectedMetadataService).toHaveBeenCalledWith({
|
||||
expect(InjectedMetadataServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(InjectedMetadataServiceConstructor).toHaveBeenCalledWith({
|
||||
injectedMetadata,
|
||||
});
|
||||
});
|
||||
|
||||
it('passes requireLegacyFiles, useLegacyTestHarness, and a dom element to LegacyPlatformService', () => {
|
||||
const requireLegacyFiles = { requireLegacyFiles: true } as any;
|
||||
const useLegacyTestHarness = { useLegacyTestHarness: true } as any;
|
||||
const requireLegacyFiles = { requireLegacyFiles: true };
|
||||
const useLegacyTestHarness = { useLegacyTestHarness: true };
|
||||
|
||||
// tslint:disable no-unused-expression
|
||||
new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
createCoreSystem({
|
||||
requireLegacyFiles,
|
||||
useLegacyTestHarness,
|
||||
});
|
||||
|
||||
expect(MockLegacyPlatformService).toHaveBeenCalledTimes(1);
|
||||
expect(MockLegacyPlatformService).toHaveBeenCalledWith({
|
||||
expect(LegacyPlatformServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(LegacyPlatformServiceConstructor).toHaveBeenCalledWith({
|
||||
targetDomElement: expect.any(HTMLElement),
|
||||
requireLegacyFiles,
|
||||
useLegacyTestHarness,
|
||||
|
@ -202,46 +156,39 @@ describe('constructor', () => {
|
|||
});
|
||||
|
||||
it('passes a dom element to NotificationsService', () => {
|
||||
// tslint:disable no-unused-expression
|
||||
new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
createCoreSystem();
|
||||
|
||||
expect(MockNotificationsService).toHaveBeenCalledTimes(1);
|
||||
expect(MockNotificationsService).toHaveBeenCalledWith({
|
||||
expect(NotificationServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(NotificationServiceConstructor).toHaveBeenCalledWith({
|
||||
targetDomElement: expect.any(HTMLElement),
|
||||
});
|
||||
});
|
||||
|
||||
it('passes browserSupportsCsp to ChromeService', () => {
|
||||
new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
createCoreSystem();
|
||||
|
||||
expect(MockChromeService).toHaveBeenCalledTimes(1);
|
||||
expect(MockChromeService).toHaveBeenCalledWith({
|
||||
expect(ChromeServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
expect(ChromeServiceConstructor).toHaveBeenCalledWith({
|
||||
browserSupportsCsp: expect.any(Boolean),
|
||||
});
|
||||
});
|
||||
|
||||
it('passes injectedMetadata, rootDomElement, and a stopCoreSystem function to FatalErrorsService', () => {
|
||||
const rootDomElement = document.createElement('div');
|
||||
const injectedMetadata = { injectedMetadata: true } as any;
|
||||
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
const coreSystem = createCoreSystem({
|
||||
rootDomElement,
|
||||
injectedMetadata,
|
||||
});
|
||||
|
||||
expect(MockFatalErrorsService).toHaveBeenCalledTimes(1);
|
||||
expect(MockFatalErrorsService).toHaveBeenLastCalledWith({
|
||||
expect(FatalErrorsServiceConstructor).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(FatalErrorsServiceConstructor).toHaveBeenLastCalledWith({
|
||||
rootDomElement,
|
||||
injectedMetadata: expect.any(MockInjectedMetadataService),
|
||||
injectedMetadata: MockInjectedMetadataService,
|
||||
stopCoreSystem: expect.any(Function),
|
||||
});
|
||||
|
||||
const [{ stopCoreSystem }] = MockFatalErrorsService.mock.calls[0];
|
||||
const [{ stopCoreSystem }] = FatalErrorsServiceConstructor.mock.calls[0];
|
||||
|
||||
expect(coreSystem.stop).not.toHaveBeenCalled();
|
||||
stopCoreSystem();
|
||||
|
@ -251,75 +198,55 @@ describe('constructor', () => {
|
|||
|
||||
describe('#stop', () => {
|
||||
it('calls legacyPlatform.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
const coreSystem = createCoreSystem();
|
||||
|
||||
const [legacyPlatformService] = MockLegacyPlatformService.mock.instances;
|
||||
expect(legacyPlatformService.stop).not.toHaveBeenCalled();
|
||||
expect(MockLegacyPlatformService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(legacyPlatformService.stop).toHaveBeenCalled();
|
||||
expect(MockLegacyPlatformService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls notifications.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
const coreSystem = createCoreSystem();
|
||||
|
||||
const [notificationsService] = MockNotificationsService.mock.instances;
|
||||
expect(notificationsService.stop).not.toHaveBeenCalled();
|
||||
expect(MockNotificationsService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(notificationsService.stop).toHaveBeenCalled();
|
||||
expect(MockNotificationsService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls http.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
|
||||
const [httpService] = MockHttpService.mock.instances;
|
||||
expect(httpService.stop).not.toHaveBeenCalled();
|
||||
const coreSystem = createCoreSystem();
|
||||
expect(MockHttpService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(httpService.stop).toHaveBeenCalled();
|
||||
expect(MockHttpService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls chrome.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
const coreSystem = createCoreSystem();
|
||||
|
||||
const [chromeService] = MockChromeService.mock.instances;
|
||||
expect(chromeService.stop).not.toHaveBeenCalled();
|
||||
expect(MockChromeService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(chromeService.stop).toHaveBeenCalled();
|
||||
expect(MockChromeService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls uiSettings.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
const coreSystem = createCoreSystem();
|
||||
|
||||
const [uiSettings] = MockUiSettingsService.mock.instances;
|
||||
expect(uiSettings.stop).not.toHaveBeenCalled();
|
||||
expect(MockUiSettingsService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(uiSettings.stop).toHaveBeenCalled();
|
||||
expect(MockUiSettingsService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('calls i18n.stop()', () => {
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
});
|
||||
const coreSystem = createCoreSystem();
|
||||
|
||||
const [i18n] = MockI18nService.mock.instances;
|
||||
expect(i18n.stop).not.toHaveBeenCalled();
|
||||
expect(MockI18nService.stop).not.toHaveBeenCalled();
|
||||
coreSystem.stop();
|
||||
expect(i18n.stop).toHaveBeenCalled();
|
||||
expect(MockI18nService.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears the rootDomElement', () => {
|
||||
const rootDomElement = document.createElement('div');
|
||||
const coreSystem = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
const coreSystem = createCoreSystem({
|
||||
rootDomElement,
|
||||
});
|
||||
|
||||
|
@ -332,8 +259,7 @@ describe('#stop', () => {
|
|||
|
||||
describe('#start()', () => {
|
||||
function startCore(rootDomElement = defaultCoreSystemParams.rootDomElement) {
|
||||
const core = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
const core = createCoreSystem({
|
||||
rootDomElement,
|
||||
});
|
||||
|
||||
|
@ -349,94 +275,60 @@ describe('#start()', () => {
|
|||
|
||||
it('calls injectedMetadata#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockInjectedMetadataService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith();
|
||||
|
||||
expect(MockInjectedMetadataService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls http#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockHttpService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({
|
||||
fatalErrors: mockFatalErrorsStart,
|
||||
});
|
||||
expect(MockHttpService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls basePath#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockBasePathService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({
|
||||
injectedMetadata: mockInjectedMetadataStart,
|
||||
});
|
||||
expect(MockBasePathService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls uiSettings#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockUiSettingsService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({
|
||||
notifications: mockNotificationStart,
|
||||
http: mockHttp,
|
||||
injectedMetadata: mockInjectedMetadataStart,
|
||||
basePath: mockBasePathStart,
|
||||
});
|
||||
expect(MockUiSettingsService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls i18n#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockI18nService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith();
|
||||
expect(MockI18nService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls fatalErrors#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockFatalErrorsService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({ i18n: mockI18nStart });
|
||||
expect(MockFatalErrorsService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls notifications#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockNotificationsService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({ i18n: mockI18nStart });
|
||||
expect(MockNotificationsService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls chrome#start()', () => {
|
||||
startCore();
|
||||
const [mockInstance] = MockChromeService.mock.instances;
|
||||
expect(mockInstance.start).toHaveBeenCalledTimes(1);
|
||||
expect(mockInstance.start).toHaveBeenCalledWith({
|
||||
notifications: mockNotificationStart,
|
||||
injectedMetadata: mockInjectedMetadataStart,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns start contract', () => {
|
||||
expect(startCore()).toEqual({ fatalErrors: mockFatalErrorsStart });
|
||||
expect(MockChromeService.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LegacyPlatform targetDomElement', () => {
|
||||
it('only mounts the element when started, before starting the legacyPlatformService', () => {
|
||||
const rootDomElement = document.createElement('div');
|
||||
const core = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
const core = createCoreSystem({
|
||||
rootDomElement,
|
||||
});
|
||||
|
||||
const [legacyPlatform] = MockLegacyPlatformService.mock.instances;
|
||||
|
||||
let targetDomElementParentInStart: HTMLElement;
|
||||
(legacyPlatform as any).start.mockImplementation(() => {
|
||||
MockLegacyPlatformService.start.mockImplementation(() => {
|
||||
targetDomElementParentInStart = targetDomElement.parentElement;
|
||||
});
|
||||
|
||||
// targetDomElement should not have a parent element when the LegacyPlatformService is constructed
|
||||
const [[{ targetDomElement }]] = MockLegacyPlatformService.mock.calls;
|
||||
const [[{ targetDomElement }]] = LegacyPlatformServiceConstructor.mock.calls;
|
||||
expect(targetDomElement).toHaveProperty('parentElement', null);
|
||||
|
||||
// starting the core system should mount the targetDomElement as a child of the rootDomElement
|
||||
|
@ -448,20 +340,20 @@ describe('LegacyPlatform targetDomElement', () => {
|
|||
describe('Notifications targetDomElement', () => {
|
||||
it('only mounts the element when started, before starting the notificationsService', () => {
|
||||
const rootDomElement = document.createElement('div');
|
||||
const core = new CoreSystem({
|
||||
...defaultCoreSystemParams,
|
||||
const core = createCoreSystem({
|
||||
rootDomElement,
|
||||
});
|
||||
|
||||
const [notifications] = MockNotificationsService.mock.instances;
|
||||
|
||||
let targetDomElementParentInStart: HTMLElement;
|
||||
(notifications as any).start.mockImplementation(() => {
|
||||
targetDomElementParentInStart = targetDomElement.parentElement;
|
||||
});
|
||||
|
||||
MockNotificationsService.start.mockImplementation(
|
||||
(): any => {
|
||||
targetDomElementParentInStart = targetDomElement.parentElement;
|
||||
}
|
||||
);
|
||||
|
||||
// targetDomElement should not have a parent element when the LegacyPlatformService is constructed
|
||||
const [[{ targetDomElement }]] = MockNotificationsService.mock.calls;
|
||||
const [[{ targetDomElement }]] = NotificationServiceConstructor.mock.calls;
|
||||
expect(targetDomElement).toHaveProperty('parentElement', null);
|
||||
|
||||
// starting the core system should mount the targetDomElement as a child of the rootDomElement
|
||||
|
|
44
src/core/public/fatal_errors/fatal_errors_service.mock.ts
Normal file
44
src/core/public/fatal_errors/fatal_errors_service.mock.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { FatalErrorsService, FatalErrorsStart } from './fatal_errors_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<FatalErrorsStart> = {
|
||||
add: jest.fn<never, any>(() => undefined as never),
|
||||
get$: jest.fn(),
|
||||
};
|
||||
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type FatalErrorsServiceContract = PublicMethodsOf<FatalErrorsService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<FatalErrorsServiceContract> = {
|
||||
start: jest.fn(),
|
||||
add: jest.fn<never, any>(() => undefined as never),
|
||||
};
|
||||
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const fatalErrorsServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
42
src/core/public/http/http_service.mock.ts
Normal file
42
src/core/public/http/http_service.mock.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { HttpService, HttpStart } from './http_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<HttpStart> = {
|
||||
addLoadingCount: jest.fn(),
|
||||
getLoadingCount$: jest.fn(),
|
||||
};
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type HttpServiceContract = PublicMethodsOf<HttpService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<HttpServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const httpServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -20,13 +20,12 @@
|
|||
import * as Rx from 'rxjs';
|
||||
import { toArray } from 'rxjs/operators';
|
||||
|
||||
import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock';
|
||||
import { HttpService } from './http_service';
|
||||
|
||||
function setup() {
|
||||
const service = new HttpService();
|
||||
const fatalErrors: any = {
|
||||
add: jest.fn(),
|
||||
};
|
||||
const fatalErrors = fatalErrorsServiceMock.createStartContract();
|
||||
const start = service.start({ fatalErrors });
|
||||
|
||||
return { service, fatalErrors, start };
|
||||
|
|
41
src/core/public/i18n/i18n_service.mock.ts
Normal file
41
src/core/public/i18n/i18n_service.mock.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { I18nService, I18nStart } from './i18n_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<I18nStart> = {
|
||||
Context: jest.fn(),
|
||||
};
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type I18nServiceContract = PublicMethodsOf<I18nService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<I18nServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const i18nServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { InjectedMetadataService, InjectedMetadataStart } from './injected_metadata_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<InjectedMetadataStart> = {
|
||||
getBasePath: jest.fn(),
|
||||
getKibanaVersion: jest.fn(),
|
||||
getCspConfig: jest.fn(),
|
||||
getLegacyMetadata: jest.fn(),
|
||||
getInjectedVar: jest.fn(),
|
||||
getInjectedVars: jest.fn(),
|
||||
};
|
||||
startContract.getCspConfig.mockReturnValue({ warnLegacyBrowsers: true });
|
||||
startContract.getKibanaVersion.mockReturnValue('kibanaVersion');
|
||||
startContract.getLegacyMetadata.mockReturnValue({
|
||||
uiSettings: {
|
||||
defaults: { legacyInjectedUiSettingDefaults: true },
|
||||
user: { legacyInjectedUiSettingUserValues: true },
|
||||
},
|
||||
} as any);
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type InjectedMetadataServiceContract = PublicMethodsOf<InjectedMetadataService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<InjectedMetadataServiceContract> = {
|
||||
start: jest.fn(),
|
||||
getKibanaVersion: jest.fn(),
|
||||
getKibanaBuildNumber: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const injectedMetadataServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -40,7 +40,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`#stop() destroys the angular scope and empties the targetDomElement if angular is bootstraped to targetDomElement 1`] = `
|
||||
exports[`#stop() destroys the angular scope and empties the targetDomElement if angular is bootstrapped to targetDomElement 1`] = `
|
||||
<div
|
||||
class="ng-scope"
|
||||
/>
|
||||
|
|
32
src/core/public/legacy/legacy_service.mock.ts
Normal file
32
src/core/public/legacy/legacy_service.mock.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { LegacyPlatformService } from './legacy_service';
|
||||
|
||||
type LegacyPlatformServiceContract = PublicMethodsOf<LegacyPlatformService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<LegacyPlatformServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const legacyPlatformServiceMock = {
|
||||
create: createMock,
|
||||
};
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import angular from 'angular';
|
||||
import * as Rx from 'rxjs';
|
||||
|
||||
const mockLoadOrder: string[] = [];
|
||||
|
||||
|
@ -142,34 +141,24 @@ jest.mock('ui/chrome/services/global_nav_state', () => {
|
|||
};
|
||||
});
|
||||
|
||||
import { basePathServiceMock } from '../base_path/base_path_service.mock';
|
||||
import { chromeServiceMock } from '../chrome/chrome_service.mock';
|
||||
import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock';
|
||||
import { httpServiceMock } from '../http/http_service.mock';
|
||||
import { i18nServiceMock } from '../i18n/i18n_service.mock';
|
||||
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
|
||||
import { notificationServiceMock } from '../notifications/notifications_service.mock';
|
||||
import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock';
|
||||
import { LegacyPlatformService } from './legacy_service';
|
||||
|
||||
const fatalErrorsStart = {} as any;
|
||||
const notificationsStart = {
|
||||
toasts: {},
|
||||
} as any;
|
||||
|
||||
const injectedMetadataStart: any = {
|
||||
getBasePath: jest.fn(),
|
||||
getLegacyMetadata: jest.fn(),
|
||||
};
|
||||
|
||||
const httpStart = {
|
||||
addLoadingCount: jest.fn(),
|
||||
getLoadingCount$: jest
|
||||
.fn()
|
||||
.mockImplementation(() => new Rx.Observable(observer => observer.next(0))),
|
||||
};
|
||||
|
||||
const basePathStart = {
|
||||
get: jest.fn(),
|
||||
addToPath: jest.fn(),
|
||||
removeFromPath: jest.fn(),
|
||||
};
|
||||
|
||||
const uiSettingsStart: any = {};
|
||||
const chromeStart: any = {};
|
||||
const i18nStart: any = { Context: () => '' };
|
||||
const basePathStart = basePathServiceMock.createStartContract();
|
||||
const chromeStart = chromeServiceMock.createStartContract();
|
||||
const fatalErrorsStart = fatalErrorsServiceMock.createStartContract();
|
||||
const httpStart = httpServiceMock.createStartContract();
|
||||
const i18nStart = i18nServiceMock.createStartContract();
|
||||
const injectedMetadataStart = injectedMetadataServiceMock.createStartContract();
|
||||
const notificationsStart = notificationServiceMock.createStartContract();
|
||||
const uiSettingsStart = uiSettingsServiceMock.createStartContract();
|
||||
|
||||
const defaultParams = {
|
||||
targetDomElement: document.createElement('div'),
|
||||
|
@ -200,7 +189,7 @@ describe('#start()', () => {
|
|||
describe('default', () => {
|
||||
it('passes legacy metadata from injectedVars to ui/metadata', () => {
|
||||
const legacyMetadata = { isLegacyMetadata: true };
|
||||
injectedMetadataStart.getLegacyMetadata.mockReturnValue(legacyMetadata);
|
||||
injectedMetadataStart.getLegacyMetadata.mockReturnValue(legacyMetadata as any);
|
||||
|
||||
const legacyPlatform = new LegacyPlatformService({
|
||||
...defaultParams,
|
||||
|
@ -422,7 +411,7 @@ describe('#stop()', () => {
|
|||
expect(targetDomElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('destroys the angular scope and empties the targetDomElement if angular is bootstraped to targetDomElement', () => {
|
||||
it('destroys the angular scope and empties the targetDomElement if angular is bootstrapped to targetDomElement', () => {
|
||||
const targetDomElement = document.createElement('div');
|
||||
const scopeDestroySpy = jest.fn();
|
||||
|
||||
|
@ -431,7 +420,7 @@ describe('#stop()', () => {
|
|||
targetDomElement,
|
||||
});
|
||||
|
||||
// simulate bootstraping with a module "foo"
|
||||
// simulate bootstrapping with a module "foo"
|
||||
angular.module('foo', []).directive('bar', () => ({
|
||||
restrict: 'E',
|
||||
link($scope) {
|
||||
|
|
28
src/core/public/mocks.ts
Normal file
28
src/core/public/mocks.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export { basePathServiceMock } from './base_path/base_path_service.mock';
|
||||
export { chromeServiceMock } from './chrome/chrome_service.mock';
|
||||
export { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
|
||||
export { httpServiceMock } from './http/http_service.mock';
|
||||
export { i18nServiceMock } from './i18n/i18n_service.mock';
|
||||
export { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
|
||||
export { legacyPlatformServiceMock } from './legacy/legacy_service.mock';
|
||||
export { notificationServiceMock } from './notifications/notifications_service.mock';
|
||||
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
44
src/core/public/notifications/notifications_service.mock.ts
Normal file
44
src/core/public/notifications/notifications_service.mock.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { NotificationsService, NotificationsStart } from './notifications_service';
|
||||
import { toastsServiceMock } from './toasts/toasts_service.mock';
|
||||
import { ToastsStart } from './toasts/toasts_start';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<NotificationsStart> = {
|
||||
// we have to suppress type errors until decide how to mock es6 class
|
||||
toasts: (toastsServiceMock.createStartContract() as unknown) as ToastsStart,
|
||||
};
|
||||
return startContract;
|
||||
};
|
||||
|
||||
type NotificationsServiceContract = PublicMethodsOf<NotificationsService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<NotificationsServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const notificationServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
35
src/core/public/notifications/toasts/toasts_service.mock.ts
Normal file
35
src/core/public/notifications/toasts/toasts_service.mock.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { ToastsStart } from './toasts_start';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<PublicMethodsOf<ToastsStart>> = {
|
||||
get$: jest.fn(),
|
||||
add: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
addSuccess: jest.fn(),
|
||||
addWarning: jest.fn(),
|
||||
addDanger: jest.fn(),
|
||||
};
|
||||
return startContract;
|
||||
};
|
||||
|
||||
export const toastsServiceMock = {
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -5,7 +5,9 @@ exports[`#start constructs UiSettingsClient and UiSettingsApi: UiSettingsApi arg
|
|||
"calls": Array [
|
||||
Array [
|
||||
Object {
|
||||
"basePathStart": true,
|
||||
"addToPath": [MockFunction],
|
||||
"get": [MockFunction],
|
||||
"removeFromPath": [MockFunction],
|
||||
},
|
||||
"kibanaVersion",
|
||||
],
|
||||
|
|
|
@ -22,12 +22,12 @@ import fetchMock from 'fetch-mock/es5/client';
|
|||
import * as Rx from 'rxjs';
|
||||
import { takeUntil, toArray } from 'rxjs/operators';
|
||||
|
||||
import { basePathServiceMock } from '../base_path/base_path_service.mock';
|
||||
import { UiSettingsApi } from './ui_settings_api';
|
||||
|
||||
function setup() {
|
||||
const basePath: any = {
|
||||
addToPath: jest.fn(path => `/foo/bar${path}`),
|
||||
};
|
||||
const basePath = basePathServiceMock.createStartContract();
|
||||
basePath.addToPath.mockImplementation(path => `/foo/bar${path}`);
|
||||
|
||||
const uiSettingsApi = new UiSettingsApi(basePath, 'v9.9.9');
|
||||
|
||||
|
|
55
src/core/public/ui_settings/ui_settings_service.mock.ts
Normal file
55
src/core/public/ui_settings/ui_settings_service.mock.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { UiSettingsService, UiSettingsStart } from './ui_settings_service';
|
||||
|
||||
const createStartContractMock = () => {
|
||||
const startContract: jest.Mocked<PublicMethodsOf<UiSettingsStart>> = {
|
||||
getAll: jest.fn(),
|
||||
get: jest.fn(),
|
||||
get$: jest.fn(),
|
||||
set: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
isDeclared: jest.fn(),
|
||||
isDefault: jest.fn(),
|
||||
isCustom: jest.fn(),
|
||||
isOverridden: jest.fn(),
|
||||
overrideLocalDefault: jest.fn(),
|
||||
getUpdate$: jest.fn(),
|
||||
getSaved$: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
// we have to suppress type errors until decide how to mock es6 class
|
||||
return (startContract as unknown) as UiSettingsStart;
|
||||
};
|
||||
|
||||
type UiSettingsServiceContract = PublicMethodsOf<UiSettingsService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<UiSettingsServiceContract> = {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
|
||||
mocked.start.mockReturnValue(createStartContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const uiSettingsServiceMock = {
|
||||
create: createMock,
|
||||
createStartContract: createStartContractMock,
|
||||
};
|
|
@ -56,31 +56,19 @@ const MockUiSettingsClient = mockClass('./ui_settings_client', UiSettingsClient,
|
|||
inst.stop = jest.fn();
|
||||
});
|
||||
|
||||
// Load the service
|
||||
import { basePathServiceMock } from '../base_path/base_path_service.mock';
|
||||
import { httpServiceMock } from '../http/http_service.mock';
|
||||
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
|
||||
import { notificationServiceMock } from '../notifications/notifications_service.mock';
|
||||
import { UiSettingsService } from './ui_settings_service';
|
||||
|
||||
const httpStart = {
|
||||
addLoadingCount: jest.fn(),
|
||||
};
|
||||
const httpStart = httpServiceMock.createStartContract();
|
||||
|
||||
const defaultDeps: any = {
|
||||
notifications: {
|
||||
notificationsStart: true,
|
||||
},
|
||||
const defaultDeps = {
|
||||
notifications: notificationServiceMock.createStartContract(),
|
||||
http: httpStart,
|
||||
injectedMetadata: {
|
||||
injectedMetadataStart: true,
|
||||
getKibanaVersion: jest.fn().mockReturnValue('kibanaVersion'),
|
||||
getLegacyMetadata: jest.fn().mockReturnValue({
|
||||
uiSettings: {
|
||||
defaults: { legacyInjectedUiSettingDefaults: true },
|
||||
user: { legacyInjectedUiSettingUserValues: true },
|
||||
},
|
||||
}),
|
||||
},
|
||||
basePath: {
|
||||
basePathStart: true,
|
||||
},
|
||||
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
|
||||
basePath: basePathServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -21,12 +21,6 @@ import { ObjectToConfigAdapter } from './object_to_config_adapter';
|
|||
|
||||
import { ConfigService } from './config_service';
|
||||
|
||||
type MethodKeysOf<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
|
||||
}[keyof T];
|
||||
|
||||
type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
|
||||
|
||||
type ConfigSericeContract = PublicMethodsOf<ConfigService>;
|
||||
const createConfigServiceMock = () => {
|
||||
const mocked: jest.Mocked<ConfigSericeContract> = {
|
||||
|
|
|
@ -34,12 +34,6 @@ const createStartContractMock = () => {
|
|||
return startContract;
|
||||
};
|
||||
|
||||
type MethodKeysOf<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
|
||||
}[keyof T];
|
||||
|
||||
type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
|
||||
|
||||
type ElasticsearchServiceContract = PublicMethodsOf<ElasticsearchService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<ElasticsearchServiceContract> = {
|
||||
|
|
|
@ -28,12 +28,6 @@ const createStartContractMock = () => {
|
|||
return startContract;
|
||||
};
|
||||
|
||||
type MethodKeysOf<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
|
||||
}[keyof T];
|
||||
|
||||
type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
|
||||
|
||||
type HttpSericeContract = PublicMethodsOf<HttpService>;
|
||||
const createHttpServiceMock = () => {
|
||||
const mocked: jest.Mocked<HttpSericeContract> = {
|
||||
|
|
|
@ -21,12 +21,6 @@
|
|||
import { Logger } from './logger';
|
||||
import { LoggingService } from './logging_service';
|
||||
|
||||
type MethodKeysOf<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
|
||||
}[keyof T];
|
||||
|
||||
type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
|
||||
|
||||
type LoggingServiceContract = PublicMethodsOf<LoggingService>;
|
||||
type MockedLogger = jest.Mocked<Logger>;
|
||||
|
||||
|
|
23
src/core/server/mocks.ts
Normal file
23
src/core/server/mocks.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export { configServiceMock } from './config/config_service.mock';
|
||||
export { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock';
|
||||
export { httpServiceMock } from './http/http_service.mock';
|
||||
export { loggingServiceMock } from './logging/logging_service.mock';
|
|
@ -17,6 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { basePathServiceMock } from '../../../../../core/public/mocks';
|
||||
import { __newPlatformInit__, initChromeBasePathApi } from './base_path';
|
||||
|
||||
function initChrome() {
|
||||
|
@ -25,11 +26,7 @@ function initChrome() {
|
|||
return chrome;
|
||||
}
|
||||
|
||||
const newPlatformBasePath = {
|
||||
get: jest.fn().mockReturnValue('get'),
|
||||
addToPath: jest.fn().mockReturnValue('addToPath'),
|
||||
removeFromPath: jest.fn().mockReturnValue('removeFromPath'),
|
||||
};
|
||||
const newPlatformBasePath = basePathServiceMock.createStartContract();
|
||||
__newPlatformInit__(newPlatformBasePath);
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -19,14 +19,12 @@
|
|||
|
||||
import * as Rx from 'rxjs';
|
||||
|
||||
import { chromeServiceMock } from '../../../../../core/public/mocks';
|
||||
import { __newPlatformInit__, initChromeControlsApi } from './controls';
|
||||
|
||||
const newPlatformChrome = {
|
||||
setIsVisible: jest.fn(),
|
||||
getIsVisible$: jest.fn(),
|
||||
};
|
||||
const newPlatformChrome = chromeServiceMock.createStartContract();
|
||||
|
||||
__newPlatformInit__(newPlatformChrome as any);
|
||||
__newPlatformInit__(newPlatformChrome);
|
||||
|
||||
function setup() {
|
||||
const isVisible$ = new Rx.BehaviorSubject(true);
|
||||
|
|
|
@ -19,17 +19,12 @@
|
|||
|
||||
import * as Rx from 'rxjs';
|
||||
|
||||
import { chromeServiceMock } from '../../../../../core/public/mocks';
|
||||
import { __newPlatformInit__, initChromeThemeApi } from './theme';
|
||||
|
||||
const newPlatformChrome = {
|
||||
setBrand: jest.fn(),
|
||||
getBrand$: jest.fn(),
|
||||
addApplicationClass: jest.fn(),
|
||||
removeApplicationClass: jest.fn(),
|
||||
getApplicationClasses$: jest.fn(),
|
||||
};
|
||||
const newPlatformChrome = chromeServiceMock.createStartContract();
|
||||
|
||||
__newPlatformInit__(newPlatformChrome as any);
|
||||
__newPlatformInit__(newPlatformChrome);
|
||||
|
||||
function setup() {
|
||||
const brand$ = new Rx.BehaviorSubject({ logo: 'foo', smallLogo: 'foo' });
|
||||
|
|
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
|
@ -21,3 +21,9 @@ declare module '*.html' {
|
|||
const template: string;
|
||||
export default template;
|
||||
}
|
||||
|
||||
type MethodKeysOf<T> = {
|
||||
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never
|
||||
}[keyof T];
|
||||
|
||||
type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue