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 1/4] 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(); + }); }); -}); +} From e886e194ea1a94c95b075155a9920c47fa6528da Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:26:43 +0100 Subject: [PATCH 2/4] remove loop --- .../alert_property_actions.test.tsx | 114 ++++++----- ...ered_attachments_property_actions.test.tsx | 182 +++++++++--------- .../user_comment_property_actions.test.tsx | 136 +++++++------ 3 files changed, 212 insertions(+), 220 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 4968c293bacf0..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,85 +17,83 @@ import { } from '../../../common/mock'; import { AlertPropertyActions } from './alert_property_actions'; -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(); - }); +describe('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(); + 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')); - await waitForEuiPopoverOpen(); + 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-group')).children.length).toBe( + 1 + ); - expect( - await screen.findByTestId('property-actions-user-action-minusInCircle') - ).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(await screen.findByText('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 89be6495cae51..04b034a1d0a56 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,127 +18,123 @@ import { import { RegisteredAttachmentsPropertyActions } from './registered_attachments_property_actions'; import { AttachmentActionType } from '../../../client/attachment_framework/types'; -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(); - }); +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(); + 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 not show the property actions when hideDefaultActions is enabled', async () => { - appMock.render(); + it('does not show the property actions when hideDefaultActions is enabled', async () => { + 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(); + }); - 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(); - }); + 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 04d168b5ed1ed..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 @@ -17,100 +17,98 @@ import { import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; -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(), - }; - - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - it('renders the correct number of actions', async () => { - appMock.render(); +describe('UserCommentPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + onEdit: jest.fn(), + onQuote: jest.fn(), + onDelete: jest.fn(), + }; + + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - 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(); - 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(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - it('edits the comment correctly', async () => { - 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(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('edits the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('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 () => { - appMock.render(); + expect(props.onEdit).toHaveBeenCalled(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('quotes the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('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 () => { - appMock.render(); + expect(props.onQuote).toHaveBeenCalled(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('deletes the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - await waitFor(() => { - expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - userEvent.click(await screen.findByText('Delete')); - expect(props.onDelete).toHaveBeenCalled(); + await waitFor(() => { + expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + userEvent.click(await screen.findByText('Delete')); + expect(props.onDelete).toHaveBeenCalled(); + }); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - expect(await screen.findByTestId('property-actions-user-action')).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(); }); -} +}); From 2c86c2e97e16244cdb5d94798bb8a07179ebe359 Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:28:18 +0100 Subject: [PATCH 3/4] PR feedback --- .../property_actions.test.tsx | 28 +++++++++---------- ...ered_attachments_property_actions.test.tsx | 2 -- 2 files changed, 14 insertions(+), 16 deletions(-) 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 04b034a1d0a56..0125b31bee2a7 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 @@ -45,8 +45,6 @@ describe('RegisteredAttachmentsPropertyActions', () => { expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( 1 ); - - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); }); it('renders the modal info correctly', async () => { From 0d8cb79929c2c9881bb479c512e739ce7f1e6e07 Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:34:32 +0100 Subject: [PATCH 4/4] remove waitForPopOverOpen, check for element directly --- .../registered_attachments_property_actions.test.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 0125b31bee2a7..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 @@ -40,11 +40,7 @@ describe('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-group')).toBeInTheDocument(); }); it('renders the modal info correctly', async () => {