From 027d812f50a727f4215a4223380a821508a70d4b Mon Sep 17 00:00:00 2001 From: restrry Date: Tue, 12 Mar 2019 15:22:22 +0100 Subject: [PATCH 1/6] Add client side service mocks --- src/core/public/base_path/base_path.mock.ts | 51 +++ .../base_path/base_path_service.test.ts | 6 +- src/core/public/chrome/chrome_service.mock.ts | 66 ++++ src/core/public/chrome/chrome_service.test.ts | 21 +- src/core/public/core_system.test.ts | 346 ++++++------------ .../fatal_errors/fatal_errors_service.mock.ts | 50 +++ src/core/public/http/http_service.mock.ts | 48 +++ src/core/public/http/http_service.test.ts | 5 +- src/core/public/i18n/i18n_service.mock.ts | 47 +++ .../injected_metadata_service.mock.ts | 61 +++ src/core/public/legacy/legacy_service.mock.ts | 38 ++ src/core/public/legacy/legacy_service.test.ts | 49 +-- .../notifications_service.mock.ts | 44 +++ .../toasts/toasts_service.mock.ts | 41 +++ .../ui_settings_service.test.ts.snap | 4 +- .../ui_settings/ui_settings_api.test.ts | 6 +- .../ui_settings/ui_settings_service.mock.ts | 61 +++ .../ui_settings/ui_settings_service.test.ts | 30 +- .../ui/public/chrome/api/base_path.test.ts | 7 +- .../ui/public/chrome/api/controls.test.ts | 8 +- src/legacy/ui/public/chrome/api/theme.test.ts | 11 +- 21 files changed, 678 insertions(+), 322 deletions(-) create mode 100644 src/core/public/base_path/base_path.mock.ts create mode 100644 src/core/public/chrome/chrome_service.mock.ts create mode 100644 src/core/public/fatal_errors/fatal_errors_service.mock.ts create mode 100644 src/core/public/http/http_service.mock.ts create mode 100644 src/core/public/i18n/i18n_service.mock.ts create mode 100644 src/core/public/injected_metadata/injected_metadata_service.mock.ts create mode 100644 src/core/public/legacy/legacy_service.mock.ts create mode 100644 src/core/public/notifications/notifications_service.mock.ts create mode 100644 src/core/public/notifications/toasts/toasts_service.mock.ts create mode 100644 src/core/public/ui_settings/ui_settings_service.mock.ts diff --git a/src/core/public/base_path/base_path.mock.ts b/src/core/public/base_path/base_path.mock.ts new file mode 100644 index 0000000000000..3b28f87810a1c --- /dev/null +++ b/src/core/public/base_path/base_path.mock.ts @@ -0,0 +1,51 @@ +/* + * 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 = { + get: jest.fn(), + addToPath: jest.fn(), + removeFromPath: jest.fn(), + }; + startContract.get.mockReturnValue('get'); + startContract.addToPath.mockReturnValue('addToPath'); + startContract.removeFromPath.mockReturnValue('removeFromPath'); + return startContract; +}; + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type BasePathServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const basePathServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/base_path/base_path_service.test.ts b/src/core/public/base_path/base_path_service.test.ts index fad092bf6fce9..1a0025ea91aca 100644 --- a/src/core/public/base_path/base_path_service.test.ts +++ b/src/core/public/base_path/base_path_service.test.ts @@ -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, diff --git a/src/core/public/chrome/chrome_service.mock.ts b/src/core/public/chrome/chrome_service.mock.ts new file mode 100644 index 0000000000000..d04c6f6986a47 --- /dev/null +++ b/src/core/public/chrome/chrome_service.mock.ts @@ -0,0 +1,66 @@ +/* + * 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 = { + 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 MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type ChromeServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const chromeServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/chrome/chrome_service.test.ts b/src/core/public/chrome/chrome_service.test.ts index 7526ff9305014..b0b7985535b42 100644 --- a/src/core/public/chrome/chrome_service.test.ts +++ b/src/core/public/chrome/chrome_service.test.ts @@ -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(), }; } diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index ffda17e340e11..2b9901abe8f23 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -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( - function _MockLegacyPlatformService(this: any) { - this.start = jest.fn(); - this.stop = jest.fn(); - return this; - } -); - +import { basePathServiceMock } from './base_path/base_path.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( - 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(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(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( - 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(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(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(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(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, - }); - - 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); + createCoreSystem(); + + 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 diff --git a/src/core/public/fatal_errors/fatal_errors_service.mock.ts b/src/core/public/fatal_errors/fatal_errors_service.mock.ts new file mode 100644 index 0000000000000..03199bdd55ec3 --- /dev/null +++ b/src/core/public/fatal_errors/fatal_errors_service.mock.ts @@ -0,0 +1,50 @@ +/* + * 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 = { + add: jest.fn(() => undefined as never), + get$: jest.fn(), + }; + + return startContract; +}; + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type FatalErrorsServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + add: jest.fn(() => undefined as never), + }; + + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const fatalErrorsServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/http/http_service.mock.ts b/src/core/public/http/http_service.mock.ts new file mode 100644 index 0000000000000..665ef50ab9113 --- /dev/null +++ b/src/core/public/http/http_service.mock.ts @@ -0,0 +1,48 @@ +/* + * 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 = { + addLoadingCount: jest.fn(), + getLoadingCount$: jest.fn(), + }; + return startContract; +}; + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type HttpServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const httpServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/http/http_service.test.ts b/src/core/public/http/http_service.test.ts index 83cb34244fcf7..64f93755fd195 100644 --- a/src/core/public/http/http_service.test.ts +++ b/src/core/public/http/http_service.test.ts @@ -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 }; diff --git a/src/core/public/i18n/i18n_service.mock.ts b/src/core/public/i18n/i18n_service.mock.ts new file mode 100644 index 0000000000000..0edf99751f541 --- /dev/null +++ b/src/core/public/i18n/i18n_service.mock.ts @@ -0,0 +1,47 @@ +/* + * 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 = { + Context: jest.fn(), + }; + return startContract; +}; + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type I18nServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const i18nServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/injected_metadata/injected_metadata_service.mock.ts b/src/core/public/injected_metadata/injected_metadata_service.mock.ts new file mode 100644 index 0000000000000..e1ab097566e76 --- /dev/null +++ b/src/core/public/injected_metadata/injected_metadata_service.mock.ts @@ -0,0 +1,61 @@ +/* + * 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 = { + 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 MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type InjectedMetadataServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + getKibanaVersion: jest.fn(), + getKibanaBuildNumber: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const injectedMetadataServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/legacy/legacy_service.mock.ts b/src/core/public/legacy/legacy_service.mock.ts new file mode 100644 index 0000000000000..a8cd8b4ad9a20 --- /dev/null +++ b/src/core/public/legacy/legacy_service.mock.ts @@ -0,0 +1,38 @@ +/* + * 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 MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type LegacyPlatformServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + return mocked; +}; + +export const legacyPlatformServiceMock = { + create: createMock, +}; diff --git a/src/core/public/legacy/legacy_service.test.ts b/src/core/public/legacy/legacy_service.test.ts index efe158b926ca5..7c3d0261661fb 100644 --- a/src/core/public/legacy/legacy_service.test.ts +++ b/src/core/public/legacy/legacy_service.test.ts @@ -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.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) { diff --git a/src/core/public/notifications/notifications_service.mock.ts b/src/core/public/notifications/notifications_service.mock.ts new file mode 100644 index 0000000000000..06ae623a30041 --- /dev/null +++ b/src/core/public/notifications/notifications_service.mock.ts @@ -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 = { + // 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; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const notificationServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/notifications/toasts/toasts_service.mock.ts b/src/core/public/notifications/toasts/toasts_service.mock.ts new file mode 100644 index 0000000000000..82ac389cd515c --- /dev/null +++ b/src/core/public/notifications/toasts/toasts_service.mock.ts @@ -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 { ToastsStart } from './toasts_start'; + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +const createStartContractMock = () => { + const startContract: jest.Mocked> = { + 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, +}; diff --git a/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap b/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap index bf8f8ba2131a2..9e591a5abd50c 100644 --- a/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap +++ b/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap @@ -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", ], diff --git a/src/core/public/ui_settings/ui_settings_api.test.ts b/src/core/public/ui_settings/ui_settings_api.test.ts index 520ebf67c83d1..aa19795a42ecf 100644 --- a/src/core/public/ui_settings/ui_settings_api.test.ts +++ b/src/core/public/ui_settings/ui_settings_api.test.ts @@ -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.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'); diff --git a/src/core/public/ui_settings/ui_settings_service.mock.ts b/src/core/public/ui_settings/ui_settings_service.mock.ts new file mode 100644 index 0000000000000..5a483074aa88e --- /dev/null +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -0,0 +1,61 @@ +/* + * 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> = { + 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 MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + +type UiSettingsServiceContract = PublicMethodsOf; +const createMock = () => { + const mocked: jest.Mocked = { + start: jest.fn(), + stop: jest.fn(), + }; + + mocked.start.mockReturnValue(createStartContractMock()); + return mocked; +}; + +export const uiSettingsServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/ui_settings/ui_settings_service.test.ts b/src/core/public/ui_settings/ui_settings_service.test.ts index b21fa4a4d144a..110d9316c0aa6 100644 --- a/src/core/public/ui_settings/ui_settings_service.test.ts +++ b/src/core/public/ui_settings/ui_settings_service.test.ts @@ -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.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(() => { diff --git a/src/legacy/ui/public/chrome/api/base_path.test.ts b/src/legacy/ui/public/chrome/api/base_path.test.ts index e6c0c7fb21708..c3e27fe3afa51 100644 --- a/src/legacy/ui/public/chrome/api/base_path.test.ts +++ b/src/legacy/ui/public/chrome/api/base_path.test.ts @@ -17,6 +17,7 @@ * under the License. */ +import { basePathServiceMock } from '../../../../../core/public/base_path/base_path.mock'; 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(() => { diff --git a/src/legacy/ui/public/chrome/api/controls.test.ts b/src/legacy/ui/public/chrome/api/controls.test.ts index f6a7fecf0f2c9..13dbca08c1336 100644 --- a/src/legacy/ui/public/chrome/api/controls.test.ts +++ b/src/legacy/ui/public/chrome/api/controls.test.ts @@ -19,14 +19,12 @@ import * as Rx from 'rxjs'; +import { chromeServiceMock } from '../../../../../core/public/chrome/chrome_service.mock'; 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); diff --git a/src/legacy/ui/public/chrome/api/theme.test.ts b/src/legacy/ui/public/chrome/api/theme.test.ts index 76a7be677bd6a..6f264814691a0 100644 --- a/src/legacy/ui/public/chrome/api/theme.test.ts +++ b/src/legacy/ui/public/chrome/api/theme.test.ts @@ -19,17 +19,12 @@ import * as Rx from 'rxjs'; +import { chromeServiceMock } from '../../../../../core/public/chrome/chrome_service.mock'; 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' }); From c77a59dd3ec7200410ca9ab1dd5d93ca02af26c9 Mon Sep 17 00:00:00 2001 From: restrry Date: Tue, 12 Mar 2019 07:54:59 -0700 Subject: [PATCH 2/6] remove ab obsolete test snapshot --- .../public/legacy/__snapshots__/legacy_service.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap b/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap index 84d2ba6c9fca7..67306bb67460c 100644 --- a/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap +++ b/src/core/public/legacy/__snapshots__/legacy_service.test.ts.snap @@ -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`] = `
From 7be3421e288da4d9b2942b1408c13493e57a3f6a Mon Sep 17 00:00:00 2001 From: restrry Date: Tue, 12 Mar 2019 09:00:47 -0700 Subject: [PATCH 3/6] put back accidentally removed type definition --- src/core/public/notifications/notifications_service.mock.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/public/notifications/notifications_service.mock.ts b/src/core/public/notifications/notifications_service.mock.ts index 06ae623a30041..b9d066243b9ca 100644 --- a/src/core/public/notifications/notifications_service.mock.ts +++ b/src/core/public/notifications/notifications_service.mock.ts @@ -28,6 +28,12 @@ const createStartContractMock = () => { return startContract; }; +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; + type NotificationsServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { From df95b2aa3083a722928418d3d7a1cdcca308f0a3 Mon Sep 17 00:00:00 2001 From: restrry Date: Sat, 16 Mar 2019 15:26:58 -0700 Subject: [PATCH 4/6] define MethodKeysOf, PublicMethodsOf on project level --- src/core/public/base_path/base_path.mock.ts | 6 ------ src/core/public/chrome/chrome_service.mock.ts | 6 ------ src/core/public/fatal_errors/fatal_errors_service.mock.ts | 6 ------ src/core/public/http/http_service.mock.ts | 6 ------ src/core/public/i18n/i18n_service.mock.ts | 6 ------ .../injected_metadata/injected_metadata_service.mock.ts | 6 ------ src/core/public/legacy/legacy_service.mock.ts | 6 ------ src/core/public/notifications/notifications_service.mock.ts | 6 ------ src/core/public/notifications/toasts/toasts_service.mock.ts | 6 ------ src/core/public/ui_settings/ui_settings_service.mock.ts | 6 ------ src/core/server/config/config_service.mock.ts | 6 ------ src/core/server/elasticsearch/elasticsearch_service.mock.ts | 6 ------ src/core/server/http/http_service.mock.ts | 6 ------ src/core/server/logging/logging_service.mock.ts | 6 ------ typings/index.d.ts | 6 ++++++ 15 files changed, 6 insertions(+), 84 deletions(-) diff --git a/src/core/public/base_path/base_path.mock.ts b/src/core/public/base_path/base_path.mock.ts index 3b28f87810a1c..0151688f6ce49 100644 --- a/src/core/public/base_path/base_path.mock.ts +++ b/src/core/public/base_path/base_path.mock.ts @@ -30,12 +30,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type BasePathServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/chrome/chrome_service.mock.ts b/src/core/public/chrome/chrome_service.mock.ts index d04c6f6986a47..b5331810df1fe 100644 --- a/src/core/public/chrome/chrome_service.mock.ts +++ b/src/core/public/chrome/chrome_service.mock.ts @@ -44,12 +44,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type ChromeServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/fatal_errors/fatal_errors_service.mock.ts b/src/core/public/fatal_errors/fatal_errors_service.mock.ts index 03199bdd55ec3..6908c26a43bd6 100644 --- a/src/core/public/fatal_errors/fatal_errors_service.mock.ts +++ b/src/core/public/fatal_errors/fatal_errors_service.mock.ts @@ -27,12 +27,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type FatalErrorsServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/http/http_service.mock.ts b/src/core/public/http/http_service.mock.ts index 665ef50ab9113..29204f1c53406 100644 --- a/src/core/public/http/http_service.mock.ts +++ b/src/core/public/http/http_service.mock.ts @@ -26,12 +26,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type HttpServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/i18n/i18n_service.mock.ts b/src/core/public/i18n/i18n_service.mock.ts index 0edf99751f541..8c3123d4dd350 100644 --- a/src/core/public/i18n/i18n_service.mock.ts +++ b/src/core/public/i18n/i18n_service.mock.ts @@ -25,12 +25,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type I18nServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/injected_metadata/injected_metadata_service.mock.ts b/src/core/public/injected_metadata/injected_metadata_service.mock.ts index e1ab097566e76..3e25fdaca532e 100644 --- a/src/core/public/injected_metadata/injected_metadata_service.mock.ts +++ b/src/core/public/injected_metadata/injected_metadata_service.mock.ts @@ -38,12 +38,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type InjectedMetadataServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/legacy/legacy_service.mock.ts b/src/core/public/legacy/legacy_service.mock.ts index a8cd8b4ad9a20..fab02bb38a735 100644 --- a/src/core/public/legacy/legacy_service.mock.ts +++ b/src/core/public/legacy/legacy_service.mock.ts @@ -18,12 +18,6 @@ */ import { LegacyPlatformService } from './legacy_service'; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type LegacyPlatformServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/notifications/notifications_service.mock.ts b/src/core/public/notifications/notifications_service.mock.ts index b9d066243b9ca..06ae623a30041 100644 --- a/src/core/public/notifications/notifications_service.mock.ts +++ b/src/core/public/notifications/notifications_service.mock.ts @@ -28,12 +28,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type NotificationsServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/public/notifications/toasts/toasts_service.mock.ts b/src/core/public/notifications/toasts/toasts_service.mock.ts index 82ac389cd515c..7e1734497436d 100644 --- a/src/core/public/notifications/toasts/toasts_service.mock.ts +++ b/src/core/public/notifications/toasts/toasts_service.mock.ts @@ -18,12 +18,6 @@ */ import { ToastsStart } from './toasts_start'; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - const createStartContractMock = () => { const startContract: jest.Mocked> = { get$: jest.fn(), diff --git a/src/core/public/ui_settings/ui_settings_service.mock.ts b/src/core/public/ui_settings/ui_settings_service.mock.ts index 5a483074aa88e..0de29bdcb901a 100644 --- a/src/core/public/ui_settings/ui_settings_service.mock.ts +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -38,12 +38,6 @@ const createStartContractMock = () => { return (startContract as unknown) as UiSettingsStart; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type UiSettingsServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/server/config/config_service.mock.ts b/src/core/server/config/config_service.mock.ts index 30a9f8961a0ce..d9f460905fc43 100644 --- a/src/core/server/config/config_service.mock.ts +++ b/src/core/server/config/config_service.mock.ts @@ -21,12 +21,6 @@ import { ObjectToConfigAdapter } from './object_to_config_adapter'; import { ConfigService } from './config_service'; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type ConfigSericeContract = PublicMethodsOf; const createConfigServiceMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/src/core/server/elasticsearch/elasticsearch_service.mock.ts index d26bd342e9163..00095e4613c98 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.mock.ts @@ -34,12 +34,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type ElasticsearchServiceContract = PublicMethodsOf; const createMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 024ff3a0307c9..be14fd9ae3a0b 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -28,12 +28,6 @@ const createStartContractMock = () => { return startContract; }; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type HttpSericeContract = PublicMethodsOf; const createHttpServiceMock = () => { const mocked: jest.Mocked = { diff --git a/src/core/server/logging/logging_service.mock.ts b/src/core/server/logging/logging_service.mock.ts index 3e5755de105c8..4bef2fe745c7d 100644 --- a/src/core/server/logging/logging_service.mock.ts +++ b/src/core/server/logging/logging_service.mock.ts @@ -21,12 +21,6 @@ import { Logger } from './logger'; import { LoggingService } from './logging_service'; -type MethodKeysOf = { - [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never -}[keyof T]; - -type PublicMethodsOf = Pick>; - type LoggingServiceContract = PublicMethodsOf; type MockedLogger = jest.Mocked; diff --git a/typings/index.d.ts b/typings/index.d.ts index ab409a41fa541..f4ccecec01118 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -21,3 +21,9 @@ declare module '*.html' { const template: string; export default template; } + +type MethodKeysOf = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never +}[keyof T]; + +type PublicMethodsOf = Pick>; From 1022fae48ccb59021b5d4ef8363743d99a881a06 Mon Sep 17 00:00:00 2001 From: restrry Date: Sat, 16 Mar 2019 15:48:38 -0700 Subject: [PATCH 5/6] export src/core/public service mocks --- ...path.mock.ts => base_path_service.mock.ts} | 0 src/core/public/core_system.test.ts | 2 +- src/core/public/legacy/legacy_service.test.ts | 2 +- src/core/public/mocks.ts | 28 +++++++++++++++++++ .../ui_settings/ui_settings_api.test.ts | 2 +- .../ui_settings/ui_settings_service.test.ts | 2 +- .../ui/public/chrome/api/base_path.test.ts | 2 +- .../ui/public/chrome/api/controls.test.ts | 2 +- src/legacy/ui/public/chrome/api/theme.test.ts | 2 +- 9 files changed, 35 insertions(+), 7 deletions(-) rename src/core/public/base_path/{base_path.mock.ts => base_path_service.mock.ts} (100%) create mode 100644 src/core/public/mocks.ts diff --git a/src/core/public/base_path/base_path.mock.ts b/src/core/public/base_path/base_path_service.mock.ts similarity index 100% rename from src/core/public/base_path/base_path.mock.ts rename to src/core/public/base_path/base_path_service.mock.ts diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index 2b9901abe8f23..060a545782217 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { basePathServiceMock } from './base_path/base_path.mock'; +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'; diff --git a/src/core/public/legacy/legacy_service.test.ts b/src/core/public/legacy/legacy_service.test.ts index 7c3d0261661fb..be103f6186df2 100644 --- a/src/core/public/legacy/legacy_service.test.ts +++ b/src/core/public/legacy/legacy_service.test.ts @@ -141,7 +141,7 @@ jest.mock('ui/chrome/services/global_nav_state', () => { }; }); -import { basePathServiceMock } from '../base_path/base_path.mock'; +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'; diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts new file mode 100644 index 0000000000000..e58bb2f0efb3a --- /dev/null +++ b/src/core/public/mocks.ts @@ -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'; diff --git a/src/core/public/ui_settings/ui_settings_api.test.ts b/src/core/public/ui_settings/ui_settings_api.test.ts index aa19795a42ecf..37b185648c9e0 100644 --- a/src/core/public/ui_settings/ui_settings_api.test.ts +++ b/src/core/public/ui_settings/ui_settings_api.test.ts @@ -22,7 +22,7 @@ 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.mock'; +import { basePathServiceMock } from '../base_path/base_path_service.mock'; import { UiSettingsApi } from './ui_settings_api'; function setup() { diff --git a/src/core/public/ui_settings/ui_settings_service.test.ts b/src/core/public/ui_settings/ui_settings_service.test.ts index 110d9316c0aa6..0100ceb611ffa 100644 --- a/src/core/public/ui_settings/ui_settings_service.test.ts +++ b/src/core/public/ui_settings/ui_settings_service.test.ts @@ -56,7 +56,7 @@ const MockUiSettingsClient = mockClass('./ui_settings_client', UiSettingsClient, inst.stop = jest.fn(); }); -import { basePathServiceMock } from '../base_path/base_path.mock'; +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'; diff --git a/src/legacy/ui/public/chrome/api/base_path.test.ts b/src/legacy/ui/public/chrome/api/base_path.test.ts index c3e27fe3afa51..de2727df36eba 100644 --- a/src/legacy/ui/public/chrome/api/base_path.test.ts +++ b/src/legacy/ui/public/chrome/api/base_path.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { basePathServiceMock } from '../../../../../core/public/base_path/base_path.mock'; +import { basePathServiceMock } from '../../../../../core/public/mocks'; import { __newPlatformInit__, initChromeBasePathApi } from './base_path'; function initChrome() { diff --git a/src/legacy/ui/public/chrome/api/controls.test.ts b/src/legacy/ui/public/chrome/api/controls.test.ts index 13dbca08c1336..16d1c1a4eee11 100644 --- a/src/legacy/ui/public/chrome/api/controls.test.ts +++ b/src/legacy/ui/public/chrome/api/controls.test.ts @@ -19,7 +19,7 @@ import * as Rx from 'rxjs'; -import { chromeServiceMock } from '../../../../../core/public/chrome/chrome_service.mock'; +import { chromeServiceMock } from '../../../../../core/public/mocks'; import { __newPlatformInit__, initChromeControlsApi } from './controls'; const newPlatformChrome = chromeServiceMock.createStartContract(); diff --git a/src/legacy/ui/public/chrome/api/theme.test.ts b/src/legacy/ui/public/chrome/api/theme.test.ts index 6f264814691a0..d2108d471d53a 100644 --- a/src/legacy/ui/public/chrome/api/theme.test.ts +++ b/src/legacy/ui/public/chrome/api/theme.test.ts @@ -19,7 +19,7 @@ import * as Rx from 'rxjs'; -import { chromeServiceMock } from '../../../../../core/public/chrome/chrome_service.mock'; +import { chromeServiceMock } from '../../../../../core/public/mocks'; import { __newPlatformInit__, initChromeThemeApi } from './theme'; const newPlatformChrome = chromeServiceMock.createStartContract(); From f6433b5042b1031efdea0fd869f0c1882c60997e Mon Sep 17 00:00:00 2001 From: restrry Date: Sat, 16 Mar 2019 15:52:22 -0700 Subject: [PATCH 6/6] export src/core/server service mocks --- src/core/server/mocks.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/core/server/mocks.ts diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts new file mode 100644 index 0000000000000..2fac83e3a2798 --- /dev/null +++ b/src/core/server/mocks.ts @@ -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';