From 30be5828c1e0f981cb4ae646378e67541551f4bd Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 15 Jan 2024 13:07:13 +0200 Subject: [PATCH] [Cases] Fix alert property actions flaky test (#174759) ## Summary Fixes: https://github.com/elastic/kibana/issues/174671, https://github.com/elastic/kibana/issues/174670, https://github.com/elastic/kibana/issues/174669, https://github.com/elastic/kibana/issues/174668, https://github.com/elastic/kibana/issues/174667 Successful builds: https://buildkite.com/elastic/kibana-pull-request/builds?branch=cnasikas%3Afix_alert_property_actions_flaky ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../alert_property_actions.test.tsx | 87 +++++++++---------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx index 982484f11ed476d..ae0d7e39d5e1b9f 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; -import { waitFor } from '@testing-library/react'; +import { waitFor, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { @@ -17,12 +17,7 @@ import { } from '../../../common/mock'; import { AlertPropertyActions } from './alert_property_actions'; -// FLAKY: https://github.com/elastic/kibana/issues/174667 -// FLAKY: https://github.com/elastic/kibana/issues/174668 -// FLAKY: https://github.com/elastic/kibana/issues/174669 -// FLAKY: https://github.com/elastic/kibana/issues/174670 -// FLAKY: https://github.com/elastic/kibana/issues/174671 -describe.skip('AlertPropertyActions', () => { +describe('AlertPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -32,93 +27,89 @@ describe.skip('AlertPropertyActions', () => { }; beforeEach(() => { - appMock = createAppMockRenderer(); jest.clearAllMocks(); + appMock = createAppMockRenderer(); }); it('renders the correct number of actions', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-user-action-group').children.length).toBe(1); - expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 1 + ); + + expect( + await screen.findByTestId('property-actions-user-action-minusInCircle') + ).toBeInTheDocument(); }); it('renders the modal info correctly for one alert', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); - - await waitFor(() => { - expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(result.getByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert'); - expect(result.getByText('Remove')).toBeInTheDocument(); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert'); + expect(await screen.findByText('Remove')).toBeInTheDocument(); }); it('renders the modal info correctly for multiple alert', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - await waitFor(() => { - expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); - - expect(result.getByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); - expect(result.getByText('Remove')).toBeInTheDocument(); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); + expect(await screen.findByText('Remove')).toBeInTheDocument(); }); it('remove alerts correctly', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + + userEvent.click(screen.getByText('Remove')); await waitFor(() => { - expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(props.onDelete).toHaveBeenCalled(); }); - - userEvent.click(result.getByText('Remove')); - expect(props.onDelete).toHaveBeenCalled(); }); it('does not show the property actions without delete permissions', async () => { appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - const result = appMock.render(); + appMock.render(); - expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); }); it('does show the property actions with only delete permissions', async () => { appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); }); });