From 39efa1c0a1c26e1b54be7195e53c993671cd0bd0 Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:17:04 +0100 Subject: [PATCH] remove loop --- .../all_cases/columns_popover.test.tsx | 294 +++++++++--------- 1 file changed, 145 insertions(+), 149 deletions(-) diff --git a/x-pack/plugins/cases/public/components/all_cases/columns_popover.test.tsx b/x-pack/plugins/cases/public/components/all_cases/columns_popover.test.tsx index 5f3d1a1ace58c..27f94319ecbcf 100644 --- a/x-pack/plugins/cases/public/components/all_cases/columns_popover.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/columns_popover.test.tsx @@ -14,186 +14,182 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; import { ColumnsPopover } from './columns_popover'; -for (let i = 0; i < 500; i++) { - describe('ColumnsPopover', () => { - let appMockRenderer: AppMockRenderer; +describe('ColumnsPopover', () => { + let appMockRenderer: AppMockRenderer; - beforeEach(() => { - appMockRenderer = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - const selectedColumns = [ - { field: 'title', name: 'Title', isChecked: true }, - { field: 'category', name: 'Category', isChecked: false }, - { field: 'tags', name: 'Tags', isChecked: false }, - ]; - - it('renders correctly a list of selected columns', async () => { - appMockRenderer.render( - {}} /> - ); - - userEvent.click(await screen.findByTestId('column-selection-popover-button')); + beforeEach(() => { + appMockRenderer = createAppMockRenderer(); + jest.clearAllMocks(); + }); - await waitForEuiPopoverOpen(); + const selectedColumns = [ + { field: 'title', name: 'Title', isChecked: true }, + { field: 'category', name: 'Category', isChecked: false }, + { field: 'tags', name: 'Tags', isChecked: false }, + ]; - expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); + it('renders correctly a list of selected columns', async () => { + appMockRenderer.render( + {}} /> + ); - selectedColumns.forEach(({ field, name, isChecked }) => { - expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( - 'aria-checked', - isChecked.toString() - ); - expect(screen.getByText(name)).toBeInTheDocument(); - }); - }); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); - it('clicking a switch calls onSelectedColumnsChange with the right params', async () => { - const onSelectedColumnsChange = jest.fn(); + await waitForEuiPopoverOpen(); - appMockRenderer.render( - - ); + expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); - userEvent.click( - await screen.findByTestId(`column-selection-switch-${selectedColumns[0].field}`), - undefined, - { skipPointerEventsCheck: true } + selectedColumns.forEach(({ field, name, isChecked }) => { + expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( + 'aria-checked', + isChecked.toString() ); - - await waitFor(() => { - expect(onSelectedColumnsChange).toHaveBeenCalledWith([ - { ...selectedColumns[0], isChecked: false }, - selectedColumns[1], - selectedColumns[2], - ]); - }); + expect(screen.getByText(name)).toBeInTheDocument(); }); + }); - it('clicking Show All calls onSelectedColumnsChange with the right params', async () => { - const onSelectedColumnsChange = jest.fn(); - - appMockRenderer.render( - - ); - - userEvent.click(await screen.findByTestId('column-selection-popover-button')); - userEvent.click( - await screen.findByTestId('column-selection-popover-show-all-button'), - undefined, - { - skipPointerEventsCheck: true, - } - ); - - const onSelectedColumnsChangeCallParams = selectedColumns.map((column) => ({ - ...column, - isChecked: true, - })); - - await waitFor(() => { - expect(onSelectedColumnsChange).toHaveBeenCalledWith(onSelectedColumnsChangeCallParams); - }); + it('clicking a switch calls onSelectedColumnsChange with the right params', async () => { + const onSelectedColumnsChange = jest.fn(); + + appMockRenderer.render( + + ); + + userEvent.click(await screen.findByTestId('column-selection-popover-button')); + userEvent.click( + await screen.findByTestId(`column-selection-switch-${selectedColumns[0].field}`), + undefined, + { skipPointerEventsCheck: true } + ); + + await waitFor(() => { + expect(onSelectedColumnsChange).toHaveBeenCalledWith([ + { ...selectedColumns[0], isChecked: false }, + selectedColumns[1], + selectedColumns[2], + ]); }); + }); - it('clicking Hide All calls onSelectedColumnsChange with the right params', async () => { - const onSelectedColumnsChange = jest.fn(); - - appMockRenderer.render( - - ); + it('clicking Show All calls onSelectedColumnsChange with the right params', async () => { + const onSelectedColumnsChange = jest.fn(); + + appMockRenderer.render( + + ); + + userEvent.click(await screen.findByTestId('column-selection-popover-button')); + userEvent.click( + await screen.findByTestId('column-selection-popover-show-all-button'), + undefined, + { + skipPointerEventsCheck: true, + } + ); + + const onSelectedColumnsChangeCallParams = selectedColumns.map((column) => ({ + ...column, + isChecked: true, + })); + + await waitFor(() => { + expect(onSelectedColumnsChange).toHaveBeenCalledWith(onSelectedColumnsChangeCallParams); + }); + }); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); - userEvent.click( - await screen.findByTestId('column-selection-popover-hide-all-button'), - undefined, - { - skipPointerEventsCheck: true, - } + it('clicking Hide All calls onSelectedColumnsChange with the right params', async () => { + const onSelectedColumnsChange = jest.fn(); + + appMockRenderer.render( + + ); + + userEvent.click(await screen.findByTestId('column-selection-popover-button')); + userEvent.click( + await screen.findByTestId('column-selection-popover-hide-all-button'), + undefined, + { + skipPointerEventsCheck: true, + } + ); + + await waitFor(() => { + expect(onSelectedColumnsChange).toHaveBeenCalledWith( + selectedColumns.map((column) => ({ ...column, isChecked: false })) ); - - await waitFor(() => { - expect(onSelectedColumnsChange).toHaveBeenCalledWith( - selectedColumns.map((column) => ({ ...column, isChecked: false })) - ); - }); }); + }); - it('searching for text changes the column list correctly', async () => { - appMockRenderer.render( - {}} /> - ); + it('searching for text changes the column list correctly', async () => { + appMockRenderer.render( + {}} /> + ); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); - await waitForEuiPopoverOpen(); - userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Title'); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); + await waitForEuiPopoverOpen(); + userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Title'); - expect(await screen.findByTestId('column-selection-switch-title')).toBeInTheDocument(); - expect(screen.queryByTestId('column-selection-switch-category')).not.toBeInTheDocument(); - expect(screen.queryByTestId('column-selection-switch-tags')).not.toBeInTheDocument(); - }); + expect(await screen.findByTestId('column-selection-switch-title')).toBeInTheDocument(); + expect(screen.queryByTestId('column-selection-switch-category')).not.toBeInTheDocument(); + expect(screen.queryByTestId('column-selection-switch-tags')).not.toBeInTheDocument(); + }); - it('searching for text does not change the list of selected columns', async () => { - const onSelectedColumnsChange = jest.fn(); + it('searching for text does not change the list of selected columns', async () => { + const onSelectedColumnsChange = jest.fn(); - appMockRenderer.render( - - ); + appMockRenderer.render( + + ); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); - await waitForEuiPopoverOpen(); - userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Category'); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); + await waitForEuiPopoverOpen(); + userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Category'); - await waitFor(() => { - expect(onSelectedColumnsChange).not.toHaveBeenCalled(); - }); + await waitFor(() => { + expect(onSelectedColumnsChange).not.toHaveBeenCalled(); }); + }); - it('searching for text hides the drag and drop icons', async () => { - appMockRenderer.render( - {}} /> - ); + it('searching for text hides the drag and drop icons', async () => { + appMockRenderer.render( + {}} /> + ); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); - expect(await screen.findAllByTestId('column-selection-popover-draggable-icon')).toHaveLength( - 3 - ); + expect(await screen.findAllByTestId('column-selection-popover-draggable-icon')).toHaveLength(3); - userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Foobar'); + userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Foobar'); - expect( - await screen.queryByTestId('column-selection-popover-draggable-icon') - ).not.toBeInTheDocument(); - }); + expect( + await screen.queryByTestId('column-selection-popover-draggable-icon') + ).not.toBeInTheDocument(); + }); - it('searching for text disables hideAll and showAll buttons', async () => { - appMockRenderer.render( - {}} /> - ); + it('searching for text disables hideAll and showAll buttons', async () => { + appMockRenderer.render( + {}} /> + ); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); - await waitForEuiPopoverOpen(); + await waitForEuiPopoverOpen(); - userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Foobar'); + userEvent.paste(await screen.findByTestId('column-selection-popover-search'), 'Foobar'); - expect(await screen.findByTestId('column-selection-popover-show-all-button')).toBeDisabled(); - expect(await screen.findByTestId('column-selection-popover-hide-all-button')).toBeDisabled(); - }); + expect(await screen.findByTestId('column-selection-popover-show-all-button')).toBeDisabled(); + expect(await screen.findByTestId('column-selection-popover-hide-all-button')).toBeDisabled(); }); -} +});