Skip to content

Commit

Permalink
Convert embaddable_api tests to new core mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Jun 24, 2019
1 parent e9db29f commit 0d5fadf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreSetup> = {
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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<OverlayStart>;
((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({
firstName: 'Dany',
lastName: 'Targaryan',
});
Expand Down

0 comments on commit 0d5fadf

Please sign in to comment.