From 549428c308f1cd73b68f6c09e4555fbec6b98dd9 Mon Sep 17 00:00:00 2001 From: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com> Date: Mon, 6 Feb 2023 15:38:36 -0500 Subject: [PATCH] [Cases] Improve functional tests (#150117) This PR tries to improve how often our functional tests succeeds. I also tried cleaning up a few things that seemed to be slowing the tests down and also causing errors when the tests were run individually. Fixes: https://github.com/elastic/kibana/issues/145271 Notable changes: - I added a value to the `property-actions*` in most places so that the functional tests can distinguish between a description, comment, or the case ellipses this seems to work consistently where other methods have not Flaky test run: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/1871 (cherry picked from commit c3ea5e5b3a2f0e13e743eea059404c81a07576c1) # Conflicts: # x-pack/plugins/cases/public/components/case_action_bar/actions.test.tsx # x-pack/plugins/cases/public/components/case_action_bar/index.test.tsx # x-pack/plugins/cases/public/components/property_actions/index.tsx # x-pack/plugins/cases/public/components/user_actions/index.test.tsx # x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts --- .../case_action_bar/actions.test.tsx | 23 +++-- .../components/case_action_bar/actions.tsx | 2 +- .../components/case_action_bar/index.test.tsx | 4 +- .../components/property_actions/index.tsx | 84 ++++++++++--------- .../user_actions/comment/comment.test.tsx | 24 +++--- .../user_actions/description.test.tsx | 16 ++-- .../components/user_actions/index.test.tsx | 24 ++++-- .../alert_property_actions.test.tsx | 36 ++++---- .../description_property_actions.test.tsx | 28 +++---- .../description_property_actions.tsx | 8 +- .../property_actions.test.tsx | 12 +-- .../property_actions/property_actions.tsx | 12 ++- ...ered_attachments_property_actions.test.tsx | 28 +++---- .../user_comment_property_actions.test.tsx | 40 ++++----- x-pack/test/functional/services/cases/list.ts | 3 - .../services/cases/single_case_view.ts | 12 ++- .../apps/cases/deletion.ts | 6 +- .../apps/cases/view_case.ts | 4 +- 18 files changed, 199 insertions(+), 167 deletions(-) diff --git a/x-pack/plugins/cases/public/components/case_action_bar/actions.test.tsx b/x-pack/plugins/cases/public/components/case_action_bar/actions.test.tsx index cf15d546415be..818a2406e28ce 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/actions.test.tsx +++ b/x-pack/plugins/cases/public/components/case_action_bar/actions.test.tsx @@ -50,8 +50,11 @@ describe('CaseView actions', () => { ); expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeFalsy(); - wrapper.find('button[data-test-subj="property-actions-ellipses"]').first().simulate('click'); - wrapper.find('button[data-test-subj="property-actions-trash"]').simulate('click'); + wrapper + .find('button[data-test-subj="property-actions-case-ellipses"]') + .first() + .simulate('click'); + wrapper.find('button[data-test-subj="property-actions-case-trash"]').simulate('click'); expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeTruthy(); }); @@ -63,7 +66,7 @@ describe('CaseView actions', () => { ); expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeFalsy(); - expect(wrapper.find('button[data-test-subj="property-actions-ellipses"]').exists()).toBeFalsy(); + expect(wrapper.find('button[data-test-subj="property-actions-case-ellipses"]').exists()).toBeFalsy(); }); it('toggle delete modal and confirm', async () => { @@ -77,8 +80,11 @@ describe('CaseView actions', () => { ); - wrapper.find('button[data-test-subj="property-actions-ellipses"]').first().simulate('click'); - wrapper.find('button[data-test-subj="property-actions-trash"]').simulate('click'); + wrapper + .find('button[data-test-subj="property-actions-case-ellipses"]') + .first() + .simulate('click'); + wrapper.find('button[data-test-subj="property-actions-case-trash"]').simulate('click'); expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeTruthy(); wrapper.find('button[data-test-subj="confirmModalConfirmButton"]').simulate('click'); @@ -106,9 +112,12 @@ describe('CaseView actions', () => { expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeFalsy(); - wrapper.find('button[data-test-subj="property-actions-ellipses"]').first().simulate('click'); + wrapper + .find('button[data-test-subj="property-actions-case-ellipses"]') + .first() + .simulate('click'); expect( - wrapper.find('[data-test-subj="property-actions-popout"]').first().prop('aria-label') + wrapper.find('[data-test-subj="property-actions-case-popout"]').first().prop('aria-label') ).toEqual(i18n.VIEW_INCIDENT(basicPush.externalTitle)); }); }); diff --git a/x-pack/plugins/cases/public/components/case_action_bar/actions.tsx b/x-pack/plugins/cases/public/components/case_action_bar/actions.tsx index 414ac6326ef5d..3ce99cc7f19bd 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/actions.tsx +++ b/x-pack/plugins/cases/public/components/case_action_bar/actions.tsx @@ -74,7 +74,7 @@ const ActionsComponent: React.FC = ({ caseData, currentExternal return ( - + {isModalVisible ? ( { ); - expect(queryByTestId('property-actions-ellipses')).not.toBeInTheDocument(); + expect(queryByTestId('property-actions-case-ellipses')).not.toBeInTheDocument(); expect(queryByText('Delete case')).not.toBeInTheDocument(); }); @@ -244,7 +244,7 @@ describe('CaseActionBar', () => { ); - userEvent.click(screen.getByTestId('property-actions-ellipses')); + userEvent.click(screen.getByTestId('property-actions-case-ellipses')); expect(queryByText('Delete case')).toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/cases/public/components/property_actions/index.tsx b/x-pack/plugins/cases/public/components/property_actions/index.tsx index 8f67611097a80..9938e05c7fb84 100644 --- a/x-pack/plugins/cases/public/components/property_actions/index.tsx +++ b/x-pack/plugins/cases/public/components/property_actions/index.tsx @@ -15,69 +15,70 @@ export interface PropertyActionButtonProps { onClick: () => void; iconType: string; label: string; + customDataTestSubj?: string; } const ComponentId = 'property-actions'; const PropertyActionButton = React.memo( - ({ disabled = false, onClick, iconType, label }) => ( - { + const dataTestSubjPrepend = makeDataTestSubjPrepend(customDataTestSubj); + + return ( {label} - - ) + ) + } ); PropertyActionButton.displayName = 'PropertyActionButton'; export interface PropertyActionsProps { propertyActions: PropertyActionButtonProps[]; + customDataTestSubj?: string; } -export const PropertyActions = React.memo(({ propertyActions }) => { - const [showActions, setShowActions] = useState(false); - - const onButtonClick = useCallback(() => { - setShowActions((prevShowActions) => !prevShowActions); - }, []); +export const PropertyActions = React.memo( + ({ propertyActions, customDataTestSubj }) => { + const [showActions, setShowActions] = useState(false); - const onClosePopover = useCallback((cb?: () => void) => { - setShowActions(false); - if (cb != null) { - cb(); - } - }, []); + const onButtonClick = useCallback(() => { + setShowActions((prevShowActions) => !prevShowActions); + }, []); - return ( - + const onClosePopover = useCallback((cb?: () => void) => { + setShowActions(false); + if (cb != null) { + cb(); } - id="settingsPopover" - isOpen={showActions} - closePopover={onClosePopover} - repositionOnScroll - > - + } + id="settingsPopover" + isOpen={showActions} + closePopover={onClosePopover} + repositionOnScroll > {propertyActions.map((action, key) => ( @@ -87,6 +88,7 @@ export const PropertyActions = React.memo(({ propertyActio iconType={action.iconType} label={action.label} onClick={() => onClosePopover(action.onClick)} + customDataTestSubj={customDataTestSubj} /> @@ -97,3 +99,7 @@ export const PropertyActions = React.memo(({ propertyActio }); PropertyActions.displayName = 'PropertyActions'; + +const makeDataTestSubjPrepend = (customDataTestSubj?: string) => { + return customDataTestSubj == null ? ComponentId : `${ComponentId}-${customDataTestSubj}`; +}; diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/comment.test.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/comment.test.tsx index 77f1af32529e4..2ecc4b32d0837 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/comment.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/comment.test.tsx @@ -223,13 +223,13 @@ describe('createCommentUserActionBuilder', () => { ); expect(result.getByText('Solve this fast!')).toBeInTheDocument(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-pencil')); + expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + userEvent.click(result.getByTestId('property-actions-user-action-pencil')); await waitFor(() => { expect(builderArgs.handleManageMarkdownEditId).toHaveBeenCalledWith('basic-comment-id'); @@ -254,13 +254,13 @@ describe('createCommentUserActionBuilder', () => { ); expect(result.getByText('Solve this fast!')).toBeInTheDocument(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-quote')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-quote')); + expect(result.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + userEvent.click(result.getByTestId('property-actions-user-action-quote')); await waitFor(() => { expect(builderArgs.handleManageQuote).toHaveBeenCalledWith('Solve this fast!'); @@ -769,14 +769,14 @@ describe('createCommentUserActionBuilder', () => { }); const deleteAttachment = async (result: RenderResult, deleteIcon: string, buttonLabel: string) => { - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId(`property-actions-${deleteIcon}`)).toBeInTheDocument(); + expect(result.queryByTestId(`property-actions-user-action-${deleteIcon}`)).toBeInTheDocument(); - userEvent.click(result.getByTestId(`property-actions-${deleteIcon}`)); + userEvent.click(result.getByTestId(`property-actions-user-action-${deleteIcon}`)); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); diff --git a/x-pack/plugins/cases/public/components/user_actions/description.test.tsx b/x-pack/plugins/cases/public/components/user_actions/description.test.tsx index 9fddcbb3cce6a..5b519b6739bdd 100644 --- a/x-pack/plugins/cases/public/components/user_actions/description.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/description.test.tsx @@ -58,13 +58,13 @@ describe('createDescriptionUserActionBuilder ', () => { ); - expect(res.getByTestId('property-actions')).toBeInTheDocument(); + expect(res.getByTestId('property-actions-description')).toBeInTheDocument(); - userEvent.click(res.getByTestId('property-actions-ellipses')); + userEvent.click(res.getByTestId('property-actions-description-ellipses')); await waitForEuiPopoverOpen(); - expect(res.queryByTestId('property-actions-pencil')).toBeInTheDocument(); - userEvent.click(res.getByTestId('property-actions-pencil')); + expect(res.queryByTestId('property-actions-description-pencil')).toBeInTheDocument(); + userEvent.click(res.getByTestId('property-actions-description-pencil')); await waitFor(() => { expect(builderArgs.handleManageMarkdownEditId).toHaveBeenCalledWith('description'); @@ -84,13 +84,13 @@ describe('createDescriptionUserActionBuilder ', () => { ); - expect(res.getByTestId('property-actions')).toBeInTheDocument(); + expect(res.getByTestId('property-actions-description')).toBeInTheDocument(); - userEvent.click(res.getByTestId('property-actions-ellipses')); + userEvent.click(res.getByTestId('property-actions-description-ellipses')); await waitForEuiPopoverOpen(); - expect(res.queryByTestId('property-actions-quote')).toBeInTheDocument(); - userEvent.click(res.getByTestId('property-actions-quote')); + expect(res.queryByTestId('property-actions-description-quote')).toBeInTheDocument(); + userEvent.click(res.getByTestId('property-actions-description-quote')); await waitFor(() => { expect(builderArgs.handleManageQuote).toHaveBeenCalledWith('Security banana Issue'); diff --git a/x-pack/plugins/cases/public/components/user_actions/index.test.tsx b/x-pack/plugins/cases/public/components/user_actions/index.test.tsx index 631772ef768d0..ccf230260efb6 100644 --- a/x-pack/plugins/cases/public/components/user_actions/index.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/index.test.tsx @@ -203,13 +203,13 @@ describe(`UserActions`, () => { wrapper .find( - `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-ellipses"]` + `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-user-action-ellipses"]` ) .first() .simulate('click'); wrapper .find( - `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-pencil"]` + `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-user-action-pencil"]` ) .first() .simulate('click'); @@ -247,14 +247,14 @@ describe(`UserActions`, () => { wrapper .find( - `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-ellipses"]` + `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-user-action-ellipses"]` ) .first() .simulate('click'); wrapper .find( - `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-pencil"]` + `[data-test-subj="comment-create-action-${props.data.comments[0].id}"] [data-test-subj="property-actions-user-action-pencil"]` ) .first() .simulate('click'); @@ -299,12 +299,16 @@ describe(`UserActions`, () => { ); wrapper - .find(`[data-test-subj="description-action"] [data-test-subj="property-actions-ellipses"]`) + .find( + `[data-test-subj="description-action"] [data-test-subj="property-actions-description-ellipses"]` + ) .first() .simulate('click'); wrapper - .find(`[data-test-subj="description-action"] [data-test-subj="property-actions-pencil"]`) + .find( + `[data-test-subj="description-action"] [data-test-subj="property-actions-description-pencil"]` + ) .first() .simulate('click'); @@ -347,12 +351,16 @@ describe(`UserActions`, () => { expect(wrapper.find(`.euiMarkdownEditorTextArea`).text()).not.toContain(quoteableText); wrapper - .find(`[data-test-subj="description-action"] [data-test-subj="property-actions-ellipses"]`) + .find( + `[data-test-subj="description-action"] [data-test-subj="property-actions-description-ellipses"]` + ) .first() .simulate('click'); wrapper - .find(`[data-test-subj="description-action"] [data-test-subj="property-actions-quote"]`) + .find( + `[data-test-subj="description-action"] [data-test-subj="property-actions-description-quote"]` + ) .first() .simulate('click'); 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 dc8a57b8477f6..79636d52572ba 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 @@ -34,26 +34,26 @@ describe('AlertPropertyActions', () => { it('renders the correct number of actions', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-group').children.length).toBe(1); - expect(result.queryByTestId('property-actions-minusInCircle')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action-group').children.length).toBe(1); + expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); }); it('renders the modal info correctly for one alert', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-minusInCircle')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-minusInCircle')); + userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -66,14 +66,14 @@ describe('AlertPropertyActions', () => { it('renders the modal info correctly for multiple alert', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-minusInCircle')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-minusInCircle')); + userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -86,14 +86,14 @@ describe('AlertPropertyActions', () => { it('remove alerts correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-minusInCircle')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-minusInCircle')); + userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -107,13 +107,13 @@ describe('AlertPropertyActions', () => { appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); const result = appMock.render(); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.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(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.test.tsx index bfaa349caf46f..4a164c5e1fbda 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.test.tsx @@ -29,27 +29,27 @@ describe('DescriptionPropertyActions', () => { it('renders the correct number of actions', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-description')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-description-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-group').children.length).toBe(2); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-quote')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-description-group').children.length).toBe(2); + expect(result.queryByTestId('property-actions-description-pencil')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-description-quote')).toBeInTheDocument(); }); it('edits the description correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-description')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-description-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-description-pencil')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-pencil')); + userEvent.click(result.getByTestId('property-actions-description-pencil')); expect(props.onEdit).toHaveBeenCalled(); }); @@ -57,14 +57,14 @@ describe('DescriptionPropertyActions', () => { it('quotes the description correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-description')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-description-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-quote')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-description-quote')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-quote')); + userEvent.click(result.getByTestId('property-actions-description-quote')); expect(props.onQuote).toHaveBeenCalled(); }); @@ -73,6 +73,6 @@ describe('DescriptionPropertyActions', () => { appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); const result = appMock.render(); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.queryByTestId('property-actions-description')).not.toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.tsx index 5ef72a5590140..1b948f57e6448 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/description_property_actions.tsx @@ -45,7 +45,13 @@ const DescriptionPropertyActionsComponent: React.FC = ({ isLoading, onEdi ]; }, [permissions.update, permissions.create, onEdit, onQuote]); - return ; + return ( + + ); }; DescriptionPropertyActionsComponent.displayName = 'DescriptionPropertyActions'; 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 c7cfdb25bb359..ca310ab5121aa 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 @@ -36,19 +36,19 @@ describe('UserActionPropertyActions', () => { const result = appMock.render(); expect(result.getByTestId('user-action-title-loading')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); }); it('renders the property actions', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-group').children.length).toBe(1); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action-group').children.length).toBe(1); + expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); }); it('does not render if properties are empty', async () => { @@ -56,7 +56,7 @@ describe('UserActionPropertyActions', () => { ); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); expect(result.queryByTestId('user-action-title-loading')).not.toBeInTheDocument(); }); }); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.tsx index abf897404711a..975a8670ab096 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/property_actions.tsx @@ -13,9 +13,14 @@ import { PropertyActions } from '../../property_actions'; interface Props { isLoading: boolean; propertyActions: PropertyActionButtonProps[]; + customDataTestSubj?: string; } -const UserActionPropertyActionsComponent: React.FC = ({ isLoading, propertyActions }) => { +const UserActionPropertyActionsComponent: React.FC = ({ + isLoading, + propertyActions, + customDataTestSubj = 'user-action', +}) => { if (propertyActions.length === 0) { return null; } @@ -25,7 +30,10 @@ const UserActionPropertyActionsComponent: React.FC = ({ isLoading, proper {isLoading ? ( ) : ( - + )} ); 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 a756f43893e03..9e391fa6e7042 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 @@ -33,26 +33,26 @@ describe('RegisteredAttachmentsPropertyActions', () => { it('renders the correct number of actions', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-group').children.length).toBe(1); - expect(result.queryByTestId('property-actions-trash')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action-group').children.length).toBe(1); + expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); }); it('renders the modal info correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-trash')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-trash')); + userEvent.click(result.getByTestId('property-actions-user-action-trash')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -65,14 +65,14 @@ describe('RegisteredAttachmentsPropertyActions', () => { it('remove attachments correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-trash')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-trash')); + userEvent.click(result.getByTestId('property-actions-user-action-trash')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -86,13 +86,13 @@ describe('RegisteredAttachmentsPropertyActions', () => { appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); const result = appMock.render(); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.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(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).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 557dae707c20f..643662dfbc3f7 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 @@ -35,28 +35,28 @@ describe('UserCommentPropertyActions', () => { it('renders the correct number of actions', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.getByTestId('property-actions-group').children.length).toBe(3); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-trash')).toBeInTheDocument(); - expect(result.queryByTestId('property-actions-quote')).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(); }); it('edits the comment correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-pencil')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-pencil')); + userEvent.click(result.getByTestId('property-actions-user-action-pencil')); expect(props.onEdit).toHaveBeenCalled(); }); @@ -64,14 +64,14 @@ describe('UserCommentPropertyActions', () => { it('quotes the comment correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-quote')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-quote')); + userEvent.click(result.getByTestId('property-actions-user-action-quote')); expect(props.onQuote).toHaveBeenCalled(); }); @@ -79,14 +79,14 @@ describe('UserCommentPropertyActions', () => { it('deletes the comment correctly', async () => { const result = appMock.render(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-ellipses')); + userEvent.click(result.getByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - expect(result.queryByTestId('property-actions-trash')).toBeInTheDocument(); + expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(result.getByTestId('property-actions-trash')); + userEvent.click(result.getByTestId('property-actions-user-action-trash')); await waitFor(() => { expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -100,13 +100,13 @@ describe('UserCommentPropertyActions', () => { appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); const result = appMock.render(); - expect(result.queryByTestId('property-actions')).not.toBeInTheDocument(); + expect(result.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(); - expect(result.getByTestId('property-actions')).toBeInTheDocument(); + expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument(); }); }); diff --git a/x-pack/test/functional/services/cases/list.ts b/x-pack/test/functional/services/cases/list.ts index 9394cac0e469e..3c2a6e528a8a1 100644 --- a/x-pack/test/functional/services/cases/list.ts +++ b/x-pack/test/functional/services/cases/list.ts @@ -81,9 +81,6 @@ export function CasesTableServiceProvider( rows = await find.allByCssSelector('[data-test-subj*="cases-table-row-"', 100); if (rows.length > 0) { await this.bulkDeleteAllCases(); - // wait for a second - await new Promise((r) => setTimeout(r, 1000)); - await header.waitUntilLoadingHasFinished(); } } while (rows.length > 0); }, diff --git a/x-pack/test/functional/services/cases/single_case_view.ts b/x-pack/test/functional/services/cases/single_case_view.ts index bd9377ebd5abd..b8bea0841a605 100644 --- a/x-pack/test/functional/services/cases/single_case_view.ts +++ b/x-pack/test/functional/services/cases/single_case_view.ts @@ -20,14 +20,12 @@ export function CasesSingleViewServiceProvider({ getService, getPageObject }: Ft return { async deleteCase() { - const caseActions = await testSubjects.findDescendant( - 'property-actions-ellipses', - await testSubjects.find('case-view-actions') - ); + await retry.try(async () => { + await testSubjects.click('property-actions-case-ellipses'); + await testSubjects.existOrFail('property-actions-case-trash', { timeout: 100 }); + }); - await caseActions.click(); - await testSubjects.existOrFail('property-actions-trash'); - await common.clickAndValidate('property-actions-trash', 'confirmModalConfirmButton'); + await common.clickAndValidate('property-actions-case-trash', 'confirmModalConfirmButton'); await testSubjects.click('confirmModalConfirmButton'); await header.waitUntilLoadingHasFinished(); }, diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/deletion.ts b/x-pack/test/functional_with_es_ssl/apps/cases/deletion.ts index 0f8d551ce86aa..4179c549484fb 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/deletion.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/deletion.ts @@ -17,8 +17,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); const cases = getService('cases'); - // Failing: See https://github.com/elastic/kibana/issues/145271 - describe.skip('cases deletion sub privilege', () => { + describe('cases deletion sub privilege', () => { before(async () => { await createUsersAndRoles(getService, users, roles); await PageObjects.security.forceLogout(); @@ -101,7 +100,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); it(`User ${user.username} cannot delete a case while on a specific case page`, async () => { - await testSubjects.missingOrFail('case-view-actions'); + await testSubjects.click('property-actions-case-ellipses'); + await testSubjects.missingOrFail('property-actions-case-trash'); }); }); diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts b/x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts index 5a3862d5ac781..4be470a584a0e 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts @@ -14,7 +14,7 @@ import { createUsersAndRoles, deleteUsersAndRoles, } from '../../../cases_api_integration/common/lib/authentication'; -import { users, roles, casesAllUser } from './common'; +import { users, roles, casesAllUser, casesAllUser2 } from './common'; export default ({ getPageObject, getService }: FtrProviderContext) => { const header = getPageObject('header'); @@ -213,7 +213,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { describe('Assignees field', () => { before(async () => { await createUsersAndRoles(getService, users, roles); - await cases.api.activateUserProfiles([casesAllUser]); + await cases.api.activateUserProfiles([casesAllUser, casesAllUser2]); }); after(async () => {