diff --git a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx index aeca39a39c98f..c807152ba84a9 100644 --- a/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { waitFor, screen, within } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; +import userEvent, { type UserEvent } from '@testing-library/user-event'; import { connector, choices } from '../mock'; import { useGetChoices } from './use_get_choices'; @@ -23,6 +23,16 @@ const useGetChoicesMock = useGetChoices as jest.Mock; let appMockRenderer: AppMockRenderer; describe('ServiceNowITSM Fields', () => { + let user: UserEvent; + + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + const fields = { severity: '1', urgency: '2', @@ -32,6 +42,10 @@ describe('ServiceNowITSM Fields', () => { }; beforeEach(() => { + // Workaround for timeout via https://github.com/testing-library/user-event/issues/833#issuecomment-1171452841 + user = userEvent.setup({ + advanceTimers: jest.advanceTimersByTime, + }); appMockRenderer = createAppMockRenderer(); useGetChoicesMock.mockReturnValue({ isLoading: false, @@ -169,7 +183,7 @@ describe('ServiceNowITSM Fields', () => { ); const select = await screen.findByTestId(`${subj}Select`); - await userEvent.selectOptions(select, '4 - Low'); + await user.selectOptions(select, '4 - Low'); expect(select).toHaveValue('4'); }) @@ -194,19 +208,19 @@ describe('ServiceNowITSM Fields', () => { ]; for (const [element] of selectables) { - await userEvent.selectOptions(element, ['2']); + await user.selectOptions(element, ['2']); } const categorySelect = await screen.findByTestId('categorySelect'); expect(await within(categorySelect).findByRole('option', { name: 'Software' })); - await userEvent.selectOptions(categorySelect, ['software']); + await user.selectOptions(categorySelect, ['software']); const subcategorySelect = await screen.findByTestId('subcategorySelect'); expect(await within(subcategorySelect).findByRole('option', { name: 'Operation System' })); - await userEvent.selectOptions(subcategorySelect, ['os']); + await user.selectOptions(subcategorySelect, ['os']); expect(severitySelect).toHaveValue('2'); expect(urgencySelect).toHaveValue('2'); @@ -226,7 +240,7 @@ describe('ServiceNowITSM Fields', () => { expect(await within(categorySelect).findByRole('option', { name: 'Software' })); - await userEvent.selectOptions(categorySelect, ['software']); + await user.selectOptions(categorySelect, ['software']); const subcategorySelect = await screen.findByTestId('subcategorySelect'); @@ -234,7 +248,7 @@ describe('ServiceNowITSM Fields', () => { expect(subcategorySelect).toHaveValue('os'); - await userEvent.selectOptions(categorySelect, ['Privilege Escalation']); + await user.selectOptions(categorySelect, ['Privilege Escalation']); await waitFor(() => { expect(subcategorySelect).not.toHaveValue(); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx index 79344284d479d..0bab06f1e2326 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/alert_property_actions.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import { waitFor, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; +import userEvent, { type UserEvent } from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { noCasesPermissions, @@ -18,6 +18,7 @@ import { import { AlertPropertyActions } from './alert_property_actions'; describe('AlertPropertyActions', () => { + let user: UserEvent; let appMock: AppMockRenderer; const props = { @@ -26,8 +27,20 @@ describe('AlertPropertyActions', () => { onDelete: jest.fn(), }; + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + beforeEach(() => { jest.clearAllMocks(); + // Workaround for timeout via https://github.com/testing-library/user-event/issues/833#issuecomment-1171452841 + user = userEvent.setup({ + advanceTimers: jest.advanceTimersByTime, + }); appMock = createAppMockRenderer(); }); @@ -40,7 +53,7 @@ describe('AlertPropertyActions', () => { expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - await userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await user.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( @@ -57,10 +70,10 @@ describe('AlertPropertyActions', () => { expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - await userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await user.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - await userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + await user.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); @@ -73,14 +86,14 @@ describe('AlertPropertyActions', () => { expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - await userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await user.click(await screen.findByTestId('property-actions-user-action-ellipses')); await waitForEuiPopoverOpen(); - await userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + await user.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - await userEvent.click(await screen.findByText('Remove')); + await user.click(await screen.findByText('Remove')); await waitFor(() => { expect(props.onDelete).toHaveBeenCalled();