From 1e99f1bd033fd5127071dc897fe62cc29da4201e Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:18:17 +0100 Subject: [PATCH] [Cases] fix description flaky tests (#175126) ## Summary Fixes https://github.com/elastic/kibana/issues/174133, https://github.com/elastic/kibana/issues/174134, https://github.com/elastic/kibana/issues/174135 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --- .../components/create/description.test.tsx | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/cases/public/components/create/description.test.tsx b/x-pack/plugins/cases/public/components/create/description.test.tsx index d7cef68771739..bedb72f7bd9e6 100644 --- a/x-pack/plugins/cases/public/components/create/description.test.tsx +++ b/x-pack/plugins/cases/public/components/create/description.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { waitFor, screen } from '@testing-library/react'; -import userEvent, { specialChars } from '@testing-library/user-event'; +import userEvent from '@testing-library/user-event'; import type { FormHook } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import { useForm, Form } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; @@ -18,10 +18,7 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; import { MAX_DESCRIPTION_LENGTH } from '../../../common/constants'; -// FLAKY: https://github.com/elastic/kibana/issues/174133 -// FLAKY: https://github.com/elastic/kibana/issues/174134 -// FLAKY: https://github.com/elastic/kibana/issues/174135 -describe.skip('Description', () => { +describe('Description', () => { let globalForm: FormHook; let appMockRender: AppMockRenderer; const draftStorageKey = `cases.caseView.createCase.description.markdownEditor`; @@ -55,7 +52,7 @@ describe.skip('Description', () => { ); - expect(screen.getByTestId('caseDescription')).toBeInTheDocument(); + expect(await screen.findByTestId('caseDescription')).toBeInTheDocument(); }); it('it changes the description', async () => { @@ -65,12 +62,10 @@ describe.skip('Description', () => { ); - const description = screen.getByTestId('euiMarkdownEditorTextArea'); + const description = await screen.findByTestId('euiMarkdownEditorTextArea'); - userEvent.type( - description, - `${specialChars.selectAll}${specialChars.delete}My new description` - ); + userEvent.clear(description); + userEvent.paste(description, 'My new description'); await waitFor(() => { expect(globalForm.getFormData()).toEqual({ description: 'My new description' }); @@ -84,14 +79,12 @@ describe.skip('Description', () => { ); - const description = screen.getByTestId('euiMarkdownEditorTextArea'); + const description = await screen.findByTestId('euiMarkdownEditorTextArea'); userEvent.clear(description); - userEvent.type(description, ' '); + userEvent.paste(description, ' '); - await waitFor(() => { - expect(screen.getByText('A description is required.')).toBeInTheDocument(); - }); + expect(await screen.findByText('A description is required.')).toBeInTheDocument(); }); it('shows an error when description is too long', async () => { @@ -103,16 +96,14 @@ describe.skip('Description', () => { ); - const description = screen.getByTestId('euiMarkdownEditorTextArea'); + const description = await screen.findByTestId('euiMarkdownEditorTextArea'); userEvent.paste(description, longDescription); - await waitFor(() => { - expect( - screen.getByText( - 'The length of the description is too long. The maximum length is 30000 characters.' - ) - ).toBeInTheDocument(); - }); + expect( + await screen.findByText( + 'The length of the description is too long. The maximum length is 30000 characters.' + ) + ).toBeInTheDocument(); }); });