mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Plugin mocks (#40123) * test: 💍 add ability to mock plugins in ui/new_platform * chore: 🤖 delete olds NP backdoor mock * test: 💍 normalize plugin contract naming in line with Core * test: 💍 use mock from ui/new_platform instead of core * test: 💍 remove ui/new_platform mocking from Core * chore: 🤖 leave only one mocking strategy for ui/new_platform * style: 💄 format according to Prettier * chore: 🤖 remove /src/plugins/__mocks__ folder * fix: 🐛 move mock to correct folder * test: 💍 fix test mock
This commit is contained in:
parent
9ed0b2fa76
commit
76572d426a
29 changed files with 141 additions and 41 deletions
|
@ -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';
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import '../ui_capabilities.test.mocks';
|
||||
import '../../../../../core/public/ui_new_platform.test.mocks';
|
||||
|
||||
import * as Rx from 'rxjs';
|
||||
import { skip } from 'rxjs/operators';
|
||||
|
@ -46,6 +45,8 @@ import {
|
|||
import { ERROR_EMBEDDABLE_TYPE } from '../embeddables/error_embeddable';
|
||||
import { PanelNotFoundError } from './panel_not_found_error';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
const embeddableFactories = new Map<string, EmbeddableFactory>();
|
||||
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());
|
||||
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new SlowContactCardEmbeddableFactory());
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import '../ui_capabilities.test.mocks';
|
||||
import '../../../../../core/public/ui_new_platform.test.mocks';
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
import { skip } from 'rxjs/operators';
|
||||
import {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import './ui_capabilities.test.mocks';
|
||||
import '../../../../core/public/ui_new_platform.test.mocks';
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
import {
|
||||
HelloWorldAction,
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import '../ui_capabilities.test.mocks';
|
||||
import '../../../../../core/public/ui_new_platform.test.mocks';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
@ -48,6 +47,8 @@ import { CONTEXT_MENU_TRIGGER } from '../triggers';
|
|||
import { attachAction } from '../triggers/attach_action';
|
||||
import { EmbeddableFactory } from '../embeddables';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
const editModeAction = new EditModeAction();
|
||||
actionRegistry.set(editModeAction.id, editModeAction);
|
||||
attachAction(triggerRegistry, {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import '../../../../ui_capabilities.test.mocks';
|
||||
import '../../../../../../../../core/public/ui_new_platform.test.mocks';
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
import {
|
||||
FilterableContainer,
|
||||
|
|
|
@ -17,7 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
import '../../../../ui_capabilities.test.mocks';
|
||||
import { coreStartMock } from '../../../../../../../../core/public/ui_new_platform.test.mocks';
|
||||
import { npStart } from 'ui/new_platform';
|
||||
|
||||
jest.mock('ui/new_platform', () =>
|
||||
require('ui/new_platform/__mocks__/helpers').createUiNewPlatformMock()
|
||||
);
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
|
@ -79,8 +83,8 @@ test('create new calls factory.adds a panel to the container', async done => {
|
|||
|
||||
await nextTick();
|
||||
|
||||
const overlayMock = coreStartMock.overlays;
|
||||
((overlayMock.openModal.mock.calls[0][0] as any).props as ContactCardInitializerProps).onCreate({
|
||||
const overlayMock = npStart.core.overlays;
|
||||
((overlayMock.openModal as any).mock.calls[0][0].props as ContactCardInitializerProps).onCreate({
|
||||
firstName: 'Dany',
|
||||
lastName: 'Targaryan',
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import '../../../../ui_capabilities.test.mocks';
|
||||
import '../../../../../../../../core/public/ui_new_platform.test.mocks';
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
|
@ -37,6 +36,8 @@ import { Container, isErrorEmbeddable } from '../../../..';
|
|||
import { mountWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { EmbeddableFactory } from '../../../../embeddables';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
let container: Container;
|
||||
let embeddable: ContactCardEmbeddable;
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import '../../../ui_capabilities.test.mocks';
|
||||
import '../../../../../../../core/public/ui_new_platform.test.mocks';
|
||||
|
||||
jest.mock('ui/inspector', () => ({
|
||||
Inspector: {
|
||||
|
@ -46,6 +45,8 @@ import { Inspector, Adapters } from 'ui/inspector';
|
|||
import { EmbeddableFactory } from '../../../embeddables';
|
||||
import { Filter, FilterStateStore } from '@kbn/es-query';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
const embeddableFactories = new Map<string, EmbeddableFactory>();
|
||||
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import '../../../ui_capabilities.test.mocks';
|
||||
import '../../../../../../../core/public/ui_new_platform.test.mocks';
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
import {
|
||||
FilterableContainer,
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import '../ui_capabilities.test.mocks';
|
||||
import '../../../../../core/public/ui_new_platform.test.mocks';
|
||||
|
||||
import { EuiContextMenuPanelDescriptor } from '@elastic/eui';
|
||||
|
||||
|
@ -33,6 +32,8 @@ import { Action, ActionContext, actionRegistry } from '../actions';
|
|||
import { executeTriggerActions } from './execute_trigger_actions';
|
||||
import { ContactCardEmbeddable } from '../test_samples';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
class TestAction extends Action {
|
||||
public readonly type = 'testAction';
|
||||
public checkCompatibility: (context: ActionContext) => boolean;
|
||||
|
|
|
@ -18,13 +18,14 @@
|
|||
*/
|
||||
|
||||
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';
|
||||
import { attachAction } from './attach_action';
|
||||
import { detachAction } from './detach_action';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
beforeAll(() => {
|
||||
triggerRegistry.clear();
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { inputControlVis } from './input_control_fn';
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { kibanaPie } from './pie_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
const mockResponseHandler = jest.fn().mockReturnValue(Promise.resolve({
|
||||
hits: 1,
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { metric } from './metric_vis_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('interpreter/functions#metric', () => {
|
||||
const fn = functionWrapper(metric);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { regionmap } from './region_map_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('interpreter/functions#regionmap', () => {
|
||||
const fn = functionWrapper(regionmap);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { kibanaTable } from './table_vis_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
const mockResponseHandler = jest.fn().mockReturnValue(Promise.resolve({
|
||||
tables: [{ columns: [], rows: [] }],
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { tagcloud } from './tag_cloud_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('interpreter/functions#tagcloud', () => {
|
||||
const fn = functionWrapper(tagcloud);
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { tilemap } from './tilemap_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () => require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor());
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
jest.mock('ui/vis/map/convert_to_geojson', () => ({
|
||||
convertToGeoJson: jest.fn().mockReturnValue({
|
||||
featureCollection: {
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
import { functionWrapper } from '../../interpreter/test_helpers';
|
||||
import { kibanaMarkdown } from './markdown_fn';
|
||||
|
||||
jest.mock('ui/new_platform', () =>
|
||||
require('../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor()
|
||||
);
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('interpreter/functions#markdown', () => {
|
||||
const fn = functionWrapper(kibanaMarkdown);
|
||||
|
|
45
src/legacy/ui/public/new_platform/__mocks__/helpers.ts
Normal file
45
src/legacy/ui/public/new_platform/__mocks__/helpers.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 '../../../../../core/public/mocks';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { dataPluginMock } from '../../../../../plugins/data/public/mocks';
|
||||
|
||||
export const pluginsMock = {
|
||||
createSetup: () => ({
|
||||
data: dataPluginMock.createSetupContract(),
|
||||
}),
|
||||
createStart: () => ({
|
||||
data: dataPluginMock.createStartContract(),
|
||||
}),
|
||||
};
|
||||
|
||||
export const createUiNewPlatformMock = () => {
|
||||
const mock = {
|
||||
npSetup: {
|
||||
core: coreMock.createSetup(),
|
||||
plugins: pluginsMock.createSetup(),
|
||||
},
|
||||
npStart: {
|
||||
core: coreMock.createStart(),
|
||||
plugins: pluginsMock.createStart(),
|
||||
},
|
||||
};
|
||||
return mock;
|
||||
};
|
|
@ -17,14 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { coreMock } from './mocks';
|
||||
import { createUiNewPlatformMock } from './helpers';
|
||||
|
||||
export const coreSetupMock = coreMock.createSetup();
|
||||
export const coreStartMock = coreMock.createStart();
|
||||
|
||||
jest.doMock('ui/new_platform', () => {
|
||||
return {
|
||||
npStart: { core: coreStartMock },
|
||||
npSetup: { core: coreSetupMock },
|
||||
};
|
||||
});
|
||||
const { npSetup, npStart } = createUiNewPlatformMock();
|
||||
export { npSetup, npStart };
|
|
@ -26,9 +26,7 @@ import { VisResponseData } from './types';
|
|||
import { Inspector } from '../../inspector';
|
||||
import { EmbeddedVisualizeHandler } from './embedded_visualize_handler';
|
||||
|
||||
jest.mock('ui/new_platform', () =>
|
||||
require('../../../../ui/public/new_platform/index.test.mocks').mockNewPlatformBackdoor()
|
||||
);
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('EmbeddedVisualizeHandler', () => {
|
||||
let handler: any;
|
||||
|
|
54
src/plugins/data/public/mocks.ts
Normal file
54
src/plugins/data/public/mocks.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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 { Plugin } from '.';
|
||||
|
||||
export type Setup = jest.Mocked<ReturnType<Plugin['setup']>>;
|
||||
export type Start = jest.Mocked<ReturnType<Plugin['start']>>;
|
||||
|
||||
const createSetupContract = (): Setup => {
|
||||
const setupContract: Setup = {
|
||||
expressions: {
|
||||
registerFunction: jest.fn(),
|
||||
registerRenderer: jest.fn(),
|
||||
registerType: jest.fn(),
|
||||
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
|
||||
functions: {
|
||||
register: () => {},
|
||||
} as any,
|
||||
renderers: {
|
||||
register: () => {},
|
||||
} as any,
|
||||
types: {
|
||||
register: () => {},
|
||||
} as any,
|
||||
},
|
||||
},
|
||||
};
|
||||
return setupContract;
|
||||
};
|
||||
|
||||
const createStartContract = (): Start => {
|
||||
const startContract: Start = undefined;
|
||||
return startContract;
|
||||
};
|
||||
|
||||
export const dataPluginMock = {
|
||||
createSetupContract,
|
||||
createStartContract,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue