From f4233d5598cc434d4b33df1d8fb00726158229c5 Mon Sep 17 00:00:00 2001 From: adcoelho Date: Fri, 9 Feb 2024 14:17:42 +0100 Subject: [PATCH 1/2] Fix flaky test --- .../all_cases/severity_filter.test.tsx | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx index 28be7c63f22b3..54d979b0cf56c 100644 --- a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx @@ -14,44 +14,53 @@ import { screen, waitFor } from '@testing-library/react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import { SeverityFilter } from './severity_filter'; -// FLAKY: https://github.com/elastic/kibana/issues/176336 -// FLAKY: https://github.com/elastic/kibana/issues/176337 -describe.skip('Severity form field', () => { - const onChange = jest.fn(); - let appMockRender: AppMockRenderer; - const props = { - selectedOptionKeys: [], - onChange, - }; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - }); +for (let i = 0; i <= 200; i = i + 1) { + describe('Severity form field', () => { + const onChange = jest.fn(); + let appMockRender: AppMockRenderer; + const props = { + selectedOptionKeys: [], + onChange, + }; - it('renders', async () => { - appMockRender.render(); - expect(screen.getByTestId('options-filter-popover-button-severity')).toBeInTheDocument(); - expect(screen.getByTestId('options-filter-popover-button-severity')).not.toBeDisabled(); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + }); - userEvent.click(screen.getByRole('button', { name: 'Severity' })); - await waitForEuiPopoverOpen(); + it('renders', async () => { + appMockRender.render(); + expect( + await screen.findByTestId('options-filter-popover-button-severity') + ).toBeInTheDocument(); + expect( + await screen.findByTestId('options-filter-popover-button-severity') + ).not.toBeDisabled(); - expect(screen.getByRole('option', { name: CaseSeverity.LOW })).toBeInTheDocument(); - expect(screen.getByRole('option', { name: CaseSeverity.MEDIUM })).toBeInTheDocument(); - expect(screen.getByRole('option', { name: CaseSeverity.HIGH })).toBeInTheDocument(); - expect(screen.getByRole('option', { name: CaseSeverity.CRITICAL })).toBeInTheDocument(); - expect(screen.getAllByRole('option').length).toBe(4); - }); + userEvent.click(await screen.findByRole('button', { name: 'Severity' })); + await waitForEuiPopoverOpen(); + + expect(await screen.findByRole('option', { name: CaseSeverity.LOW })).toBeInTheDocument(); + expect(await screen.findByRole('option', { name: CaseSeverity.MEDIUM })).toBeInTheDocument(); + expect(await screen.findByRole('option', { name: CaseSeverity.HIGH })).toBeInTheDocument(); + expect( + await screen.findByRole('option', { name: CaseSeverity.CRITICAL }) + ).toBeInTheDocument(); + expect((await screen.findAllByRole('option')).length).toBe(4); + }); - it('selects the correct value when changed', async () => { - appMockRender.render(); + it('selects the correct value when changed', async () => { + appMockRender.render(); - userEvent.click(screen.getByRole('button', { name: 'Severity' })); - await waitForEuiPopoverOpen(); - userEvent.click(screen.getByRole('option', { name: 'high' })); + userEvent.click(await screen.findByRole('button', { name: 'Severity' })); + await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByRole('option', { name: 'high' })); - await waitFor(() => { - expect(onChange).toHaveBeenCalledWith({ filterId: 'severity', selectedOptionKeys: ['high'] }); + await waitFor(() => { + expect(onChange).toHaveBeenCalledWith({ + filterId: 'severity', + selectedOptionKeys: ['high'], + }); + }); }); }); -}); +} From 762b1de9a629b8b117154bdbdc0e9a5d5ed61823 Mon Sep 17 00:00:00 2001 From: adcoelho Date: Fri, 9 Feb 2024 16:09:33 +0100 Subject: [PATCH 2/2] removed for loop --- .../all_cases/severity_filter.test.tsx | 74 +++++++++---------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx index 54d979b0cf56c..ca09d53501e5f 100644 --- a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx @@ -14,53 +14,45 @@ import { screen, waitFor } from '@testing-library/react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import { SeverityFilter } from './severity_filter'; -for (let i = 0; i <= 200; i = i + 1) { - describe('Severity form field', () => { - const onChange = jest.fn(); - let appMockRender: AppMockRenderer; - const props = { - selectedOptionKeys: [], - onChange, - }; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - }); +describe('Severity form field', () => { + const onChange = jest.fn(); + let appMockRender: AppMockRenderer; + const props = { + selectedOptionKeys: [], + onChange, + }; + + beforeEach(() => { + appMockRender = createAppMockRenderer(); + }); - it('renders', async () => { - appMockRender.render(); - expect( - await screen.findByTestId('options-filter-popover-button-severity') - ).toBeInTheDocument(); - expect( - await screen.findByTestId('options-filter-popover-button-severity') - ).not.toBeDisabled(); + it('renders', async () => { + appMockRender.render(); + expect(await screen.findByTestId('options-filter-popover-button-severity')).toBeInTheDocument(); + expect(await screen.findByTestId('options-filter-popover-button-severity')).not.toBeDisabled(); - userEvent.click(await screen.findByRole('button', { name: 'Severity' })); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByRole('button', { name: 'Severity' })); + await waitForEuiPopoverOpen(); - expect(await screen.findByRole('option', { name: CaseSeverity.LOW })).toBeInTheDocument(); - expect(await screen.findByRole('option', { name: CaseSeverity.MEDIUM })).toBeInTheDocument(); - expect(await screen.findByRole('option', { name: CaseSeverity.HIGH })).toBeInTheDocument(); - expect( - await screen.findByRole('option', { name: CaseSeverity.CRITICAL }) - ).toBeInTheDocument(); - expect((await screen.findAllByRole('option')).length).toBe(4); - }); + expect(await screen.findByRole('option', { name: CaseSeverity.LOW })).toBeInTheDocument(); + expect(await screen.findByRole('option', { name: CaseSeverity.MEDIUM })).toBeInTheDocument(); + expect(await screen.findByRole('option', { name: CaseSeverity.HIGH })).toBeInTheDocument(); + expect(await screen.findByRole('option', { name: CaseSeverity.CRITICAL })).toBeInTheDocument(); + expect((await screen.findAllByRole('option')).length).toBe(4); + }); - it('selects the correct value when changed', async () => { - appMockRender.render(); + it('selects the correct value when changed', async () => { + appMockRender.render(); - userEvent.click(await screen.findByRole('button', { name: 'Severity' })); - await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByRole('option', { name: 'high' })); + userEvent.click(await screen.findByRole('button', { name: 'Severity' })); + await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByRole('option', { name: 'high' })); - await waitFor(() => { - expect(onChange).toHaveBeenCalledWith({ - filterId: 'severity', - selectedOptionKeys: ['high'], - }); + await waitFor(() => { + expect(onChange).toHaveBeenCalledWith({ + filterId: 'severity', + selectedOptionKeys: ['high'], }); }); }); -} +});