diff --git a/src/plugins/controls/public/control_group/actions/delete_control_action.test.tsx b/src/plugins/controls/public/control_group/actions/delete_control_action.test.tsx index 0f64334b94787a..cff04dc7e56a46 100644 --- a/src/plugins/controls/public/control_group/actions/delete_control_action.test.tsx +++ b/src/plugins/controls/public/control_group/actions/delete_control_action.test.tsx @@ -8,6 +8,7 @@ import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import { OPTIONS_LIST_CONTROL } from '../../../common'; import { ControlOutput } from '../../types'; import { ControlGroupInput } from '../types'; import { pluginServices } from '../../services'; @@ -15,6 +16,7 @@ import { DeleteControlAction } from './delete_control_action'; import { OptionsListEmbeddableInput } from '../../options_list'; import { controlGroupInputBuilder } from '../external_api/control_group_input_builder'; import { ControlGroupContainer } from '../embeddable/control_group_container'; +import { OptionsListEmbeddableFactory } from '../../options_list/embeddable/options_list_embeddable_factory'; import { OptionsListEmbeddable } from '../../options_list/embeddable/options_list_embeddable'; import { mockedReduxEmbeddablePackage } from '@kbn/presentation-util-plugin/public/mocks'; @@ -22,6 +24,12 @@ let container: ControlGroupContainer; let embeddable: OptionsListEmbeddable; beforeAll(async () => { + pluginServices.getServices().controls.getControlFactory = jest + .fn() + .mockImplementation((type: string) => { + if (type === OPTIONS_LIST_CONTROL) return new OptionsListEmbeddableFactory(); + }); + const controlGroupInput = { chainingSystem: 'NONE', panels: {} } as ControlGroupInput; controlGroupInputBuilder.addOptionsListControl(controlGroupInput, { dataViewId: 'test-data-view', @@ -34,6 +42,7 @@ beforeAll(async () => { await container.untilInitialized(); embeddable = container.getChild(container.getChildIds()[0]); + expect(embeddable.type).toBe(OPTIONS_LIST_CONTROL); }); test('Action is incompatible with Error Embeddables', async () => { diff --git a/src/plugins/controls/public/control_group/actions/edit_control_action.test.tsx b/src/plugins/controls/public/control_group/actions/edit_control_action.test.tsx index d8a1bdb30832fc..a496e8671f6d67 100644 --- a/src/plugins/controls/public/control_group/actions/edit_control_action.test.tsx +++ b/src/plugins/controls/public/control_group/actions/edit_control_action.test.tsx @@ -8,6 +8,7 @@ import { ErrorEmbeddable } from '@kbn/embeddable-plugin/public'; +import { OPTIONS_LIST_CONTROL } from '../../../common'; import { ControlOutput } from '../../types'; import { ControlGroupInput } from '../types'; import { pluginServices } from '../../services'; @@ -55,13 +56,14 @@ test('Action is compatible with embeddables that are editable', async () => { const editControlAction = new EditControlAction(deleteControlAction); const emptyContainer = new ControlGroupContainer(mockedReduxEmbeddablePackage, controlGroupInput); await emptyContainer.untilInitialized(); - await emptyContainer.addOptionsListControl({ + const control = await emptyContainer.addOptionsListControl({ dataViewId: 'test-data-view', title: 'test', fieldName: 'test-field', width: 'medium', grow: false, }); + expect(emptyContainer.getInput().panels[control.getInput().id].type).toBe(OPTIONS_LIST_CONTROL); expect( await editControlAction.isCompatible({ @@ -88,18 +90,16 @@ test('Execute should open a flyout', async () => { const emptyContainer = new ControlGroupContainer(mockedReduxEmbeddablePackage, controlGroupInput); await emptyContainer.untilInitialized(); - await emptyContainer.addOptionsListControl({ + const control = (await emptyContainer.addOptionsListControl({ dataViewId: 'test-data-view', title: 'test', fieldName: 'test-field', width: 'medium', grow: false, - }); - const embeddable: OptionsListEmbeddable = emptyContainer.getChild( - emptyContainer.getChildIds()[0] - ); + })) as OptionsListEmbeddable; + expect(emptyContainer.getInput().panels[control.getInput().id].type).toBe(OPTIONS_LIST_CONTROL); const editControlAction = new EditControlAction(deleteControlAction); - await editControlAction.execute({ embeddable }); + await editControlAction.execute({ embeddable: control }); expect(spyOn).toHaveBeenCalled(); });