From 968fb71f3c1a7d92980e687306577ac90feac3b4 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 20 Jun 2019 16:58:41 +0200 Subject: [PATCH 01/15] Mocks for CoreStart, CoreSetup and PluginInitializerContext --- src/core/server/http/http_service.mock.ts | 1 + src/core/server/mocks.ts | 55 +++++++++++++++++++++++ src/core/server/plugins/plugin_context.ts | 6 +-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 2ea0614645c60..9b241e8679318 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -73,4 +73,5 @@ const createHttpServiceMock = () => { export const httpServiceMock = { create: createHttpServiceMock, createSetupContract: createSetupContractMock, + createStartContract: createStartContractMock, }; diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index b7a9ac2c79454..c77fd0f23e6f9 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -16,9 +16,64 @@ * specific language governing permissions and limitations * under the License. */ +import { of } from 'rxjs'; +import { PluginInitializerContext, CoreSetup, CoreStart } from '.'; +import { loggingServiceMock } from './logging/logging_service.mock'; +import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock'; +import { httpServiceMock } from './http/http_service.mock'; 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'; export { SavedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; + +export function pluginInitializerContextConfigMock(defaultValue: T) { + return (value?: Partial) => { + const config: T = Object.assign({}, defaultValue, value); + + const mock: jest.Mocked['config']> = { + create: jest.fn().mockReturnValue(of(config)), + createIfExists: jest.fn().mockReturnValue(of(config)), + }; + + return mock; + }; +} + +function pluginInitializerContextMock(config: T) { + const mock: jest.Mocked> = { + logger: loggingServiceMock.create(), + env: { + mode: { + dev: true, + name: 'development', + prod: false, + }, + }, + config: pluginInitializerContextConfigMock(config)() as jest.Mocked< + PluginInitializerContext['config'] + >, + }; + + return mock.config; +} + +function createCoreSetupMock() { + const mock: jest.Mocked = { + elasticsearch: elasticsearchServiceMock.createSetupContract(), + http: httpServiceMock.createSetupContract(), + }; + + return mock; +} + +function createCoreStartMock() { + return {} as jest.Mocked; +} + +export const coreMock = { + createSetup: createCoreSetupMock, + createStart: createCoreStartMock, + createPluginInitializerContext: pluginInitializerContextMock, +}; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 10912ca608485..00d09e8873391 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -30,12 +30,12 @@ import { CoreSetup, CoreStart } from '..'; * * @public */ -export interface PluginInitializerContext { +export interface PluginInitializerContext { env: { mode: EnvironmentMode }; logger: LoggerFactory; config: { - create: () => Observable; - createIfExists: () => Observable; + create: () => Observable; + createIfExists: () => Observable; }; } From f189fdc7fab7fbcb0ae00128e5f3ae6aed81c199 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 21 Jun 2019 13:20:04 +0200 Subject: [PATCH 02/15] Public CoreStart, CoreSetup mocks --- src/core/public/mocks.ts | 40 +++++++++++++++++++ .../notifications/toasts/toasts_api.test.ts | 3 +- .../ui_settings/ui_settings_service.mock.ts | 4 +- .../public/ui_settings/ui_settings_service.ts | 4 +- src/core/server/plugins/plugin_context.ts | 4 +- .../notify/toasts/toast_notifications.test.ts | 4 +- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index cb09b1d0b6be5..ab1992cc5cf53 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -16,6 +16,15 @@ * specific language governing permissions and limitations * under the License. */ +import { CoreSetup, CoreStart, PluginInitializerContext } from '.'; +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 { notificationServiceMock } from './notifications/notifications_service.mock'; +import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; +import { applicationServiceMock } from './application/application_service.mock'; +import { overlayServiceMock } from './overlays/overlay_service.mock'; export { chromeServiceMock } from './chrome/chrome_service.mock'; export { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock'; @@ -25,3 +34,34 @@ export { injectedMetadataServiceMock } from './injected_metadata/injected_metada export { legacyPlatformServiceMock } from './legacy/legacy_service.mock'; export { notificationServiceMock } from './notifications/notifications_service.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; + +function createCoreSetupMock() { + const mock: jest.Mocked = { + http: httpServiceMock.createSetupContract(), + fatalErrors: fatalErrorsServiceMock.createSetupContract(), + notifications: notificationServiceMock.createSetupContract(), + uiSettings: uiSettingsServiceMock.createSetupContract(), + }; + + return mock; +} + +function createCoreStartMock() { + const mock: jest.Mocked = { + uiSettings: uiSettingsServiceMock.createStartContract(), + application: applicationServiceMock.createStartContract(), + chrome: chromeServiceMock.createStartContract(), + http: httpServiceMock.createStartContract(), + i18n: i18nServiceMock.createStartContract(), + notifications: notificationServiceMock.createStartContract(), + overlays: overlayServiceMock.createStartContract(), + }; + + return mock; +} + +export const coreMock = { + createSetup: createCoreSetupMock, + createStart: createCoreStartMock, + createPluginInitializerContext: jest.fn() as jest.Mock, +}; diff --git a/src/core/public/notifications/toasts/toasts_api.test.ts b/src/core/public/notifications/toasts/toasts_api.test.ts index f71ed53481ff5..2d2c403876c78 100644 --- a/src/core/public/notifications/toasts/toasts_api.test.ts +++ b/src/core/public/notifications/toasts/toasts_api.test.ts @@ -23,6 +23,7 @@ import { ToastsApi } from './toasts_api'; import { uiSettingsServiceMock } from '../../ui_settings/ui_settings_service.mock'; import { i18nServiceMock } from '../../i18n/i18n_service.mock'; +import { UiSettingsSetup } from '../../ui_settings'; async function getCurrentToasts(toasts: ToastsApi) { return await toasts @@ -33,7 +34,7 @@ async function getCurrentToasts(toasts: ToastsApi) { function uiSettingsMock() { const mock = uiSettingsServiceMock.createSetupContract(); - (mock.get as jest.Mock).mockImplementation(() => (config: string) => { + (mock.get as jest.Mock).mockImplementation(() => (config: string) => { switch (config) { case 'notifications:lifetime:info': return 5000; 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 c15efe671af3e..406fc65087411 100644 --- a/src/core/public/ui_settings/ui_settings_service.mock.ts +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -42,7 +42,7 @@ const createSetupContractMock = () => { setupContract.getUpdateErrors$.mockReturnValue(new Rx.Subject()); // we have to suppress type errors until decide how to mock es6 class - return (setupContract as unknown) as UiSettingsSetup; + return setupContract; }; type UiSettingsServiceContract = PublicMethodsOf; @@ -53,7 +53,7 @@ const createMock = () => { stop: jest.fn(), }; - mocked.setup.mockReturnValue(createSetupContractMock()); + mocked.setup.mockReturnValue((createSetupContractMock() as unknown) as UiSettingsSetup); return mocked; }; diff --git a/src/core/public/ui_settings/ui_settings_service.ts b/src/core/public/ui_settings/ui_settings_service.ts index 00d1e9ea2cd5f..cabb35ba57924 100644 --- a/src/core/public/ui_settings/ui_settings_service.ts +++ b/src/core/public/ui_settings/ui_settings_service.ts @@ -65,7 +65,7 @@ export class UiSettingsService { } /** @public */ -export type UiSettingsSetup = UiSettingsClient; +export type UiSettingsSetup = PublicMethodsOf; /** @public */ -export type UiSettingsStart = UiSettingsClient; +export type UiSettingsStart = PublicMethodsOf; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 00d09e8873391..885b2b0e46552 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -34,8 +34,8 @@ export interface PluginInitializerContext { env: { mode: EnvironmentMode }; logger: LoggerFactory; config: { - create: () => Observable; - createIfExists: () => Observable; + create: () => Observable; + createIfExists: () => Observable; }; } diff --git a/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts b/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts index f18c02347a2bc..c63ec2cf7a090 100644 --- a/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts +++ b/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts @@ -18,13 +18,13 @@ */ import sinon from 'sinon'; -import { ToastsApi } from '../../../../../core/public'; +import { ToastsApi, UiSettingsSetup } from '../../../../../core/public'; import { uiSettingsServiceMock, i18nServiceMock } from '../../../../../core/public/mocks'; import { ToastNotifications } from './toast_notifications'; function toastDeps() { const uiSettingsMock = uiSettingsServiceMock.createSetupContract(); - (uiSettingsMock.get as jest.Mock).mockImplementation( + (uiSettingsMock.get as jest.Mock).mockImplementation( () => (config: string) => { switch (config) { case 'notifications:lifetime:info': From e9db29f07498e15468022ce44448a140e8323f0d Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 21 Jun 2019 14:17:59 +0200 Subject: [PATCH 03/15] Update api signature/docs --- .../core/public/kibana-plugin-public.uisettingssetup.md | 2 +- .../core/public/kibana-plugin-public.uisettingsstart.md | 2 +- .../kibana-plugin-server.plugininitializercontext.config.md | 4 ++-- .../server/kibana-plugin-server.plugininitializercontext.md | 4 ++-- src/core/public/public.api.md | 4 ++-- src/core/server/server.api.md | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.uisettingssetup.md b/docs/development/core/public/kibana-plugin-public.uisettingssetup.md index ea8e9449fe596..8eb0a5db5fcff 100644 --- a/docs/development/core/public/kibana-plugin-public.uisettingssetup.md +++ b/docs/development/core/public/kibana-plugin-public.uisettingssetup.md @@ -8,5 +8,5 @@ Signature: ```typescript -export declare type UiSettingsSetup = UiSettingsClient; +export declare type UiSettingsSetup = PublicMethodsOf; ``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsstart.md b/docs/development/core/public/kibana-plugin-public.uisettingsstart.md index 00a6a9f75da04..0cd13a4519b95 100644 --- a/docs/development/core/public/kibana-plugin-public.uisettingsstart.md +++ b/docs/development/core/public/kibana-plugin-public.uisettingsstart.md @@ -8,5 +8,5 @@ Signature: ```typescript -export declare type UiSettingsStart = UiSettingsClient; +export declare type UiSettingsStart = PublicMethodsOf; ``` diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md index 7c92784c6c38a..33a26eef8a7cb 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md @@ -8,7 +8,7 @@ ```typescript config: { - create: () => Observable; - createIfExists: () => Observable; + create: () => Observable; + createIfExists: () => Observable; }; ``` diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index eeeccdf56f72b..8eab84e2531d7 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -9,14 +9,14 @@ Context that's available to plugins during initialization stage. Signature: ```typescript -export interface PluginInitializerContext +export interface PluginInitializerContext ``` ## Properties | Property | Type | Description | | --- | --- | --- | -| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
create: <Schema>() => Observable<Schema>;
createIfExists: <Schema>() => Observable<Schema | undefined>;
} | | +| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | | [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index d6086a0e0dbf2..64ec38626019c 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -459,10 +459,10 @@ export class UiSettingsClient { } // @public (undocumented) -export type UiSettingsSetup = UiSettingsClient; +export type UiSettingsSetup = PublicMethodsOf; // @public (undocumented) -export type UiSettingsStart = UiSettingsClient; +export type UiSettingsStart = PublicMethodsOf; // @public (undocumented) export interface UiSettingsState { diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 086d0f4bef1a2..9eccfc6c05baf 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -328,11 +328,11 @@ export interface Plugin = {}, TPluginsStart extends Record = {}> = (core: PluginInitializerContext) => Plugin; // @public -export interface PluginInitializerContext { +export interface PluginInitializerContext { // (undocumented) config: { - create: () => Observable; - createIfExists: () => Observable; + create: () => Observable; + createIfExists: () => Observable; }; // (undocumented) env: { From 0d5fadf65f7564fa949f2757a0307ba9355a7dac Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 21 Jun 2019 15:47:10 +0200 Subject: [PATCH 04/15] Convert embaddable_api tests to new core mocks --- src/core/public/mocks.ts | 1 + .../public/overlays/overlay_service.mock.ts | 4 +++ .../public/np_core.test.mocks.ts | 28 ++++--------------- .../add_panel/add_panel_flyout.test.tsx | 8 ++++-- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index ab1992cc5cf53..dcac271375e44 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -34,6 +34,7 @@ export { injectedMetadataServiceMock } from './injected_metadata/injected_metada export { legacyPlatformServiceMock } from './legacy/legacy_service.mock'; export { notificationServiceMock } from './notifications/notifications_service.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; +export { overlayServiceMock } from './overlays/overlay_service.mock'; function createCoreSetupMock() { const mock: jest.Mocked = { diff --git a/src/core/public/overlays/overlay_service.mock.ts b/src/core/public/overlays/overlay_service.mock.ts index c6989800cbf78..da62d2a42b29a 100644 --- a/src/core/public/overlays/overlay_service.mock.ts +++ b/src/core/public/overlays/overlay_service.mock.ts @@ -23,6 +23,10 @@ const createStartContractMock = () => { openFlyout: jest.fn(), openModal: jest.fn(), }; + startContract.openModal.mockReturnValue({ + close: jest.fn(), + onClose: Promise.resolve(), + }); return startContract; }; diff --git a/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts b/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts index 68ad9a22501da..efabd12731e48 100644 --- a/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts +++ b/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts @@ -17,33 +17,15 @@ * under the License. */ -import { fatalErrorsServiceMock, notificationServiceMock } from '../../../../core/public/mocks'; +import { coreMock } from '../../../../core/public/mocks'; -let modalContents: React.Component; - -export const getModalContents = () => modalContents; +export const coreSetupMock = coreMock.createSetup(); +export const coreStartMock = coreMock.createStart(); jest.doMock('ui/new_platform', () => { return { - npStart: { - core: { - overlays: { - openFlyout: jest.fn(), - openModal: (component: React.Component) => { - modalContents = component; - return { - close: jest.fn(), - }; - }, - }, - }, - }, - npSetup: { - core: { - fatalErrors: fatalErrorsServiceMock.createSetupContract(), - notifications: notificationServiceMock.createSetupContract(), - }, - }, + npStart: { core: coreStartMock }, + npSetup: { core: coreSetupMock }, }; }); diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index 137bf36d0230c..87c2f8834d556 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -16,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import { getModalContents } from '../../../../np_core.test.mocks'; +import '../../../../np_core.test.mocks'; import React from 'react'; import { @@ -36,6 +35,8 @@ import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { skip } from 'rxjs/operators'; import * as Rx from 'rxjs'; import { EmbeddableFactory } from '../../../../embeddables'; +import { coreStartMock } from '../../../../np_core.test.mocks'; +import { OverlayStart } from 'src/core/public'; const onClose = jest.fn(); let container: Container; @@ -79,7 +80,8 @@ test('create new calls factory.adds a panel to the container', async done => { await nextTick(); - (getModalContents().props as ContactCardInitializerProps).onCreate({ + const overlayMock = (coreStartMock.overlays as unknown) as jest.Mocked; + ((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({ firstName: 'Dany', lastName: 'Targaryan', }); From b038601281fcdd3cb6c9565d283718060ebeba8e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 24 Jun 2019 20:06:52 +0200 Subject: [PATCH 05/15] CR Feedback --- src/core/public/mocks.ts | 2 +- .../notifications/toasts/toasts_api.test.ts | 3 +-- .../add_panel/add_panel_flyout.test.tsx | 6 ++--- .../notify/toasts/toast_notifications.test.ts | 26 +++++++++---------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index dcac271375e44..43ce876288a69 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -48,7 +48,7 @@ function createCoreSetupMock() { } function createCoreStartMock() { - const mock: jest.Mocked = { + const mock = { uiSettings: uiSettingsServiceMock.createStartContract(), application: applicationServiceMock.createStartContract(), chrome: chromeServiceMock.createStartContract(), diff --git a/src/core/public/notifications/toasts/toasts_api.test.ts b/src/core/public/notifications/toasts/toasts_api.test.ts index 2d2c403876c78..38e6d2a222990 100644 --- a/src/core/public/notifications/toasts/toasts_api.test.ts +++ b/src/core/public/notifications/toasts/toasts_api.test.ts @@ -23,7 +23,6 @@ import { ToastsApi } from './toasts_api'; import { uiSettingsServiceMock } from '../../ui_settings/ui_settings_service.mock'; import { i18nServiceMock } from '../../i18n/i18n_service.mock'; -import { UiSettingsSetup } from '../../ui_settings'; async function getCurrentToasts(toasts: ToastsApi) { return await toasts @@ -34,7 +33,7 @@ async function getCurrentToasts(toasts: ToastsApi) { function uiSettingsMock() { const mock = uiSettingsServiceMock.createSetupContract(); - (mock.get as jest.Mock).mockImplementation(() => (config: string) => { + mock.get.mockImplementation(() => (config: string) => { switch (config) { case 'notifications:lifetime:info': return 5000; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index 87c2f8834d556..615b4e9635a7b 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import '../../../../np_core.test.mocks'; +import { coreStartMock } from '../../../../np_core.test.mocks'; import React from 'react'; import { @@ -35,8 +35,6 @@ import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { skip } from 'rxjs/operators'; import * as Rx from 'rxjs'; import { EmbeddableFactory } from '../../../../embeddables'; -import { coreStartMock } from '../../../../np_core.test.mocks'; -import { OverlayStart } from 'src/core/public'; const onClose = jest.fn(); let container: Container; @@ -80,7 +78,7 @@ test('create new calls factory.adds a panel to the container', async done => { await nextTick(); - const overlayMock = (coreStartMock.overlays as unknown) as jest.Mocked; + const overlayMock = coreStartMock.overlays; ((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({ firstName: 'Dany', lastName: 'Targaryan', diff --git a/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts b/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts index c63ec2cf7a090..61660812de1b7 100644 --- a/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts +++ b/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts @@ -18,26 +18,24 @@ */ import sinon from 'sinon'; -import { ToastsApi, UiSettingsSetup } from '../../../../../core/public'; +import { ToastsApi } from '../../../../../core/public'; import { uiSettingsServiceMock, i18nServiceMock } from '../../../../../core/public/mocks'; import { ToastNotifications } from './toast_notifications'; function toastDeps() { const uiSettingsMock = uiSettingsServiceMock.createSetupContract(); - (uiSettingsMock.get as jest.Mock).mockImplementation( - () => (config: string) => { - switch (config) { - case 'notifications:lifetime:info': - return 5000; - case 'notifications:lifetime:warning': - return 10000; - case 'notification:lifetime:error': - return 30000; - default: - throw new Error(`Accessing ${config} is not supported in the mock.`); - } + uiSettingsMock.get.mockImplementation(() => (config: string) => { + switch (config) { + case 'notifications:lifetime:info': + return 5000; + case 'notifications:lifetime:warning': + return 10000; + case 'notification:lifetime:error': + return 30000; + default: + throw new Error(`Accessing ${config} is not supported in the mock.`); } - ); + }); return { uiSettings: uiSettingsMock, i18n: i18nServiceMock.createStartContract(), From 358d92871d4a65e2d631750c05eed9e2d0c520a2 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 24 Jun 2019 20:59:36 +0200 Subject: [PATCH 06/15] Introduce ui_new_platform.test.mocks and refactor embedabble tests --- .eslintrc.js | 2 ++ .../public/ui_new_platform.test.mocks.ts} | 10 +------ .../public/actions/action.test.ts | 3 ++- .../actions/apply_filter_action.test.ts | 3 ++- .../public/containers/container.test.ts | 3 ++- .../embeddable_child_panel.test.tsx | 3 ++- .../public/embeddables/embeddable.test.tsx | 3 ++- .../public/get_actions_for_trigger.test.ts | 2 +- .../public/panel/embeddable_panel.test.tsx | 3 ++- .../add_panel/add_panel_action.test.tsx | 3 ++- .../add_panel/add_panel_flyout.test.tsx | 3 ++- .../customize_panel_action.test.ts | 3 ++- .../customize_panel_modal.test.tsx | 3 ++- .../panel_actions/edit_panel_action.test.tsx | 3 ++- .../inspect_panel_action.test.tsx | 3 ++- .../remove_panel_action.test.tsx | 3 ++- .../triggers/execute_trigger_actions.test.ts | 3 ++- .../public/triggers/trigger_registry.test.ts | 3 ++- .../public/ui_capabilities.test.mocks.ts | 26 +++++++++++++++++++ 19 files changed, 60 insertions(+), 25 deletions(-) rename src/{legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts => core/public/ui_new_platform.test.mocks.ts} (85%) create mode 100644 src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts diff --git a/.eslintrc.js b/.eslintrc.js index 079e2908d409c..d80f7437824af 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -140,11 +140,13 @@ module.exports = { 'src/core/public/**/*', '!src/core/public/index.ts', '!src/core/public/mocks.ts', + '!src/core/public/*.test.mocks.ts', '!src/core/public/utils/**/*', 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', + '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', '!src/plugins/**/public/index*', diff --git a/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts b/src/core/public/ui_new_platform.test.mocks.ts similarity index 85% rename from src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts rename to src/core/public/ui_new_platform.test.mocks.ts index efabd12731e48..00bdadeb57266 100644 --- a/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts +++ b/src/core/public/ui_new_platform.test.mocks.ts @@ -17,7 +17,7 @@ * under the License. */ -import { coreMock } from '../../../../core/public/mocks'; +import { coreMock } from './mocks'; export const coreSetupMock = coreMock.createSetup(); export const coreStartMock = coreMock.createStart(); @@ -28,11 +28,3 @@ jest.doMock('ui/new_platform', () => { npSetup: { core: coreSetupMock }, }; }); - -jest.doMock('ui/capabilities', () => ({ - uiCapabilities: { - visualize: { - save: true, - }, - }, -})); diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts index f74318855e2a7..24eb4bef95604 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { HelloWorldAction, SayHelloAction, EmptyEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts index 88f24be36b117..68b1db7c4fa4f 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableEmbeddable, FilterableEmbeddableFactory, diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts index 3ac23902f11e0..d31e3910ab78c 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import * as Rx from 'rxjs'; import { skip } from 'rxjs/operators'; diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx index 7f9a513e3caba..fc225e9af2602 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { ContactCardEmbeddable, ContactCardEmbeddableInput, diff --git a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx index a3fba7694ed62..4909233ba5f00 100644 --- a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx @@ -19,7 +19,8 @@ /* eslint-disable max-classes-per-file */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { skip } from 'rxjs/operators'; import { ContactCardEmbeddable, FilterableEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts index eccde1c3d59a7..da02db702ee74 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import './np_core.test.mocks'; +import './ui_capabilities.test.mocks'; import { HelloWorldAction, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx index 489ee970f9deb..e7359d4e9733a 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx index e08f806f8477f..4ad483be3217f 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../../../../np_core.test.mocks'; +import '../../../../ui_capabilities.test.mocks'; +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index 615b4e9635a7b..eec6a90c792e9 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -16,7 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { coreStartMock } from '../../../../np_core.test.mocks'; +import '../../../../ui_capabilities.test.mocks'; +import { coreStartMock } from '../../../../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; import { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts index 5215f662c6a6a..d2383b3ea3dcb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../../../../np_core.test.mocks'; +import '../../../../ui_capabilities.test.mocks'; +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import { CONTACT_CARD_EMBEDDABLE, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx index 3192c4838a855..c56664fa5c739 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../../../../np_core.test.mocks'; +import '../../../../ui_capabilities.test.mocks'; +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; import { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx index edc3f2190aa68..579acf22221f9 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../../../np_core.test.mocks'; +import '../../../ui_capabilities.test.mocks'; +import '../../../../../../../core/public/ui_new_platform.test.mocks'; import { EmbeddableInput } from '../../../embeddables/i_embeddable'; import { Embeddable } from '../../../embeddables/embeddable'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx index 0a0ba4f08f646..5cdc8ed4e4748 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../../../np_core.test.mocks'; +import '../../../ui_capabilities.test.mocks'; +import '../../../../../../../core/public/ui_new_platform.test.mocks'; jest.mock('ui/inspector', () => ({ Inspector: { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx index f8b7c9ef6fbd3..ddc444fd88bdd 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx @@ -17,7 +17,8 @@ * under the License. */ -import '../../../np_core.test.mocks'; +import '../../../ui_capabilities.test.mocks'; +import '../../../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts index 5a95da378b847..508aab1e37eae 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { EuiContextMenuPanelDescriptor } from '@elastic/eui'; diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts index f2dac33da80b1..dca946d410139 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts @@ -17,7 +17,8 @@ * under the License. */ -import '../np_core.test.mocks'; +import '../ui_capabilities.test.mocks'; +import '../../../../../core/public/ui_new_platform.test.mocks'; import { triggerRegistry } from '../triggers'; import { HELLO_WORLD_ACTION_ID } from '../test_samples'; diff --git a/src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts b/src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts new file mode 100644 index 0000000000000..b7e4a12fac247 --- /dev/null +++ b/src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ + +jest.doMock('ui/capabilities', () => ({ + uiCapabilities: { + visualize: { + save: true, + }, + }, +})); From bcf7630ac87f9106245062f10357536a206af59c Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 24 Jun 2019 21:14:35 +0200 Subject: [PATCH 07/15] Hack to get TS warnings for Core mocks --- src/core/public/mocks.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 43ce876288a69..4d2358339976d 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -37,13 +37,16 @@ export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; export { overlayServiceMock } from './overlays/overlay_service.mock'; function createCoreSetupMock() { - const mock: jest.Mocked = { + const mock = { http: httpServiceMock.createSetupContract(), fatalErrors: fatalErrorsServiceMock.createSetupContract(), notifications: notificationServiceMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), }; + // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreSetup type + ((): CoreSetup => mock)(); + return mock; } @@ -58,6 +61,9 @@ function createCoreStartMock() { overlays: overlayServiceMock.createStartContract(), }; + // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreStart type + ((): CoreStart => mock)(); + return mock; } From 4f5331c769db468fe5edde55e3f8f02d9114a55f Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 24 Jun 2019 21:33:22 +0200 Subject: [PATCH 08/15] Core mocks types cleanup & hack to get TS warnings for Server Core mocks --- src/core/public/mocks.ts | 14 ++++---- .../ui_settings/ui_settings_service.mock.ts | 3 +- src/core/server/mocks.ts | 34 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 72aa22c0f9bfe..0fb304bfd0ec3 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -16,15 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -import { CoreSetup, CoreStart, PluginInitializerContext } from '.'; +import { applicationServiceMock } from './application/application_service.mock'; import { chromeServiceMock } from './chrome/chrome_service.mock'; +import { CoreSetup, CoreStart, PluginInitializerContext } from '.'; +import { docLinksServiceMock } from './doc_links/doc_links_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 { notificationServiceMock } from './notifications/notifications_service.mock'; -import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; -import { applicationServiceMock } from './application/application_service.mock'; import { overlayServiceMock } from './overlays/overlay_service.mock'; +import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; export { chromeServiceMock } from './chrome/chrome_service.mock'; export { docLinksServiceMock } from './doc_links/doc_links_service.mock'; @@ -34,13 +35,13 @@ 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'; export { overlayServiceMock } from './overlays/overlay_service.mock'; +export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; function createCoreSetupMock() { const mock = { - http: httpServiceMock.createSetupContract(), fatalErrors: fatalErrorsServiceMock.createSetupContract(), + http: httpServiceMock.createSetupContract(), notifications: notificationServiceMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), }; @@ -53,13 +54,14 @@ function createCoreSetupMock() { function createCoreStartMock() { const mock = { - uiSettings: uiSettingsServiceMock.createStartContract(), application: applicationServiceMock.createStartContract(), chrome: chromeServiceMock.createStartContract(), + docLinks: docLinksServiceMock.createStartContract(), http: httpServiceMock.createStartContract(), i18n: i18nServiceMock.createStartContract(), notifications: notificationServiceMock.createStartContract(), overlays: overlayServiceMock.createStartContract(), + uiSettings: uiSettingsServiceMock.createStartContract(), }; // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreStart type 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 406fc65087411..bd15b8dde4772 100644 --- a/src/core/public/ui_settings/ui_settings_service.mock.ts +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -41,7 +41,6 @@ const createSetupContractMock = () => { setupContract.getSaved$.mockReturnValue(new Rx.Subject()); setupContract.getUpdateErrors$.mockReturnValue(new Rx.Subject()); - // we have to suppress type errors until decide how to mock es6 class return setupContract; }; @@ -53,7 +52,7 @@ const createMock = () => { stop: jest.fn(), }; - mocked.setup.mockReturnValue((createSetupContractMock() as unknown) as UiSettingsSetup); + mocked.setup.mockReturnValue(createSetupContractMock()); return mocked; }; diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index c77fd0f23e6f9..d95a826f840e7 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -28,17 +28,13 @@ export { httpServiceMock } from './http/http_service.mock'; export { loggingServiceMock } from './logging/logging_service.mock'; export { SavedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; -export function pluginInitializerContextConfigMock(defaultValue: T) { - return (value?: Partial) => { - const config: T = Object.assign({}, defaultValue, value); - - const mock: jest.Mocked['config']> = { - create: jest.fn().mockReturnValue(of(config)), - createIfExists: jest.fn().mockReturnValue(of(config)), - }; - - return mock; +export function pluginInitializerContextConfigMock(config: T) { + const mock: jest.Mocked['config']> = { + create: jest.fn().mockReturnValue(of(config)), + createIfExists: jest.fn().mockReturnValue(of(config)), }; + + return mock; } function pluginInitializerContextMock(config: T) { @@ -51,25 +47,31 @@ function pluginInitializerContextMock(config: T) { prod: false, }, }, - config: pluginInitializerContextConfigMock(config)() as jest.Mocked< - PluginInitializerContext['config'] - >, + config: pluginInitializerContextConfigMock(config), }; - return mock.config; + return mock; } function createCoreSetupMock() { - const mock: jest.Mocked = { + const mock = { elasticsearch: elasticsearchServiceMock.createSetupContract(), http: httpServiceMock.createSetupContract(), }; + // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreSetup type + ((): CoreSetup => mock)(); + return mock; } function createCoreStartMock() { - return {} as jest.Mocked; + const mock = {}; + + // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreStart type + ((): CoreStart => mock)(); + + return mock; } export const coreMock = { From 2d666facc8c87d71ac869adf1269acc75faa457b Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 25 Jun 2019 10:06:34 +0200 Subject: [PATCH 09/15] Use __mocks__ new_platform --- .eslintrc.js | 2 -- src/core/public/ui_new_platform.test.mocks.ts | 30 ------------------- src/dev/jest/setup/mocks.js | 1 + .../public/actions/action.test.ts | 2 +- .../actions/apply_filter_action.test.ts | 2 +- .../public/containers/container.test.ts | 2 +- .../embeddable_child_panel.test.tsx | 2 +- .../public/embeddables/embeddable.test.tsx | 2 +- .../public/get_actions_for_trigger.test.ts | 1 + .../public/panel/embeddable_panel.test.tsx | 2 +- .../add_panel/add_panel_action.test.tsx | 2 +- .../add_panel/add_panel_flyout.test.tsx | 7 +++-- .../customize_panel_action.test.ts | 2 +- .../customize_panel_modal.test.tsx | 2 +- .../panel_actions/edit_panel_action.test.tsx | 2 +- .../inspect_panel_action.test.tsx | 2 +- .../remove_panel_action.test.tsx | 2 +- .../triggers/execute_trigger_actions.test.ts | 2 +- .../public/triggers/trigger_registry.test.ts | 2 +- .../index.ts => __mocks__/new_platform.ts} | 6 +++- .../public/{new_platform => }/new_platform.ts | 2 +- 21 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 src/core/public/ui_new_platform.test.mocks.ts rename src/legacy/ui/public/{new_platform/index.ts => __mocks__/new_platform.ts} (82%) rename src/legacy/ui/public/{new_platform => }/new_platform.ts (95%) diff --git a/.eslintrc.js b/.eslintrc.js index c3cfeb6a384a3..daff238f4f49b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -140,13 +140,11 @@ module.exports = { 'src/core/public/**/*', '!src/core/public/index.ts', '!src/core/public/mocks.ts', - '!src/core/public/*.test.mocks.ts', '!src/core/public/utils/**/*', 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', - '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', '!src/plugins/**/public/index*', diff --git a/src/core/public/ui_new_platform.test.mocks.ts b/src/core/public/ui_new_platform.test.mocks.ts deleted file mode 100644 index 00bdadeb57266..0000000000000 --- a/src/core/public/ui_new_platform.test.mocks.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 { coreMock } from './mocks'; - -export const coreSetupMock = coreMock.createSetup(); -export const coreStartMock = coreMock.createStart(); - -jest.doMock('ui/new_platform', () => { - return { - npStart: { core: coreStartMock }, - npSetup: { core: coreSetupMock }, - }; -}); diff --git a/src/dev/jest/setup/mocks.js b/src/dev/jest/setup/mocks.js index f17c0f44536b6..aa10bfcb5222e 100644 --- a/src/dev/jest/setup/mocks.js +++ b/src/dev/jest/setup/mocks.js @@ -35,6 +35,7 @@ */ jest.mock('ui/metadata'); +jest.mock('ui/new_platform'); jest.mock('ui/documentation_links/documentation_links'); jest.mock('ui/chrome'); diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts index 24eb4bef95604..cd29bc500df62 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { HelloWorldAction, SayHelloAction, EmptyEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts index 68b1db7c4fa4f..f2d1fdcc980d6 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { FilterableEmbeddable, FilterableEmbeddableFactory, diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts index d31e3910ab78c..f7c01acfa930a 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import * as Rx from 'rxjs'; import { skip } from 'rxjs/operators'; diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx index fc225e9af2602..545c2b53a1dcc 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { ContactCardEmbeddable, ContactCardEmbeddableInput, diff --git a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx index 4909233ba5f00..76ca5e1f65458 100644 --- a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx @@ -20,7 +20,7 @@ /* eslint-disable max-classes-per-file */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { skip } from 'rxjs/operators'; import { ContactCardEmbeddable, FilterableEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts index da02db702ee74..aafaaa1e04f5b 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts @@ -18,6 +18,7 @@ */ import './ui_capabilities.test.mocks'; +jest.mock('ui/new_platform'); import { HelloWorldAction, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx index e7359d4e9733a..53d372ff106d3 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import React from 'react'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx index 4ad483be3217f..6e2331ca922e2 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -import '../../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index eec6a90c792e9..3ea8c2b241470 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -17,7 +17,7 @@ * under the License. */ import '../../../../ui_capabilities.test.mocks'; -import { coreStartMock } from '../../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import React from 'react'; import { @@ -36,6 +36,8 @@ import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { skip } from 'rxjs/operators'; import * as Rx from 'rxjs'; import { EmbeddableFactory } from '../../../../embeddables'; +import { OverlayStart } from 'src/core/public'; +import { npStart } from 'ui/new_platform'; const onClose = jest.fn(); let container: Container; @@ -79,7 +81,8 @@ test('create new calls factory.adds a panel to the container', async done => { await nextTick(); - const overlayMock = coreStartMock.overlays; + const overlayMock = npStart.core.overlays as jest.Mocked>; + ((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({ firstName: 'Dany', lastName: 'Targaryan', diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts index d2383b3ea3dcb..8f73a7a2773d0 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -import '../../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { CONTACT_CARD_EMBEDDABLE, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx index c56664fa5c739..2a7da9a7f92a0 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -import '../../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import React from 'react'; import { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx index 579acf22221f9..b8072bd9e330d 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -import '../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { EmbeddableInput } from '../../../embeddables/i_embeddable'; import { Embeddable } from '../../../embeddables/embeddable'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx index 5cdc8ed4e4748..99be725ec27c3 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -import '../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); jest.mock('ui/inspector', () => ({ Inspector: { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx index ddc444fd88bdd..53c6bf59ab9a5 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -import '../../../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts index 508aab1e37eae..2cd9b327bc76d 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { EuiContextMenuPanelDescriptor } from '@elastic/eui'; diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts index dca946d410139..44119e3364bae 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -import '../../../../../core/public/ui_new_platform.test.mocks'; +jest.mock('ui/new_platform'); import { triggerRegistry } from '../triggers'; import { HELLO_WORLD_ACTION_ID } from '../test_samples'; diff --git a/src/legacy/ui/public/new_platform/index.ts b/src/legacy/ui/public/__mocks__/new_platform.ts similarity index 82% rename from src/legacy/ui/public/new_platform/index.ts rename to src/legacy/ui/public/__mocks__/new_platform.ts index ca5890854f3aa..3e2245658148d 100644 --- a/src/legacy/ui/public/new_platform/index.ts +++ b/src/legacy/ui/public/__mocks__/new_platform.ts @@ -16,4 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -export { __setup__, __start__, npSetup, npStart } from './new_platform'; + +import { coreMock } from '../../../../core/public/mocks'; + +export const npStart = { core: coreMock.createStart() }; +export const npSetup = { core: coreMock.createSetup() }; diff --git a/src/legacy/ui/public/new_platform/new_platform.ts b/src/legacy/ui/public/new_platform.ts similarity index 95% rename from src/legacy/ui/public/new_platform/new_platform.ts rename to src/legacy/ui/public/new_platform.ts index 694e92f352015..be4794fdd1f35 100644 --- a/src/legacy/ui/public/new_platform/new_platform.ts +++ b/src/legacy/ui/public/new_platform.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { InternalCoreSetup, InternalCoreStart } from '../../../../core/public'; +import { InternalCoreSetup, InternalCoreStart } from '../../../core/public'; export const npSetup = { core: (null as unknown) as InternalCoreSetup, From a0db51f95ed3febab6f8bd1f418a593a456c799f Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 25 Jun 2019 21:27:36 +0200 Subject: [PATCH 10/15] Remove accidently commited auto-mock --- src/dev/jest/setup/mocks.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dev/jest/setup/mocks.js b/src/dev/jest/setup/mocks.js index aa10bfcb5222e..f17c0f44536b6 100644 --- a/src/dev/jest/setup/mocks.js +++ b/src/dev/jest/setup/mocks.js @@ -35,7 +35,6 @@ */ jest.mock('ui/metadata'); -jest.mock('ui/new_platform'); jest.mock('ui/documentation_links/documentation_links'); jest.mock('ui/chrome'); From 45d08874c5b516e31c259267316713ea8600eefa Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 26 Jun 2019 09:47:06 +0200 Subject: [PATCH 11/15] Introduce MockedKeys type for Core mocks --- src/core/public/mocks.ts | 10 ++-------- src/core/server/mocks.ts | 10 ++-------- typings/index.d.ts | 2 ++ x-pack/typings/index.d.ts | 2 ++ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 0fb304bfd0ec3..b1312eaa228d2 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -39,21 +39,18 @@ export { overlayServiceMock } from './overlays/overlay_service.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; function createCoreSetupMock() { - const mock = { + const mock: MockedKeys = { fatalErrors: fatalErrorsServiceMock.createSetupContract(), http: httpServiceMock.createSetupContract(), notifications: notificationServiceMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), }; - // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreSetup type - ((): CoreSetup => mock)(); - return mock; } function createCoreStartMock() { - const mock = { + const mock: MockedKeys = { application: applicationServiceMock.createStartContract(), chrome: chromeServiceMock.createStartContract(), docLinks: docLinksServiceMock.createStartContract(), @@ -64,9 +61,6 @@ function createCoreStartMock() { uiSettings: uiSettingsServiceMock.createStartContract(), }; - // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreStart type - ((): CoreStart => mock)(); - return mock; } diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index d95a826f840e7..af0eed6ba833d 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -54,22 +54,16 @@ function pluginInitializerContextMock(config: T) { } function createCoreSetupMock() { - const mock = { + const mock: MockedKeys = { elasticsearch: elasticsearchServiceMock.createSetupContract(), http: httpServiceMock.createSetupContract(), }; - // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreSetup type - ((): CoreSetup => mock)(); - return mock; } function createCoreStartMock() { - const mock = {}; - - // This line is a noop but gives TS warnings if our mock doesn't satisfy the CoreStart type - ((): CoreStart => mock)(); + const mock: MockedKeys = {}; return mock; } diff --git a/typings/index.d.ts b/typings/index.d.ts index 42c62edf805ab..02770874b070f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -28,3 +28,5 @@ type MethodKeysOf = { }[keyof T]; type PublicMethodsOf = Pick>; + +type MockedKeys = { [P in keyof T]: jest.Mocked }; diff --git a/x-pack/typings/index.d.ts b/x-pack/typings/index.d.ts index 9486fde759877..181bb8788c469 100644 --- a/x-pack/typings/index.d.ts +++ b/x-pack/typings/index.d.ts @@ -22,3 +22,5 @@ type MethodKeysOf = { type PublicMethodsOf = Pick>; declare module 'axios/lib/adapters/xhr'; + +type MockedKeys = { [P in keyof T]: jest.Mocked }; From c52707e315d4691f983fb45556d1c39ae86fbc6e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 26 Jun 2019 10:47:18 +0200 Subject: [PATCH 12/15] Better typing/docs for UiSettings --- .../public/kibana-plugin-public.coresetup.md | 2 +- ...bana-plugin-public.coresetup.uisettings.md | 4 +- .../public/kibana-plugin-public.corestart.md | 2 +- ...bana-plugin-public.corestart.uisettings.md | 4 +- .../core/public/kibana-plugin-public.md | 3 +- ...a-plugin-public.toastsapi.(constructor).md | 4 +- ...-plugin-public.uisettingsclientcontract.md | 13 +++++++ .../kibana-plugin-public.uisettingssetup.md | 12 ------ .../kibana-plugin-public.uisettingsstart.md | 12 ------ src/core/public/index.ts | 39 +++++++++---------- .../notifications/notifications_service.ts | 4 +- .../notifications/toasts/toasts_api.tsx | 6 +-- .../notifications/toasts/toasts_service.tsx | 4 +- src/core/public/public.api.md | 11 ++---- src/core/public/ui_settings/index.ts | 4 +- .../public/ui_settings/ui_settings_client.ts | 6 +++ .../ui_settings/ui_settings_service.mock.ts | 4 +- .../public/ui_settings/ui_settings_service.ts | 12 ++---- 18 files changed, 65 insertions(+), 81 deletions(-) create mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingssetup.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsstart.md diff --git a/docs/development/core/public/kibana-plugin-public.coresetup.md b/docs/development/core/public/kibana-plugin-public.coresetup.md index 4c0dc2f73f959..5bbd54a2561a3 100644 --- a/docs/development/core/public/kibana-plugin-public.coresetup.md +++ b/docs/development/core/public/kibana-plugin-public.coresetup.md @@ -19,5 +19,5 @@ export interface CoreSetup | [fatalErrors](./kibana-plugin-public.coresetup.fatalerrors.md) | FatalErrorsSetup | [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) | | [http](./kibana-plugin-public.coresetup.http.md) | HttpSetup | [HttpSetup](./kibana-plugin-public.httpsetup.md) | | [notifications](./kibana-plugin-public.coresetup.notifications.md) | NotificationsSetup | [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) | -| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | UiSettingsSetup | [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) | +| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | UiSettingsClientContract | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md b/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md index fae6040b5337f..78a13fccd23ed 100644 --- a/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md +++ b/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md @@ -4,10 +4,10 @@ ## CoreSetup.uiSettings property -[UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) +[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) Signature: ```typescript -uiSettings: UiSettingsSetup; +uiSettings: UiSettingsClientContract; ``` diff --git a/docs/development/core/public/kibana-plugin-public.corestart.md b/docs/development/core/public/kibana-plugin-public.corestart.md index d2134bce0763e..d22bcb09a1054 100644 --- a/docs/development/core/public/kibana-plugin-public.corestart.md +++ b/docs/development/core/public/kibana-plugin-public.corestart.md @@ -23,5 +23,5 @@ export interface CoreStart | [i18n](./kibana-plugin-public.corestart.i18n.md) | I18nStart | [I18nStart](./kibana-plugin-public.i18nstart.md) | | [notifications](./kibana-plugin-public.corestart.notifications.md) | NotificationsStart | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | | [overlays](./kibana-plugin-public.corestart.overlays.md) | OverlayStart | [OverlayStart](./kibana-plugin-public.overlaystart.md) | -| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | UiSettingsStart | [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) | +| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | UiSettingsClientContract | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md b/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md index 7ad3c800a7a1c..1751135e01981 100644 --- a/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md +++ b/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md @@ -4,10 +4,10 @@ ## CoreStart.uiSettings property -[UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) +[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) Signature: ```typescript -uiSettings: UiSettingsStart; +uiSettings: UiSettingsClientContract; ``` diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index 881d83c8ab3f4..99e73ce7ed38f 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -63,6 +63,5 @@ The plugin integrates with the core system via lifecycle events: `setup` | [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The plugin export at the root of a plugin's public directory should conform to this interface. | | [RecursiveReadonly](./kibana-plugin-public.recursivereadonly.md) | | | [ToastInput](./kibana-plugin-public.toastinput.md) | | -| [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) | | -| [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) | | +| [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.toastsapi.(constructor).md b/docs/development/core/public/kibana-plugin-public.toastsapi.(constructor).md index c7d2e8204008e..c883e336a6137 100644 --- a/docs/development/core/public/kibana-plugin-public.toastsapi.(constructor).md +++ b/docs/development/core/public/kibana-plugin-public.toastsapi.(constructor).md @@ -10,7 +10,7 @@ Constructs a new instance of the `ToastsApi` class ```typescript constructor(deps: { - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; }); ``` @@ -18,5 +18,5 @@ constructor(deps: { | Parameter | Type | Description | | --- | --- | --- | -| deps | {
uiSettings: UiSettingsSetup;
} | | +| deps | {
uiSettings: UiSettingsClientContract;
} | | diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md b/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md new file mode 100644 index 0000000000000..6eda1fd3274c6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) + +## UiSettingsClientContract type + +[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) + +Signature: + +```typescript +export declare type UiSettingsClientContract = PublicMethodsOf; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingssetup.md b/docs/development/core/public/kibana-plugin-public.uisettingssetup.md deleted file mode 100644 index 8eb0a5db5fcff..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingssetup.md +++ /dev/null @@ -1,12 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) - -## UiSettingsSetup type - - -Signature: - -```typescript -export declare type UiSettingsSetup = PublicMethodsOf; -``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsstart.md b/docs/development/core/public/kibana-plugin-public.uisettingsstart.md deleted file mode 100644 index 0cd13a4519b95..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsstart.md +++ /dev/null @@ -1,12 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) - -## UiSettingsStart type - - -Signature: - -```typescript -export declare type UiSettingsStart = PublicMethodsOf; -``` diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 807dc9694bc37..2a88ebf86ab0c 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -63,7 +63,7 @@ import { } from './notifications'; import { OverlayRef, OverlayStart } from './overlays'; import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins'; -import { UiSettingsClient, UiSettingsSetup, UiSettingsStart, UiSettingsState } from './ui_settings'; +import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './ui_settings'; import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; @@ -86,8 +86,8 @@ export interface CoreSetup { http: HttpSetup; /** {@link NotificationsSetup} */ notifications: NotificationsSetup; - /** {@link UiSettingsSetup} */ - uiSettings: UiSettingsSetup; + /** {@link UiSettingsClient} */ + uiSettings: UiSettingsClientContract; } /** @@ -114,8 +114,8 @@ export interface CoreStart { notifications: NotificationsStart; /** {@link OverlayStart} */ overlays: OverlayStart; - /** {@link UiSettingsStart} */ - uiSettings: UiSettingsStart; + /** {@link UiSettingsClient} */ + uiSettings: UiSettingsClientContract; } /** @internal */ @@ -133,19 +133,10 @@ export interface InternalCoreStart extends CoreStart { export { ApplicationSetup, ApplicationStart, - DocLinksStart, - HttpServiceBase, - HttpSetup, - HttpStart, - HttpInterceptor, - ErrorToastOptions, - FatalErrorsSetup, - FatalErrorInfo, Capabilities, - ChromeStart, ChromeBadge, - ChromeBreadcrumb, ChromeBrand, + ChromeBreadcrumb, ChromeHelpExtension, ChromeNavControl, ChromeNavControls, @@ -154,20 +145,28 @@ export { ChromeNavLinkUpdateableFields, ChromeRecentlyAccessed, ChromeRecentlyAccessedHistoryItem, + ChromeStart, + DocLinksStart, + ErrorToastOptions, + FatalErrorInfo, + FatalErrorsSetup, + HttpInterceptor, + HttpServiceBase, + HttpSetup, + HttpStart, I18nStart, LegacyNavLink, - Plugin, - PluginInitializer, - PluginInitializerContext, NotificationsSetup, NotificationsStart, OverlayRef, OverlayStart, + Plugin, + PluginInitializer, + PluginInitializerContext, Toast, ToastInput, ToastsApi, UiSettingsClient, + UiSettingsClientContract, UiSettingsState, - UiSettingsSetup, - UiSettingsStart, }; diff --git a/src/core/public/notifications/notifications_service.ts b/src/core/public/notifications/notifications_service.ts index 35ba7d7d4ddae..2dc2b2ef06094 100644 --- a/src/core/public/notifications/notifications_service.ts +++ b/src/core/public/notifications/notifications_service.ts @@ -22,11 +22,11 @@ import { i18n } from '@kbn/i18n'; import { Subscription } from 'rxjs'; import { I18nStart } from '../i18n'; import { ToastsService, ToastsSetup, ToastsStart } from './toasts'; -import { UiSettingsSetup } from '../ui_settings'; +import { UiSettingsClientContract } from '../ui_settings'; import { OverlayStart } from '../overlays'; interface SetupDeps { - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; } interface StartDeps { diff --git a/src/core/public/notifications/toasts/toasts_api.tsx b/src/core/public/notifications/toasts/toasts_api.tsx index 9376c4758d855..6381d50f554c9 100644 --- a/src/core/public/notifications/toasts/toasts_api.tsx +++ b/src/core/public/notifications/toasts/toasts_api.tsx @@ -22,7 +22,7 @@ import React from 'react'; import * as Rx from 'rxjs'; import { ErrorToast } from './error_toast'; -import { UiSettingsSetup } from '../../ui_settings'; +import { UiSettingsClientContract } from '../../ui_settings'; import { OverlayStart } from '../../overlays'; type ToastInputFields = Pick>; @@ -58,11 +58,11 @@ const normalizeToast = (toastOrTitle: ToastInput) => { export class ToastsApi { private toasts$ = new Rx.BehaviorSubject([]); private idCounter = 0; - private uiSettings: UiSettingsSetup; + private uiSettings: UiSettingsClientContract; private overlays?: OverlayStart; - constructor(deps: { uiSettings: UiSettingsSetup }) { + constructor(deps: { uiSettings: UiSettingsClientContract }) { this.uiSettings = deps.uiSettings; } diff --git a/src/core/public/notifications/toasts/toasts_service.tsx b/src/core/public/notifications/toasts/toasts_service.tsx index 2ddaf8dad5f0b..b7ac67a3c19de 100644 --- a/src/core/public/notifications/toasts/toasts_service.tsx +++ b/src/core/public/notifications/toasts/toasts_service.tsx @@ -22,13 +22,13 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { Toast } from '@elastic/eui'; import { I18nStart } from '../../i18n'; -import { UiSettingsSetup } from '../../ui_settings'; +import { UiSettingsClientContract } from '../../ui_settings'; import { GlobalToastList } from './global_toast_list'; import { ToastsApi } from './toasts_api'; import { OverlayStart } from '../../overlays'; interface SetupDeps { - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; } interface StartDeps { diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index f856c63b05c38..0a8c71688f0d1 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -174,7 +174,7 @@ export interface CoreSetup { // (undocumented) notifications: NotificationsSetup; // (undocumented) - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; } // @public @@ -194,7 +194,7 @@ export interface CoreStart { // (undocumented) overlays: OverlayStart; // (undocumented) - uiSettings: UiSettingsStart; + uiSettings: UiSettingsClientContract; } // @internal @@ -503,7 +503,7 @@ export type ToastInput = string | ToastInputFields | Promise; // @public (undocumented) export class ToastsApi { constructor(deps: { - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; }); // (undocumented) add(toastOrTitle: ToastInput): Toast; @@ -552,10 +552,7 @@ export class UiSettingsClient { } // @public (undocumented) -export type UiSettingsSetup = PublicMethodsOf; - -// @public (undocumented) -export type UiSettingsStart = PublicMethodsOf; +export type UiSettingsClientContract = PublicMethodsOf; // @public (undocumented) export interface UiSettingsState { diff --git a/src/core/public/ui_settings/index.ts b/src/core/public/ui_settings/index.ts index 7ec0014ebcfd9..7f10cfb1539d7 100644 --- a/src/core/public/ui_settings/index.ts +++ b/src/core/public/ui_settings/index.ts @@ -17,6 +17,6 @@ * under the License. */ -export { UiSettingsService, UiSettingsSetup, UiSettingsStart } from './ui_settings_service'; -export { UiSettingsClient } from './ui_settings_client'; +export { UiSettingsService } from './ui_settings_service'; +export { UiSettingsClient, UiSettingsClientContract } from './ui_settings_client'; export { UiSettingsState } from './types'; diff --git a/src/core/public/ui_settings/ui_settings_client.ts b/src/core/public/ui_settings/ui_settings_client.ts index 9207109d1ce0b..3083851dd453d 100644 --- a/src/core/public/ui_settings/ui_settings_client.ts +++ b/src/core/public/ui_settings/ui_settings_client.ts @@ -31,6 +31,12 @@ interface UiSettingsClientParams { initialSettings?: UiSettingsState; } +/** + * {@link UiSettingsClient} + * @public + */ +export type UiSettingsClientContract = PublicMethodsOf; + /** @public */ export class UiSettingsClient { private readonly update$ = new Rx.Subject<{ key: string; newValue: any; oldValue: any }>(); 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 bd15b8dde4772..2ec6175ff67d5 100644 --- a/src/core/public/ui_settings/ui_settings_service.mock.ts +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -17,10 +17,10 @@ * under the License. */ import * as Rx from 'rxjs'; -import { UiSettingsService, UiSettingsSetup } from './ui_settings_service'; +import { UiSettingsService, UiSettingsClientContract } from './'; const createSetupContractMock = () => { - const setupContract: jest.Mocked> = { + const setupContract: jest.Mocked = { getAll: jest.fn(), get: jest.fn(), get$: jest.fn(), diff --git a/src/core/public/ui_settings/ui_settings_service.ts b/src/core/public/ui_settings/ui_settings_service.ts index cabb35ba57924..8678a1cf7003d 100644 --- a/src/core/public/ui_settings/ui_settings_service.ts +++ b/src/core/public/ui_settings/ui_settings_service.ts @@ -21,7 +21,7 @@ import { HttpSetup } from '../http'; import { InjectedMetadataSetup } from '../injected_metadata'; import { UiSettingsApi } from './ui_settings_api'; -import { UiSettingsClient } from './ui_settings_client'; +import { UiSettingsClient, UiSettingsClientContract } from './ui_settings_client'; interface UiSettingsServiceDeps { http: HttpSetup; @@ -33,7 +33,7 @@ export class UiSettingsService { private uiSettingsApi?: UiSettingsApi; private uiSettingsClient?: UiSettingsClient; - public setup({ http, injectedMetadata }: UiSettingsServiceDeps): UiSettingsSetup { + public setup({ http, injectedMetadata }: UiSettingsServiceDeps): UiSettingsClientContract { this.uiSettingsApi = new UiSettingsApi(http); http.addLoadingCount(this.uiSettingsApi.getLoadingCount$()); @@ -49,7 +49,7 @@ export class UiSettingsService { return this.uiSettingsClient; } - public start(): UiSettingsStart { + public start(): UiSettingsClient { return this.uiSettingsClient!; } @@ -63,9 +63,3 @@ export class UiSettingsService { } } } - -/** @public */ -export type UiSettingsSetup = PublicMethodsOf; - -/** @public */ -export type UiSettingsStart = PublicMethodsOf; From 878c46ae14396a567d13881b2b33b3caac7e3ec5 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 27 Jun 2019 09:00:03 +0200 Subject: [PATCH 13/15] Revert "Use __mocks__ new_platform" This reverts commit 2d666facc8c87d71ac869adf1269acc75faa457b. --- .eslintrc.js | 2 ++ src/core/public/ui_new_platform.test.mocks.ts | 30 +++++++++++++++++++ .../public/actions/action.test.ts | 2 +- .../actions/apply_filter_action.test.ts | 2 +- .../public/containers/container.test.ts | 2 +- .../embeddable_child_panel.test.tsx | 2 +- .../public/embeddables/embeddable.test.tsx | 2 +- .../public/get_actions_for_trigger.test.ts | 1 - .../public/panel/embeddable_panel.test.tsx | 2 +- .../add_panel/add_panel_action.test.tsx | 2 +- .../add_panel/add_panel_flyout.test.tsx | 7 ++--- .../customize_panel_action.test.ts | 2 +- .../customize_panel_modal.test.tsx | 2 +- .../panel_actions/edit_panel_action.test.tsx | 2 +- .../inspect_panel_action.test.tsx | 2 +- .../remove_panel_action.test.tsx | 2 +- .../triggers/execute_trigger_actions.test.ts | 2 +- .../public/triggers/trigger_registry.test.ts | 2 +- .../new_platform.ts => new_platform/index.ts} | 6 +--- .../public/{ => new_platform}/new_platform.ts | 2 +- 20 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 src/core/public/ui_new_platform.test.mocks.ts rename src/legacy/ui/public/{__mocks__/new_platform.ts => new_platform/index.ts} (82%) rename src/legacy/ui/public/{ => new_platform}/new_platform.ts (95%) diff --git a/.eslintrc.js b/.eslintrc.js index daff238f4f49b..c3cfeb6a384a3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -140,11 +140,13 @@ module.exports = { 'src/core/public/**/*', '!src/core/public/index.ts', '!src/core/public/mocks.ts', + '!src/core/public/*.test.mocks.ts', '!src/core/public/utils/**/*', 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', + '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', '!src/plugins/**/public/index*', diff --git a/src/core/public/ui_new_platform.test.mocks.ts b/src/core/public/ui_new_platform.test.mocks.ts new file mode 100644 index 0000000000000..00bdadeb57266 --- /dev/null +++ b/src/core/public/ui_new_platform.test.mocks.ts @@ -0,0 +1,30 @@ +/* + * 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 { coreMock } from './mocks'; + +export const coreSetupMock = coreMock.createSetup(); +export const coreStartMock = coreMock.createStart(); + +jest.doMock('ui/new_platform', () => { + return { + npStart: { core: coreStartMock }, + npSetup: { core: coreSetupMock }, + }; +}); diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts index cd29bc500df62..24eb4bef95604 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/action.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { HelloWorldAction, SayHelloAction, EmptyEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts index f2d1fdcc980d6..68b1db7c4fa4f 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableEmbeddable, FilterableEmbeddableFactory, diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts index f7c01acfa930a..d31e3910ab78c 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import * as Rx from 'rxjs'; import { skip } from 'rxjs/operators'; diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx index 545c2b53a1dcc..fc225e9af2602 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/containers/embeddable_child_panel.test.tsx @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { ContactCardEmbeddable, ContactCardEmbeddableInput, diff --git a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx index 76ca5e1f65458..4909233ba5f00 100644 --- a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable.test.tsx @@ -20,7 +20,7 @@ /* eslint-disable max-classes-per-file */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { skip } from 'rxjs/operators'; import { ContactCardEmbeddable, FilterableEmbeddable } from '../test_samples/index'; diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts index aafaaa1e04f5b..da02db702ee74 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts @@ -18,7 +18,6 @@ */ import './ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); import { HelloWorldAction, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx index 53d372ff106d3..e7359d4e9733a 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx index 6e2331ca922e2..4ad483be3217f 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index 3ea8c2b241470..eec6a90c792e9 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -17,7 +17,7 @@ * under the License. */ import '../../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import { coreStartMock } from '../../../../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; import { @@ -36,8 +36,6 @@ import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { skip } from 'rxjs/operators'; import * as Rx from 'rxjs'; import { EmbeddableFactory } from '../../../../embeddables'; -import { OverlayStart } from 'src/core/public'; -import { npStart } from 'ui/new_platform'; const onClose = jest.fn(); let container: Container; @@ -81,8 +79,7 @@ test('create new calls factory.adds a panel to the container', async done => { await nextTick(); - const overlayMock = npStart.core.overlays as jest.Mocked>; - + const overlayMock = coreStartMock.overlays; ((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({ firstName: 'Dany', lastName: 'Targaryan', diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts index 8f73a7a2773d0..d2383b3ea3dcb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import { CONTACT_CARD_EMBEDDABLE, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx index 2a7da9a7f92a0..c56664fa5c739 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx @@ -18,7 +18,7 @@ */ import '../../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../../core/public/ui_new_platform.test.mocks'; import React from 'react'; import { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx index b8072bd9e330d..579acf22221f9 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/edit_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../core/public/ui_new_platform.test.mocks'; import { EmbeddableInput } from '../../../embeddables/i_embeddable'; import { Embeddable } from '../../../embeddables/embeddable'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx index 99be725ec27c3..5cdc8ed4e4748 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../core/public/ui_new_platform.test.mocks'; jest.mock('ui/inspector', () => ({ Inspector: { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx index 53c6bf59ab9a5..ddc444fd88bdd 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx @@ -18,7 +18,7 @@ */ import '../../../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../../../core/public/ui_new_platform.test.mocks'; import { FilterableContainer, diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts index 2cd9b327bc76d..508aab1e37eae 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { EuiContextMenuPanelDescriptor } from '@elastic/eui'; diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts index 44119e3364bae..dca946d410139 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts @@ -18,7 +18,7 @@ */ import '../ui_capabilities.test.mocks'; -jest.mock('ui/new_platform'); +import '../../../../../core/public/ui_new_platform.test.mocks'; import { triggerRegistry } from '../triggers'; import { HELLO_WORLD_ACTION_ID } from '../test_samples'; diff --git a/src/legacy/ui/public/__mocks__/new_platform.ts b/src/legacy/ui/public/new_platform/index.ts similarity index 82% rename from src/legacy/ui/public/__mocks__/new_platform.ts rename to src/legacy/ui/public/new_platform/index.ts index 3e2245658148d..ca5890854f3aa 100644 --- a/src/legacy/ui/public/__mocks__/new_platform.ts +++ b/src/legacy/ui/public/new_platform/index.ts @@ -16,8 +16,4 @@ * specific language governing permissions and limitations * under the License. */ - -import { coreMock } from '../../../../core/public/mocks'; - -export const npStart = { core: coreMock.createStart() }; -export const npSetup = { core: coreMock.createSetup() }; +export { __setup__, __start__, npSetup, npStart } from './new_platform'; diff --git a/src/legacy/ui/public/new_platform.ts b/src/legacy/ui/public/new_platform/new_platform.ts similarity index 95% rename from src/legacy/ui/public/new_platform.ts rename to src/legacy/ui/public/new_platform/new_platform.ts index be4794fdd1f35..694e92f352015 100644 --- a/src/legacy/ui/public/new_platform.ts +++ b/src/legacy/ui/public/new_platform/new_platform.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { InternalCoreSetup, InternalCoreStart } from '../../../core/public'; +import { InternalCoreSetup, InternalCoreStart } from '../../../../core/public'; export const npSetup = { core: (null as unknown) as InternalCoreSetup, From f6fd9d1a5e142d9fecc1e1f4dd440d7fe168f257 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 27 Jun 2019 09:42:24 +0200 Subject: [PATCH 14/15] Add missing mock to test --- .../embeddable_api/public/get_actions_for_trigger.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts index da02db702ee74..dde4cc96a5deb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts @@ -18,6 +18,7 @@ */ import './ui_capabilities.test.mocks'; +import '../../../../core/public/ui_new_platform.test.mocks'; import { HelloWorldAction, From 49aa1b599978735c2a4ba38ad35048ee159643b7 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 27 Jun 2019 11:21:43 +0200 Subject: [PATCH 15/15] Cleanup UiSettings types --- src/core/public/plugins/plugins_service.test.ts | 5 ++--- src/core/public/ui_settings/ui_settings_service.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/public/plugins/plugins_service.test.ts b/src/core/public/plugins/plugins_service.test.ts index 99e28f5ec36f2..55e91bde27cb0 100644 --- a/src/core/public/plugins/plugins_service.test.ts +++ b/src/core/public/plugins/plugins_service.test.ts @@ -41,7 +41,6 @@ import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.moc import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock'; import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock'; import { httpServiceMock } from '../http/http_service.mock'; -import { UiSettingsClient } from '../ui_settings'; import { CoreSetup, CoreStart } from '..'; import { docLinksServiceMock } from '../doc_links/doc_links_service.mock'; @@ -77,7 +76,7 @@ beforeEach(() => { fatalErrors: fatalErrorsServiceMock.createSetupContract(), http: httpServiceMock.createSetupContract(), notifications: notificationServiceMock.createSetupContract(), - uiSettings: uiSettingsServiceMock.createSetupContract() as jest.Mocked, + uiSettings: uiSettingsServiceMock.createSetupContract(), }; mockSetupContext = omit(mockSetupDeps, 'application', 'injectedMetadata'); mockStartDeps = { @@ -89,7 +88,7 @@ beforeEach(() => { injectedMetadata: injectedMetadataServiceMock.createStartContract(), notifications: notificationServiceMock.createStartContract(), overlays: overlayServiceMock.createStartContract(), - uiSettings: uiSettingsServiceMock.createStartContract() as jest.Mocked, + uiSettings: uiSettingsServiceMock.createStartContract(), }; mockStartContext = { ...omit(mockStartDeps, 'injectedMetadata'), diff --git a/src/core/public/ui_settings/ui_settings_service.ts b/src/core/public/ui_settings/ui_settings_service.ts index 8678a1cf7003d..2efb0884312d8 100644 --- a/src/core/public/ui_settings/ui_settings_service.ts +++ b/src/core/public/ui_settings/ui_settings_service.ts @@ -49,7 +49,7 @@ export class UiSettingsService { return this.uiSettingsClient; } - public start(): UiSettingsClient { + public start(): UiSettingsClientContract { return this.uiSettingsClient!; }