From 6aa5ae89498518cbb62757362b16fd91a02d3d0a Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 16 Jan 2024 18:58:35 +0200 Subject: [PATCH] [Cases] Fix description flaky tests (#174903) ## Summary Fixes: https://github.com/elastic/kibana/issues/174323, https://github.com/elastic/kibana/issues/174322, https://github.com/elastic/kibana/issues/174321, https://github.com/elastic/kibana/issues/164049, https://github.com/elastic/kibana/issues/164048, https://github.com/elastic/kibana/issues/164045 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../components/description/index.test.tsx | 77 +++++++------------ 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index 3c2f32437f4a0..ed03dc453737e 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -13,7 +13,7 @@ import { basicCase } from '../../containers/mock'; import { Description } from '.'; import type { AppMockRenderer } from '../../common/mock'; -import { createAppMockRenderer, noUpdateCasesPermissions, TestProviders } from '../../common/mock'; +import { createAppMockRenderer, noUpdateCasesPermissions } from '../../common/mock'; import { MAX_DESCRIPTION_LENGTH } from '../../../common/constants'; jest.mock('../../common/lib/kibana'); @@ -27,13 +27,7 @@ const defaultProps = { isLoadingDescription: false, }; -// FLAKY: https://github.com/elastic/kibana/issues/174321 -// FLAKY: https://github.com/elastic/kibana/issues/174322 -// FLAKY: https://github.com/elastic/kibana/issues/174323 -// FLAKY: https://github.com/elastic/kibana/issues/164045 -// FLAKY: https://github.com/elastic/kibana/issues/164048 -// FLAKY: https://github.com/elastic/kibana/issues/164049 -describe.skip('Description', () => { +describe('Description', () => { const onUpdateField = jest.fn(); let appMockRender: AppMockRenderer; @@ -45,48 +39,42 @@ describe.skip('Description', () => { it('renders description correctly', async () => { appMockRender.render(); - expect(screen.getByTestId('description')).toBeInTheDocument(); - expect(screen.getByText('Security banana Issue')).toBeInTheDocument(); + expect(await screen.findByTestId('description')).toBeInTheDocument(); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); }); it('hides and shows the description correctly when collapse button clicked', async () => { - const res = appMockRender.render( - - ); + appMockRender.render(); - userEvent.click(res.getByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); await waitFor(() => { expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument(); }); - userEvent.click(res.getByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); }); it('shows textarea on edit click', async () => { - const res = appMockRender.render( - - ); + appMockRender.render(); - userEvent.click(res.getByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument(); }); it('edits the description correctly when saved', async () => { const editedDescription = 'New updated description'; - const res = appMockRender.render( - - ); + appMockRender.render(); - userEvent.click(res.getByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), editedDescription); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - userEvent.click(screen.getByTestId('editable-save-markdown')); + userEvent.click(await screen.findByTestId('editable-save-markdown')); await waitFor(() => { expect(onUpdateField).toHaveBeenCalledWith({ @@ -98,37 +86,33 @@ describe.skip('Description', () => { it('keeps the old description correctly when canceled', async () => { const editedDescription = 'New updated description'; - const res = appMockRender.render( - - ); + appMockRender.render(); - userEvent.click(res.getByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), editedDescription); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - expect(screen.getByText(editedDescription)).toBeInTheDocument(); + expect(await screen.findByText(editedDescription)).toBeInTheDocument(); - userEvent.click(screen.getByTestId('editable-cancel-markdown')); + userEvent.click(await screen.findByTestId('editable-cancel-markdown')); await waitFor(() => { expect(onUpdateField).not.toHaveBeenCalled(); }); - expect(screen.getByText('Security banana Issue')).toBeInTheDocument(); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); }); it('shows an error when description is too long', async () => { const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1); - const res = appMockRender.render( - - ); + appMockRender.render(); - userEvent.click(res.getByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), longDescription); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription); expect( await screen.findByText( @@ -139,14 +123,11 @@ describe.skip('Description', () => { expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled'); }); - it('should hide the edit button when the user does not have update permissions', () => { - appMockRender.render( - - - - ); + it('should hide the edit button when the user does not have update permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() }); + appMockRender.render(); - expect(screen.getByText('Security banana Issue')).toBeInTheDocument(); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument(); });