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/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 455372f77a8dd..98b6a8703f543 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 ea8e9449fe596..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 = UiSettingsClient; -``` 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 00a6a9f75da04..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 = UiSettingsClient; -``` 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/index.ts b/src/core/public/index.ts index ae741be3b8fef..3ffcf309767e5 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'; @@ -87,8 +87,8 @@ export interface CoreSetup { http: HttpSetup; /** {@link NotificationsSetup} */ notifications: NotificationsSetup; - /** {@link UiSettingsSetup} */ - uiSettings: UiSettingsSetup; + /** {@link UiSettingsClient} */ + uiSettings: UiSettingsClientContract; } /** @@ -115,8 +115,8 @@ export interface CoreStart { notifications: NotificationsStart; /** {@link OverlayStart} */ overlays: OverlayStart; - /** {@link UiSettingsStart} */ - uiSettings: UiSettingsStart; + /** {@link UiSettingsClient} */ + uiSettings: UiSettingsClientContract; } /** @internal */ @@ -134,19 +134,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, @@ -155,20 +146,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/mocks.ts b/src/core/public/mocks.ts index c0b12c9b1ec95..b1312eaa228d2 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -16,6 +16,16 @@ * specific language governing permissions and limitations * under the License. */ +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 { 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'; @@ -25,4 +35,37 @@ 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 { overlayServiceMock } from './overlays/overlay_service.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; + +function createCoreSetupMock() { + const mock: MockedKeys = { + fatalErrors: fatalErrorsServiceMock.createSetupContract(), + http: httpServiceMock.createSetupContract(), + notifications: notificationServiceMock.createSetupContract(), + uiSettings: uiSettingsServiceMock.createSetupContract(), + }; + + return mock; +} + +function createCoreStartMock() { + const mock: MockedKeys = { + application: applicationServiceMock.createStartContract(), + chrome: chromeServiceMock.createStartContract(), + docLinks: docLinksServiceMock.createStartContract(), + http: httpServiceMock.createStartContract(), + i18n: i18nServiceMock.createStartContract(), + notifications: notificationServiceMock.createStartContract(), + overlays: overlayServiceMock.createStartContract(), + uiSettings: uiSettingsServiceMock.createStartContract(), + }; + + return mock; +} + +export const coreMock = { + createSetup: createCoreSetupMock, + createStart: createCoreStartMock, + createPluginInitializerContext: jest.fn() as jest.Mock, +}; 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.test.ts b/src/core/public/notifications/toasts/toasts_api.test.ts index f71ed53481ff5..38e6d2a222990 100644 --- a/src/core/public/notifications/toasts/toasts_api.test.ts +++ b/src/core/public/notifications/toasts/toasts_api.test.ts @@ -33,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/core/public/notifications/toasts/toasts_api.tsx b/src/core/public/notifications/toasts/toasts_api.tsx index 8c8e567638f78..9ecbc87f15b45 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 75d80d6e353d8..022d57d155b6b 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 { EuiGlobalToastListToast as 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/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/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/public.api.md b/src/core/public/public.api.md index d9ae4614f8c87..d6354d5c09c61 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -179,7 +179,7 @@ export interface CoreSetup { // (undocumented) notifications: NotificationsSetup; // (undocumented) - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; } // @public @@ -199,7 +199,7 @@ export interface CoreStart { // (undocumented) overlays: OverlayStart; // (undocumented) - uiSettings: UiSettingsStart; + uiSettings: UiSettingsClientContract; } // @internal @@ -508,7 +508,7 @@ export type ToastInput = string | ToastInputFields | Promise; // @public (undocumented) export class ToastsApi { constructor(deps: { - uiSettings: UiSettingsSetup; + uiSettings: UiSettingsClientContract; }); // (undocumented) add(toastOrTitle: ToastInput): Toast; @@ -557,10 +557,7 @@ export class UiSettingsClient { } // @public (undocumented) -export type UiSettingsSetup = UiSettingsClient; - -// @public (undocumented) -export type UiSettingsStart = UiSettingsClient; +export type UiSettingsClientContract = PublicMethodsOf; // @public (undocumented) export interface UiSettingsState { 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/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 c15efe671af3e..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(), @@ -41,8 +41,7 @@ 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 as unknown) as UiSettingsSetup; + return setupContract; }; type UiSettingsServiceContract = PublicMethodsOf; diff --git a/src/core/public/ui_settings/ui_settings_service.ts b/src/core/public/ui_settings/ui_settings_service.ts index 00d1e9ea2cd5f..2efb0884312d8 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(): UiSettingsClientContract { return this.uiSettingsClient!; } @@ -63,9 +63,3 @@ export class UiSettingsService { } } } - -/** @public */ -export type UiSettingsSetup = UiSettingsClient; - -/** @public */ -export type UiSettingsStart = UiSettingsClient; 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..af0eed6ba833d 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -16,9 +16,60 @@ * 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(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) { + const mock: jest.Mocked> = { + logger: loggingServiceMock.create(), + env: { + mode: { + dev: true, + name: 'development', + prod: false, + }, + }, + config: pluginInitializerContextConfigMock(config), + }; + + return mock; +} + +function createCoreSetupMock() { + const mock: MockedKeys = { + elasticsearch: elasticsearchServiceMock.createSetupContract(), + http: httpServiceMock.createSetupContract(), + }; + + return mock; +} + +function createCoreStartMock() { + const mock: MockedKeys = {}; + + return mock; +} + +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..885b2b0e46552 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; }; } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index a1c8d4a8e2b51..7aa793764cabc 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -326,11 +326,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: { 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..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 @@ -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, 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 137bf36d0230c..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,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ - -import { getModalContents } 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 { @@ -79,7 +79,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; + ((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 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/np_core.test.mocks.ts b/src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts similarity index 56% rename from src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts rename to src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts index 68ad9a22501da..b7e4a12fac247 100644 --- a/src/legacy/core_plugins/embeddable_api/public/np_core.test.mocks.ts +++ b/src/legacy/core_plugins/embeddable_api/public/ui_capabilities.test.mocks.ts @@ -17,36 +17,6 @@ * under the License. */ -import { fatalErrorsServiceMock, notificationServiceMock } from '../../../../core/public/mocks'; - -let modalContents: React.Component; - -export const getModalContents = () => modalContents; - -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(), - }, - }, - }; -}); - jest.doMock('ui/capabilities', () => ({ uiCapabilities: { visualize: { 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..61660812de1b7 100644 --- a/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts +++ b/src/legacy/ui/public/notify/toasts/toast_notifications.test.ts @@ -24,20 +24,18 @@ 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(), 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 };