From 3548cbeeb3f5d069c8444d3e6cee2d9ab3e99701 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 16 Nov 2021 13:46:22 +0200 Subject: [PATCH] [Cases] Fixes configuration page flaky tests (#118521) --- .../components/configure_cases/index.test.tsx | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/cases/public/components/configure_cases/index.test.tsx b/x-pack/plugins/cases/public/components/configure_cases/index.test.tsx index 990d44584cf05..8843bed9a2b43 100644 --- a/x-pack/plugins/cases/public/components/configure_cases/index.test.tsx +++ b/x-pack/plugins/cases/public/components/configure_cases/index.test.tsx @@ -39,6 +39,8 @@ const useConnectorsMock = useConnectors as jest.Mock; const useCaseConfigureMock = useCaseConfigure as jest.Mock; const useGetUrlSearchMock = jest.fn(); const useActionTypesMock = useActionTypes as jest.Mock; +const getAddConnectorFlyoutMock = jest.fn(); +const getEditConnectorFlyoutMock = jest.fn(); describe('ConfigureCases', () => { beforeAll(() => { @@ -46,6 +48,12 @@ describe('ConfigureCases', () => { actionTypeTitle: '.servicenow', iconClass: 'logoSecurity', }); + + useKibanaMock().services.triggersActionsUi.getAddConnectorFlyout = + getAddConnectorFlyoutMock.mockReturnValue(
); + + useKibanaMock().services.triggersActionsUi.getEditConnectorFlyout = + getEditConnectorFlyoutMock.mockReturnValue(
); }); beforeEach(() => { @@ -72,12 +80,12 @@ describe('ConfigureCases', () => { expect(wrapper.find('[data-test-subj="closure-options-radio-group"]').exists()).toBeTruthy(); }); - test('it does NOT render the ConnectorAddFlyout', () => { - expect(wrapper.find('ConnectorAddFlyout').exists()).toBeFalsy(); + test('it does NOT render the add connector flyout', () => { + expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBeFalsy(); }); - test('it does NOT render the ConnectorEditFlyout', () => { - expect(wrapper.find('ConnectorEditFlyout').exists()).toBeFalsy(); + test('it does NOT render the edit connector flyout"]', () => { + expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBeFalsy(); }); test('it does NOT render the EuiCallOut', () => { @@ -176,8 +184,8 @@ describe('ConfigureCases', () => { expect(wrapper.find(ClosureOptions).prop('closureTypeSelected')).toBe('close-by-user'); // Flyouts - expect(wrapper.find('ConnectorAddFlyout').exists()).toBe(false); - expect(wrapper.find('ConnectorEditFlyout').exists()).toBe(false); + expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBe(false); + expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBe(false); }); test('it disables correctly when the user cannot crud', () => { @@ -541,21 +549,25 @@ describe('ConfigureCases', () => { await waitFor(() => { wrapper.update(); - expect(wrapper.find('ConnectorAddFlyout').exists()).toBe(true); - expect(wrapper.find('ConnectorAddFlyout').prop('actionTypes')).toEqual([ - expect.objectContaining({ - id: '.servicenow', - }), - expect.objectContaining({ - id: '.jira', - }), - expect.objectContaining({ - id: '.resilient', - }), + expect(wrapper.find('[data-test-subj="add-connector-flyout"]').exists()).toBe(true); + expect(getAddConnectorFlyoutMock).toHaveBeenCalledWith( expect.objectContaining({ - id: '.servicenow-sir', - }), - ]); + actionTypes: [ + expect.objectContaining({ + id: '.servicenow', + }), + expect.objectContaining({ + id: '.jira', + }), + expect.objectContaining({ + id: '.resilient', + }), + expect.objectContaining({ + id: '.servicenow-sir', + }), + ], + }) + ); }); }); @@ -588,8 +600,10 @@ describe('ConfigureCases', () => { await waitFor(() => { wrapper.update(); - expect(wrapper.find('ConnectorEditFlyout').exists()).toBe(true); - expect(wrapper.find('ConnectorEditFlyout').prop('initialConnector')).toEqual(connectors[1]); + expect(wrapper.find('[data-test-subj="edit-connector-flyout"]').exists()).toBe(true); + expect(getEditConnectorFlyoutMock).toHaveBeenCalledWith( + expect.objectContaining({ initialConnector: connectors[1] }) + ); }); expect(