From 885df523d1cacca136ae8f76d6a9f75b7d24c82d Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:52:03 +0100 Subject: [PATCH] [Cases] Fix property actions flaky tests (#176709) ## Summary Fixes #175314 Fixes #175313 Fixes #175312 Fixes #175311 Fixes #175310 Fixes #174667 Fixes #174384 ### Checklist - [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 --- .../alert_property_actions.test.tsx | 21 +----- .../property_actions.test.tsx | 28 ++++---- ...ered_attachments_property_actions.test.tsx | 11 +-- .../user_comment_property_actions.test.tsx | 67 +++++++++---------- 4 files changed, 50 insertions(+), 77 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 63c7ea95d8d9a..ac2d1d245b56b 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 @@ -17,8 +17,7 @@ import { } from '../../../common/mock'; import { AlertPropertyActions } from './alert_property_actions'; -// FLAKY: https://github.com/elastic/kibana/issues/174667 -describe.skip('AlertPropertyActions', () => { +describe('AlertPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -49,22 +48,6 @@ describe.skip('AlertPropertyActions', () => { ).toBeInTheDocument(); }); - it('renders the modal info correctly for one alert', async () => { - appMock.render(); - - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); - - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - - expect(await screen.findByTestId('property-actions-confirm-modal')).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 () => { appMock.render(); @@ -93,7 +76,7 @@ describe.skip('AlertPropertyActions', () => { expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(screen.getByText('Remove')); + userEvent.click(await screen.findByText('Remove')); await waitFor(() => { expect(props.onDelete).toHaveBeenCalled(); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.test.tsx index 4d6964da2047c..6ae104a0d2521 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; +import { waitForEuiPopoverOpen, screen } from '@elastic/eui/lib/test/rtl'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { createAppMockRenderer } from '../../../common/mock'; @@ -35,30 +35,30 @@ describe('UserActionPropertyActions', () => { }); it('renders the loading spinner correctly when loading', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('user-action-title-loading')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + expect(await screen.findByTestId('user-action-title-loading')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); }); it('renders the property 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-pencil')).toBeInTheDocument(); + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 1 + ); + expect(await screen.findByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); }); it('does not render if properties are empty', async () => { - const result = appMock.render( - - ); + appMock.render(); - expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - expect(result.queryByTestId('user-action-title-loading')).not.toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + expect(screen.queryByTestId('user-action-title-loading')).not.toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index 3fb7b1fcc53cd..f0db59b3a682d 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -18,8 +18,7 @@ import { import { RegisteredAttachmentsPropertyActions } from './registered_attachments_property_actions'; import { AttachmentActionType } from '../../../client/attachment_framework/types'; -// FLAKY: https://github.com/elastic/kibana/issues/174384 -describe.skip('RegisteredAttachmentsPropertyActions', () => { +describe('RegisteredAttachmentsPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -41,13 +40,7 @@ describe.skip('RegisteredAttachmentsPropertyActions', () => { userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); - - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 1 - ); - - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument(); }); it('renders the modal info correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index 79f1c7ffc29d7..8fc3b0cb8adcb 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; +import { waitForEuiPopoverOpen, screen } from '@elastic/eui/lib/test/rtl'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { @@ -17,12 +17,7 @@ import { import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; -// FLAKY: https://github.com/elastic/kibana/issues/175310 -// FLAKY: https://github.com/elastic/kibana/issues/175311 -// FLAKY: https://github.com/elastic/kibana/issues/175312 -// FLAKY: https://github.com/elastic/kibana/issues/175313 -// FLAKY: https://github.com/elastic/kibana/issues/175314 -describe.skip('UserCommentPropertyActions', () => { +describe('UserCommentPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -38,80 +33,82 @@ describe.skip('UserCommentPropertyActions', () => { }); 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(3); - expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 3 + ); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); }); it('edits the comment 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-pencil')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-pencil')); + userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); expect(props.onEdit).toHaveBeenCalled(); }); it('quotes the comment 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-quote')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-quote')); + userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); expect(props.onQuote).toHaveBeenCalled(); }); it('deletes the comment 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-trash')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); await waitFor(() => { - expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); }); - userEvent.click(result.getByText('Delete')); + userEvent.click(await screen.findByText('Delete')); 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(); }); });