Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocks for CoreStart, CoreSetup and PluginInitializerContext #39351

Merged
merged 18 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface CoreSetup
| [fatalErrors](./kibana-plugin-public.coresetup.fatalerrors.md) | <code>FatalErrorsSetup</code> | [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) |
| [http](./kibana-plugin-public.coresetup.http.md) | <code>HttpSetup</code> | [HttpSetup](./kibana-plugin-public.httpsetup.md) |
| [notifications](./kibana-plugin-public.coresetup.notifications.md) | <code>NotificationsSetup</code> | [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) |
| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | <code>UiSettingsSetup</code> | [UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md) |
| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | <code>UiSettingsClientContract</code> | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) |

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## CoreSetup.uiSettings property

[UiSettingsSetup](./kibana-plugin-public.uisettingssetup.md)
[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md)

<b>Signature:</b>

```typescript
uiSettings: UiSettingsSetup;
uiSettings: UiSettingsClientContract;
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export interface CoreStart
| [i18n](./kibana-plugin-public.corestart.i18n.md) | <code>I18nStart</code> | [I18nStart](./kibana-plugin-public.i18nstart.md) |
| [notifications](./kibana-plugin-public.corestart.notifications.md) | <code>NotificationsStart</code> | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) |
| [overlays](./kibana-plugin-public.corestart.overlays.md) | <code>OverlayStart</code> | [OverlayStart](./kibana-plugin-public.overlaystart.md) |
| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | <code>UiSettingsStart</code> | [UiSettingsStart](./kibana-plugin-public.uisettingsstart.md) |
| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | <code>UiSettingsClientContract</code> | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) |

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## CoreStart.uiSettings property

[UiSettingsStart](./kibana-plugin-public.uisettingsstart.md)
[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md)

<b>Signature:</b>

```typescript
uiSettings: UiSettingsStart;
uiSettings: UiSettingsClientContract;
```
3 changes: 1 addition & 2 deletions docs/development/core/public/kibana-plugin-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The <code>plugin</code> export at the root of a plugin's <code>public</code> 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) |

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Constructs a new instance of the `ToastsApi` class

```typescript
constructor(deps: {
uiSettings: UiSettingsSetup;
uiSettings: UiSettingsClientContract;
});
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| deps | <code>{</code><br/><code> uiSettings: UiSettingsSetup;</code><br/><code> }</code> | |
| deps | <code>{</code><br/><code> uiSettings: UiSettingsClientContract;</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md)

## UiSettingsClientContract type

[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md)

<b>Signature:</b>

```typescript
export declare type UiSettingsClientContract = PublicMethodsOf<UiSettingsClient>;
```

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```typescript
config: {
create: <Schema>() => Observable<Schema>;
createIfExists: <Schema>() => Observable<Schema | undefined>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Context that's available to plugins during initialization stage.
<b>Signature:</b>

```typescript
export interface PluginInitializerContext
export interface PluginInitializerContext<ConfigSchema = unknown>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [config](./kibana-plugin-server.plugininitializercontext.config.md) | <code>{</code><br/><code> create: &lt;Schema&gt;() =&gt; Observable&lt;Schema&gt;;</code><br/><code> createIfExists: &lt;Schema&gt;() =&gt; Observable&lt;Schema &#124; undefined&gt;;</code><br/><code> }</code> | |
| [config](./kibana-plugin-server.plugininitializercontext.config.md) | <code>{</code><br/><code> create: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T&gt;;</code><br/><code> createIfExists: &lt;T = ConfigSchema&gt;() =&gt; Observable&lt;T &#124; undefined&gt;;</code><br/><code> }</code> | |
| [env](./kibana-plugin-server.plugininitializercontext.env.md) | <code>{</code><br/><code> mode: EnvironmentMode;</code><br/><code> }</code> | |
| [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | <code>LoggerFactory</code> | |

39 changes: 19 additions & 20 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -86,8 +86,8 @@ export interface CoreSetup {
http: HttpSetup;
/** {@link NotificationsSetup} */
notifications: NotificationsSetup;
/** {@link UiSettingsSetup} */
uiSettings: UiSettingsSetup;
/** {@link UiSettingsClient} */
uiSettings: UiSettingsClientContract;
}

/**
Expand All @@ -114,8 +114,8 @@ export interface CoreStart {
notifications: NotificationsStart;
/** {@link OverlayStart} */
overlays: OverlayStart;
/** {@link UiSettingsStart} */
uiSettings: UiSettingsStart;
/** {@link UiSettingsClient} */
uiSettings: UiSettingsClientContract;
}

/** @internal */
Expand All @@ -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,
Expand All @@ -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,
};
43 changes: 43 additions & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<CoreSetup> = {
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
http: httpServiceMock.createSetupContract(),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
};

return mock;
}

function createCoreStartMock() {
const mock: MockedKeys<CoreStart> = {
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<PluginInitializerContext>,
};
4 changes: 2 additions & 2 deletions src/core/public/notifications/notifications_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/notifications/toasts/toasts_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function getCurrentToasts(toasts: ToastsApi) {

function uiSettingsMock() {
const mock = uiSettingsServiceMock.createSetupContract();
(mock.get as jest.Mock<typeof mock['get']>).mockImplementation(() => (config: string) => {
mock.get.mockImplementation(() => (config: string) => {
switch (config) {
case 'notifications:lifetime:info':
return 5000;
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/notifications/toasts/toasts_api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Toast, Exclude<keyof Toast, 'id'>>;
Expand Down Expand Up @@ -58,11 +58,11 @@ const normalizeToast = (toastOrTitle: ToastInput) => {
export class ToastsApi {
private toasts$ = new Rx.BehaviorSubject<Toast[]>([]);
private idCounter = 0;
private uiSettings: UiSettingsSetup;
private uiSettings: UiSettingsClientContract;

private overlays?: OverlayStart;

constructor(deps: { uiSettings: UiSettingsSetup }) {
constructor(deps: { uiSettings: UiSettingsClientContract }) {
this.uiSettings = deps.uiSettings;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/public/notifications/toasts/toasts_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/core/public/overlays/overlay_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const createStartContractMock = () => {
openFlyout: jest.fn(),
openModal: jest.fn(),
};
startContract.openModal.mockReturnValue({
close: jest.fn(),
onClose: Promise.resolve(),
});
return startContract;
};

Expand Down
5 changes: 2 additions & 3 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -77,7 +76,7 @@ beforeEach(() => {
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
http: httpServiceMock.createSetupContract(),
notifications: notificationServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract() as jest.Mocked<UiSettingsClient>,
uiSettings: uiSettingsServiceMock.createSetupContract(),
};
mockSetupContext = omit(mockSetupDeps, 'application', 'injectedMetadata');
mockStartDeps = {
Expand All @@ -89,7 +88,7 @@ beforeEach(() => {
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
overlays: overlayServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract() as jest.Mocked<UiSettingsClient>,
uiSettings: uiSettingsServiceMock.createStartContract(),
};
mockStartContext = {
...omit(mockStartDeps, 'injectedMetadata'),
Expand Down
Loading