From 2b6e02e239788dfb1b8845fdf98a1c3bd7449789 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 29 Jan 2024 13:44:36 +0200 Subject: [PATCH] [Cases] Fix edit tags flaky tests (#175763) ## Summary Fixes: https://github.com/elastic/kibana/issues/175655, https://github.com/elastic/kibana/issues/175623, https://github.com/elastic/kibana/issues/175622, https://github.com/elastic/kibana/issues/175619, https://github.com/elastic/kibana/issues/175618 ### 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) --- .../case_view/components/edit_tags.test.tsx | 96 ++++++++----------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/cases/public/components/case_view/components/edit_tags.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/edit_tags.test.tsx index 33a4230d0d59d..baad93c219b9d 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/edit_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/edit_tags.test.tsx @@ -11,7 +11,7 @@ import userEvent from '@testing-library/user-event'; import type { EditTagsProps } from './edit_tags'; import { EditTags } from './edit_tags'; -import { readCasesPermissions, TestProviders, createAppMockRenderer } from '../../../common/mock'; +import { readCasesPermissions, createAppMockRenderer } from '../../../common/mock'; import type { AppMockRenderer } from '../../../common/mock'; import { useGetTags } from '../../../containers/use_get_tags'; import { MAX_LENGTH_PER_TAG } from '../../../../common/constants'; @@ -25,15 +25,7 @@ const defaultProps: EditTagsProps = { tags: [], }; -// The suite is skipped for having several flaky tests -// See: -// https://github.com/elastic/kibana/issues/175618 -// https://github.com/elastic/kibana/issues/175619 -// https://github.com/elastic/kibana/issues/175621 -// https://github.com/elastic/kibana/issues/175622 -// https://github.com/elastic/kibana/issues/175623 -// https://github.com/elastic/kibana/issues/175655 -describe.skip('EditTags ', () => { +describe('EditTags ', () => { let appMockRender: AppMockRenderer; const sampleTags = ['coke', 'pepsi']; @@ -46,30 +38,32 @@ describe.skip('EditTags ', () => { data: sampleTags, refetch: fetchTags, })); + appMockRender = createAppMockRenderer(); }); it('renders no tags, and then edit', async () => { appMockRender.render(); - expect(screen.getByTestId('no-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('no-tags')).toBeInTheDocument(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); await waitFor(() => { expect(screen.queryByTestId('no-tags')).not.toBeInTheDocument(); - expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); }); + + expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); }); it('edit tag from options on submit', async () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - userEvent.type(screen.getByRole('combobox'), `${sampleTags[0]}{enter}`); + userEvent.type(await screen.findByRole('combobox'), `${sampleTags[0]}{enter}`); - userEvent.click(screen.getByTestId('edit-tags-submit')); + userEvent.click(await screen.findByTestId('edit-tags-submit')); await waitFor(() => expect(onSubmit).toBeCalledWith([sampleTags[0]])); }); @@ -77,15 +71,13 @@ describe.skip('EditTags ', () => { it('add new tags on submit', async () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - await waitFor(() => { - expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); - userEvent.type(screen.getByRole('combobox'), 'dude{enter}'); + userEvent.type(await screen.findByRole('combobox'), 'dude{enter}'); - userEvent.click(screen.getByTestId('edit-tags-submit')); + userEvent.click(await screen.findByTestId('edit-tags-submit')); await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); }); @@ -93,15 +85,13 @@ describe.skip('EditTags ', () => { it('trims the tags on submit', async () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - await waitFor(() => { - expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); - userEvent.type(screen.getByRole('combobox'), 'dude {enter}'); + userEvent.type(await screen.findByRole('combobox'), 'dude {enter}'); - userEvent.click(screen.getByTestId('edit-tags-submit')); + userEvent.click(await screen.findByTestId('edit-tags-submit')); await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); }); @@ -109,36 +99,31 @@ describe.skip('EditTags ', () => { it('cancels on cancel', async () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - userEvent.type(screen.getByRole('combobox'), 'new{enter}'); + userEvent.type(await screen.findByRole('combobox'), 'new{enter}'); - await waitFor(() => { - expect(screen.getByTestId('comboBoxInput')).toHaveTextContent('new'); - }); + expect(await screen.findByTestId('comboBoxInput')).toHaveTextContent('new'); - userEvent.click(screen.getByTestId('edit-tags-cancel')); + userEvent.click(await screen.findByTestId('edit-tags-cancel')); await waitFor(() => { expect(onSubmit).not.toBeCalled(); - expect(screen.getByTestId('no-tags')).toBeInTheDocument(); }); + + expect(await screen.findByTestId('no-tags')).toBeInTheDocument(); }); it('shows error when tag is empty', async () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - await waitFor(() => { - expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); - userEvent.type(screen.getByRole('combobox'), ' {enter}'); + userEvent.type(await screen.findByRole('combobox'), ' {enter}'); - await waitFor(() => { - expect(screen.getByText('A tag must contain at least one non-space character.')); - }); + expect(await screen.findByText('A tag must contain at least one non-space character.')); }); it('shows error when tag is too long', async () => { @@ -146,28 +131,23 @@ describe.skip('EditTags ', () => { appMockRender.render(); - userEvent.click(screen.getByTestId('tag-list-edit-button')); + userEvent.click(await screen.findByTestId('tag-list-edit-button')); - await waitFor(() => { - expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); - userEvent.paste(screen.getByRole('combobox'), `${longTag}`); + userEvent.paste(await screen.findByRole('combobox'), `${longTag}`); userEvent.keyboard('{enter}'); - await waitFor(() => { - expect( - screen.getByText('The length of the tag is too long. The maximum length is 256 characters.') - ); - }); + expect( + await screen.findByText( + 'The length of the tag is too long. The maximum length is 256 characters.' + ) + ); }); it('does not render when the user does not have update permissions', () => { - appMockRender.render( - - - - ); + appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); + appMockRender.render(); expect(screen.queryByTestId('tag-list-edit')).not.toBeInTheDocument(); });