From 68134683705bb9ca9491cdc2ea96af7f3ac6c05b Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:18:35 +0100 Subject: [PATCH] fix property actions flaky tests --- .../alert_property_actions.test.tsx | 131 ++++++------- ...ered_attachments_property_actions.test.tsx | 183 +++++++++--------- .../user_comment_property_actions.test.tsx | 141 +++++++------- 3 files changed, 221 insertions(+), 234 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..4968c293bacf0 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,100 +17,85 @@ import { } from '../../../common/mock'; import { AlertPropertyActions } from './alert_property_actions'; -// FLAKY: https://github.com/elastic/kibana/issues/174667 -describe.skip('AlertPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - totalAlerts: 1, - onDelete: jest.fn(), - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); - - it('renders the correct number of actions', async () => { - appMock.render(); - - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - - 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-minusInCircle') - ).toBeInTheDocument(); - }); - - it('renders the modal info correctly for one alert', async () => { - appMock.render(); +for (let i = 0; i < 500; i++) { + describe('AlertPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + totalAlerts: 1, + onDelete: jest.fn(), + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('renders the correct number of actions', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect( + (await screen.findByTestId('property-actions-user-action-group')).children.length + ).toBe(1); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert'); - expect(await screen.findByText('Remove')).toBeInTheDocument(); - }); + expect( + await screen.findByTestId('property-actions-user-action-minusInCircle') + ).toBeInTheDocument(); + }); - it('renders the modal info correctly for multiple alert', async () => { - appMock.render(); + it('renders the modal info correctly for multiple alert', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + 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-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); - expect(await screen.findByText('Remove')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); + expect(await screen.findByText('Remove')).toBeInTheDocument(); + }); - it('remove alerts correctly', async () => { - appMock.render(); + it('remove alerts correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + 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-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + 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(); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); + }); }); - }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.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() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).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..89be6495cae51 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,124 +18,127 @@ 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', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - registeredAttachmentActions: [], - onDelete: jest.fn(), - hideDefaultActions: false, - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); +for (let i = 0; i < 500; i++) { + describe('RegisteredAttachmentsPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + registeredAttachmentActions: [], + onDelete: jest.fn(), + hideDefaultActions: false, + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + await waitForEuiPopoverOpen(); - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 1 - ); + 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-trash')).toBeInTheDocument(); + }); - it('renders the modal info correctly', async () => { - appMock.render(); + it('renders the modal info correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + 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-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( - 'Delete attachment' - ); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( + 'Delete attachment' + ); - expect(await screen.findByText('Delete')).toBeInTheDocument(); - }); + expect(await screen.findByText('Delete')).toBeInTheDocument(); + }); - it('remove attachments correctly', async () => { - appMock.render(); + it('remove attachments correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + 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-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(await screen.findByText('Delete')); + userEvent.click(await screen.findByText('Delete')); - await waitFor(() => { - expect(props.onDelete).toHaveBeenCalled(); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); + }); }); - }); - - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); - - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); - it('does not show the property actions when hideDefaultActions is enabled', async () => { - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); - - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); - - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - }); - - it('renders correctly registered attachments', async () => { - const onClick = jest.fn(); - const action = [ - { - type: AttachmentActionType.BUTTON as const, - label: 'My button', - iconType: 'download', - onClick, - }, - ]; + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - appMock.render( - - ); + it('does not show the property actions when hideDefaultActions is enabled', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 2 - ); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); - expect(await screen.findByTestId('property-actions-user-action-download')).toBeInTheDocument(); + it('renders correctly registered attachments', async () => { + const onClick = jest.fn(); + const action = [ + { + type: AttachmentActionType.BUTTON as const, + label: 'My button', + iconType: 'download', + onClick, + }, + ]; + + appMock.render( + + ); + + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); + + expect( + (await screen.findByTestId('property-actions-user-action-group')).children.length + ).toBe(2); + + expect( + await screen.findByTestId('property-actions-user-action-download') + ).toBeInTheDocument(); + }); }); -}); +} 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..04d168b5ed1ed 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,101 +17,100 @@ 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', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - onEdit: jest.fn(), - onQuote: jest.fn(), - onDelete: jest.fn(), - }; - - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); +for (let i = 0; i < 500; i++) { + describe('UserCommentPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + onEdit: jest.fn(), + onQuote: jest.fn(), + onDelete: jest.fn(), + }; - it('renders the correct number of actions', async () => { - const result = appMock.render(); + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + it('renders the correct number of actions', async () => { + appMock.render(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - 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(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - it('edits the comment correctly', async () => { - const result = appMock.render(); + 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(); + }); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + it('edits the comment correctly', async () => { + appMock.render(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(result.getByTestId('property-actions-user-action-pencil')); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - expect(props.onEdit).toHaveBeenCalled(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); - it('quotes the comment correctly', async () => { - const result = appMock.render(); + expect(props.onEdit).toHaveBeenCalled(); + }); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + it('quotes the comment correctly', async () => { + appMock.render(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(result.getByTestId('property-actions-user-action-quote')); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - expect(props.onQuote).toHaveBeenCalled(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); - it('deletes the comment correctly', async () => { - const result = appMock.render(); + expect(props.onQuote).toHaveBeenCalled(); + }); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + it('deletes the comment correctly', async () => { + appMock.render(); - userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(result.getByTestId('property-actions-user-action-trash')); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - await waitFor(() => { - expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - userEvent.click(result.getByText('Delete')); - expect(props.onDelete).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + }); + + 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(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + 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(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); }); -}); +}