From 0d5fadf65f7564fa949f2757a0307ba9355a7dac Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 21 Jun 2019 15:47:10 +0200 Subject: [PATCH] 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', });