From 5acbb8d6a9283f587d4af02ccf2a75e42322a477 Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Fri, 23 Aug 2024 15:36:17 +0100 Subject: [PATCH 1/6] clear query cache for flaky tests --- .../components/all_cases/columns_popover.test.tsx | 10 +++++++++- .../public/components/all_cases/use_actions.test.tsx | 10 +++++++++- .../components/case_form_fields/severity.test.tsx | 10 +++++++++- .../case_form_fields/sync_alerts_toggle.test.tsx | 10 +++++++++- .../case_view/components/case_view_files.test.tsx | 11 ++++++++--- .../case_view/components/custom_fields.test.tsx | 11 ++++++++--- .../components/connector_selector/form.test.tsx | 12 ++++++++++-- .../cases/public/components/create/template.test.tsx | 10 +++++++++- .../components/custom_fields/form_fields.test.tsx | 10 +++++++++- .../public/components/description/index.test.tsx | 10 +++++++++- .../components/files/file_attachment_event.test.tsx | 12 ++++++++++-- .../public/components/files/file_preview.test.tsx | 10 +++++++++- .../cases/public/components/files/file_type.test.tsx | 12 ++++++++++-- .../public/components/filter_popover/index.test.tsx | 10 +++++++++- .../editable_markdown_renderer.test.tsx | 10 +++++++++- .../components/templates/template_fields.test.tsx | 10 +++++++++- .../components/templates/template_tags.test.tsx | 10 +++++++++- .../property_actions/alert_property_actions.test.tsx | 12 ++++++++++-- .../registered_attachments_property_actions.test.tsx | 10 +++++++++- .../user_comment_property_actions.test.tsx | 10 +++++++++- .../user_profiles/use_bulk_get_user_profiles.test.ts | 11 ++++++++++- 21 files changed, 192 insertions(+), 29 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 4d6eb887c86d5..7fd987383f567 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 @@ -15,7 +15,7 @@ import { createAppMockRenderer } from '../../common/mock'; import { ColumnsPopover } from './columns_popover'; // FLAKY: https://github.com/elastic/kibana/issues/174682 -describe.skip('ColumnsPopover', () => { +describe('ColumnsPopover', () => { let appMockRenderer: AppMockRenderer; beforeEach(() => { @@ -23,6 +23,14 @@ describe.skip('ColumnsPopover', () => { jest.clearAllMocks(); }); + afterEach(async () => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); + const selectedColumns = [ { field: 'title', name: 'Title', isChecked: true }, { field: 'category', name: 'Category', isChecked: false }, diff --git a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx index 4335d24910f39..edd4ad92802bf 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx @@ -29,7 +29,7 @@ jest.mock('../../containers/api'); jest.mock('../../containers/user_profiles/api'); // FLAKY: https://github.com/elastic/kibana/issues/188361 -describe.skip('useActions', () => { +describe('useActions', () => { let appMockRender: AppMockRenderer; beforeEach(() => { @@ -37,6 +37,14 @@ describe.skip('useActions', () => { jest.clearAllMocks(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders column actions', async () => { const { result } = renderHook(() => useActions({ disableActions: false }), { wrapper: appMockRender.AppWrapper, diff --git a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx index 8251e0a1f18fa..cfec8e298da71 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx @@ -17,13 +17,21 @@ import { FormTestComponent } from '../../common/test_utils'; const onSubmit = jest.fn(); // FLAKY: https://github.com/elastic/kibana/issues/188951 -describe.skip('Severity form field', () => { +describe('Severity form field', () => { let appMockRender: AppMockRenderer; beforeEach(() => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders', async () => { appMockRender.render( diff --git a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx index 01a688c474241..74d4ff3ac39c5 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx @@ -15,7 +15,7 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; // Failing: See https://github.com/elastic/kibana/issues/190270 -describe.skip('SyncAlertsToggle', () => { +describe('SyncAlertsToggle', () => { let appMockRender: AppMockRenderer; const onSubmit = jest.fn(); const defaultFormProps = { @@ -31,6 +31,14 @@ describe.skip('SyncAlertsToggle', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('it renders', async () => { appMockRender.render( diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx index d092114bde964..609e29f38ec27 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx @@ -27,7 +27,7 @@ const caseData: CaseUI = { }; // FLAKY: https://github.com/elastic/kibana/issues/185046 -describe.skip('Case View Page files tab', () => { +describe('Case View Page files tab', () => { let appMockRender: AppMockRenderer; useGetCaseFilesMock.mockReturnValue({ @@ -37,10 +37,15 @@ describe.skip('Case View Page files tab', () => { beforeEach(() => { appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); }); - afterEach(() => { - jest.clearAllMocks(); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); }); it('should render the utility bar for the files table', async () => { diff --git a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx index c0779043ec148..d8fa7d0d5aeec 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx @@ -16,16 +16,21 @@ import { customFieldsMock, customFieldsConfigurationMock } from '../../../contai import userEvent from '@testing-library/user-event'; import { CustomFieldTypes } from '../../../../common/types/domain'; -describe.skip('Case View Page files tab', () => { +describe('Case View Page files tab', () => { const onSubmit = jest.fn(); let appMockRender: AppMockRenderer; beforeEach(() => { appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); }); - afterEach(() => { - jest.clearAllMocks(); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); }); it('should render the custom fields correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index 508af2099b913..d969256357a20 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { screen } from '@testing-library/react'; +import { screen, waitFor } from '@testing-library/react'; import { ConnectorSelector } from './form'; import { useKibana } from '../../common/lib/kibana'; import type { AppMockRenderer } from '../../common/mock'; @@ -20,7 +20,7 @@ jest.mock('../../common/lib/kibana'); const useKibanaMock = useKibana as jest.Mocked; // FLAKY: https://github.com/elastic/kibana/issues/189530 -describe.skip('ConnectorSelector', () => { +describe('ConnectorSelector', () => { const handleChange = jest.fn(); const defaultProps = { connectors: [], @@ -45,6 +45,14 @@ describe.skip('ConnectorSelector', () => { }); }); + afterEach(async () => { + appMock.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); + it('should render', async () => { appMock.render( diff --git a/x-pack/plugins/cases/public/components/create/template.test.tsx b/x-pack/plugins/cases/public/components/create/template.test.tsx index 837b87827e591..86942f4b229cb 100644 --- a/x-pack/plugins/cases/public/components/create/template.test.tsx +++ b/x-pack/plugins/cases/public/components/create/template.test.tsx @@ -14,7 +14,7 @@ import { templatesConfigurationMock } from '../../containers/mock'; import { TemplateSelector } from './templates'; // FLAKY: https://github.com/elastic/kibana/issues/178457 -describe.skip('CustomFields', () => { +describe('CustomFields', () => { let appMockRender: AppMockRenderer; const onTemplateChange = jest.fn(); @@ -23,6 +23,14 @@ describe.skip('CustomFields', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders correctly', async () => { appMockRender.render( { +describe('FormFields ', () => { let appMockRender: AppMockRenderer; const onSubmit = jest.fn(); @@ -25,6 +25,14 @@ describe.skip('FormFields ', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders correctly', async () => { appMockRender.render( diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index 05f2477eda715..84c9f27cce0d2 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -28,7 +28,7 @@ const defaultProps = { }; // Failing: See https://github.com/elastic/kibana/issues/185879 -describe.skip('Description', () => { +describe('Description', () => { const onUpdateField = jest.fn(); let appMockRender: AppMockRenderer; @@ -37,6 +37,14 @@ describe.skip('Description', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders description correctly', async () => { appMockRender.render(); diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index 48ab9c3c669af..0b9fea203fa7d 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { screen } from '@testing-library/react'; +import { screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../common/mock'; @@ -17,7 +17,7 @@ import { basicFileMock } from '../../containers/mock'; import { FileAttachmentEvent } from './file_attachment_event'; // FLAKY: https://github.com/elastic/kibana/issues/174661 -describe.skip('FileAttachmentEvent', () => { +describe('FileAttachmentEvent', () => { let appMockRender: AppMockRenderer; beforeEach(() => { @@ -25,6 +25,14 @@ describe.skip('FileAttachmentEvent', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders clickable name', async () => { appMockRender.render( diff --git a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx index 8f24a9073c9be..952c919993e13 100644 --- a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx @@ -17,7 +17,7 @@ import { basicFileMock } from '../../containers/mock'; import { FilePreview } from './file_preview'; // FLAKY: https://github.com/elastic/kibana/issues/182364 -describe.skip('FilePreview', () => { +describe('FilePreview', () => { let appMockRender: AppMockRenderer; beforeEach(() => { @@ -25,6 +25,14 @@ describe.skip('FilePreview', () => { appMockRender = createAppMockRenderer(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('FilePreview rendered correctly', async () => { appMockRender.render(); diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index 242fb2fa6af09..b052ce16079f7 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -6,7 +6,7 @@ */ import type { JsonValue } from '@kbn/utility-types'; import userEvent from '@testing-library/user-event'; -import { screen } from '@testing-library/react'; +import { screen, waitFor } from '@testing-library/react'; import type { ExternalReferenceAttachmentViewProps } from '../../client/attachment_framework/types'; import type { AppMockRenderer } from '../../common/mock'; @@ -18,7 +18,7 @@ import { getFileType } from './file_type'; import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; // FLAKY: https://github.com/elastic/kibana/issues/175841 -describe.skip('getFileType', () => { +describe('getFileType', () => { const fileType = getFileType(); it('invalid props return blank FileAttachmentViewObject', () => { @@ -45,6 +45,14 @@ describe.skip('getFileType', () => { jest.clearAllMocks(); }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('event renders a clickable name if the file is an image', async () => { appMockRender = createAppMockRenderer(); diff --git a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx index c79705f109a74..b9b7c4d648cc1 100644 --- a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx +++ b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx @@ -16,7 +16,7 @@ import { createAppMockRenderer } from '../../common/mock'; import { FilterPopover } from '.'; // FLAKY: https://github.com/elastic/kibana/issues/176679 -describe.skip('FilterPopover ', () => { +describe('FilterPopover ', () => { let appMockRender: AppMockRenderer; const onSelectedOptionsChanged = jest.fn(); const tags: string[] = ['coke', 'pepsi']; @@ -26,6 +26,14 @@ describe.skip('FilterPopover ', () => { jest.clearAllMocks(); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('renders button label correctly', async () => { appMockRender.render( { +describe('EditableMarkdown', () => { let appMockRender: AppMockRenderer; beforeEach(() => { @@ -74,6 +74,14 @@ describe.skip('EditableMarkdown', () => { sessionStorage.removeItem(draftStorageKey); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { appMockRender.render(); diff --git a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx index 19efd1a8643bf..404cd3543b729 100644 --- a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx @@ -14,7 +14,7 @@ import { FormTestComponent } from '../../common/test_utils'; import { TemplateFields } from './template_fields'; // FLAKY: https://github.com/elastic/kibana/issues/187854 -describe.skip('Template fields', () => { +describe('Template fields', () => { let appMockRenderer: AppMockRenderer; const onSubmit = jest.fn(); const formDefaultValue = { templateTags: [] }; @@ -28,6 +28,14 @@ describe.skip('Template fields', () => { appMockRenderer = createAppMockRenderer(); }); + afterEach(async () => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); + it('renders template fields correctly', async () => { appMockRenderer.render( diff --git a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx index ed94b28d80d5e..922df965ea7de 100644 --- a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx @@ -16,7 +16,7 @@ import { TemplateTags } from './template_tags'; import { showEuiComboBoxOptions } from '@elastic/eui/lib/test/rtl'; // FLAKY: https://github.com/elastic/kibana/issues/189293 -describe.skip('TemplateTags', () => { +describe('TemplateTags', () => { let appMockRenderer: AppMockRenderer; const onSubmit = jest.fn(); const formDefaultValue = { templateTags: [] }; @@ -26,6 +26,14 @@ describe.skip('TemplateTags', () => { appMockRenderer = createAppMockRenderer(); }); + afterEach(async () => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); + it('renders template tags', async () => { appMockRenderer.render( 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 64dfa08944ea1..13fd336ca967e 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 @@ -7,7 +7,7 @@ import React from 'react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; -import { waitFor, screen } from '@testing-library/react'; +import { waitFor, screen, act } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { @@ -18,7 +18,7 @@ import { import { AlertPropertyActions } from './alert_property_actions'; // FLAKY: https://github.com/elastic/kibana/issues/174667 -describe.skip('AlertPropertyActions', () => { +describe('AlertPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -32,6 +32,14 @@ describe.skip('AlertPropertyActions', () => { appMock = createAppMockRenderer(); }); + afterEach(async () => { + appMock.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); + it('renders the correct number of actions', async () => { appMock.render(); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index a1f407a1c98cd..9a041b4feb327 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -19,7 +19,7 @@ import { RegisteredAttachmentsPropertyActions } from './registered_attachments_p import { AttachmentActionType } from '../../../client/attachment_framework/types'; // Failing: See https://github.com/elastic/kibana/issues/174384 -describe.skip('RegisteredAttachmentsPropertyActions', () => { +describe('RegisteredAttachmentsPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -34,6 +34,14 @@ describe.skip('RegisteredAttachmentsPropertyActions', () => { appMock = createAppMockRenderer(); }); + afterEach(async () => { + appMock.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); + it('renders the correct number of actions', async () => { appMock.render(); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index c24d26fa3b283..ccad2f74f3772 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -18,7 +18,7 @@ import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; // FLAKY: https://github.com/elastic/kibana/issues/175310 -describe.skip('UserCommentPropertyActions', () => { +describe('UserCommentPropertyActions', () => { let appMock: AppMockRenderer; const props = { @@ -33,6 +33,14 @@ describe.skip('UserCommentPropertyActions', () => { jest.clearAllMocks(); }); + afterEach(async () => { + appMock.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); + it('renders the correct number of actions', async () => { appMock.render(); diff --git a/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts b/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts index 4edc105b8d349..63bd94d55763b 100644 --- a/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts +++ b/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts @@ -13,6 +13,7 @@ import * as api from './api'; import { useBulkGetUserProfiles } from './use_bulk_get_user_profiles'; import { userProfilesIds } from './api.mock'; import { createStartServicesMock } from '../../common/lib/kibana/kibana_react.mock'; +import { waitFor } from '@testing-library/react'; jest.mock('../../common/lib/kibana'); jest.mock('./api'); @@ -20,7 +21,7 @@ jest.mock('./api'); const useKibanaMock = useKibana as jest.Mock; // FLAKY: https://github.com/elastic/kibana/issues/176335 -describe.skip('useBulkGetUserProfiles', () => { +describe('useBulkGetUserProfiles', () => { const props = { uids: userProfilesIds, }; @@ -38,6 +39,14 @@ describe.skip('useBulkGetUserProfiles', () => { }); }); + afterEach(async () => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + it('calls bulkGetUserProfiles with correct arguments', async () => { const spyOnBulkGetUserProfiles = jest.spyOn(api, 'bulkGetUserProfiles'); From 9c2f288647f5695086313ea4cb5499b8505b737c Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Fri, 23 Aug 2024 16:57:29 +0100 Subject: [PATCH 2/6] Loop all flaky tests --- .../all_cases/columns_popover.test.tsx | 306 ++++++------ .../components/all_cases/use_actions.test.tsx | 470 +++++++++--------- .../case_form_fields/severity.test.tsx | 108 ++-- .../sync_alerts_toggle.test.tsx | 120 ++--- .../components/case_view_files.test.tsx | 134 ++--- .../components/custom_fields.test.tsx | 418 ++++++++-------- .../connector_selector/form.test.tsx | 142 +++--- .../components/create/template.test.tsx | 118 ++--- .../custom_fields/form_fields.test.tsx | 106 ++-- .../components/description/index.test.tsx | 206 ++++---- .../files/file_attachment_event.test.tsx | 44 +- .../components/files/file_preview.test.tsx | 74 +-- .../components/files/file_type.test.tsx | 275 +++++----- .../components/filter_popover/index.test.tsx | 303 +++++------ .../editable_markdown_renderer.test.tsx | 236 ++++----- .../templates/template_fields.test.tsx | 234 ++++----- .../templates/template_tags.test.tsx | 192 +++---- .../alert_property_actions.test.tsx | 128 ++--- ...ered_attachments_property_actions.test.tsx | 186 +++---- .../user_comment_property_actions.test.tsx | 148 +++--- .../use_bulk_get_user_profiles.test.ts | 11 +- 21 files changed, 2007 insertions(+), 1952 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 7fd987383f567..dda96100a2012 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 @@ -15,190 +15,194 @@ import { createAppMockRenderer } from '../../common/mock'; import { ColumnsPopover } from './columns_popover'; // FLAKY: https://github.com/elastic/kibana/issues/174682 -describe('ColumnsPopover', () => { - let appMockRenderer: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('ColumnsPopover', () => { + let appMockRenderer: AppMockRenderer; - beforeEach(() => { - appMockRenderer = createAppMockRenderer(); - jest.clearAllMocks(); - }); + beforeEach(() => { + appMockRenderer = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - const selectedColumns = [ - { field: 'title', name: 'Title', isChecked: true }, - { field: 'category', name: 'Category', isChecked: false }, - { field: 'tags', name: 'Tags', isChecked: false }, - ]; + 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( - {}} /> - ); + it('renders correctly a list of selected columns', 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(); - expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); + expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); - selectedColumns.forEach(({ field, name, isChecked }) => { - expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( - 'aria-checked', - isChecked.toString() - ); - expect(screen.getByText(name)).toBeInTheDocument(); + selectedColumns.forEach(({ field, name, isChecked }) => { + expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( + 'aria-checked', + isChecked.toString() + ); + expect(screen.getByText(name)).toBeInTheDocument(); + }); }); - }); - 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 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 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 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 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 })) + 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 })) + ); + }); }); - }); - 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(); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx index edd4ad92802bf..e17a3ab9fcb1b 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx @@ -29,28 +29,29 @@ jest.mock('../../containers/api'); jest.mock('../../containers/user_profiles/api'); // FLAKY: https://github.com/elastic/kibana/issues/188361 -describe('useActions', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('useActions', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - it('renders column actions', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); }); - expect(result.current).toMatchInlineSnapshot(` + it('renders column actions', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); + + expect(result.current).toMatchInlineSnapshot(` Object { "actions": Object { "align": "right", @@ -60,123 +61,65 @@ describe('useActions', () => { }, } `); - }); - - it('renders the popover', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - expect(res.getByTestId(`case-action-popover-${basicCase.id}`)).toBeInTheDocument(); - }); - - it('open the action popover', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); - - expect(res.getByText('Actions')).toBeInTheDocument(); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); - }); - - it('change the status of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); - - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); - - userEvent.click(res.getByTestId(`case-action-status-panel-${basicCase.id}`)); - await waitForEuiContextMenuPanelTransition(); - - expect(res.getByTestId('cases-bulk-action-status-open')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-status-in-progress')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-status-closed')).toBeInTheDocument(); - - userEvent.click(res.getByTestId('cases-bulk-action-status-in-progress')); - - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); - }); + it('renders the popover', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - it('change the severity of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, + expect(res.getByTestId(`case-action-popover-${basicCase.id}`)).toBeInTheDocument(); }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); - - userEvent.click(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)); - await waitForEuiContextMenuPanelTransition(); + it('open the action popover', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - expect(res.getByTestId('cases-bulk-action-severity-low')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-medium')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-high')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-critical')).toBeInTheDocument(); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - userEvent.click(res.getByTestId('cases-bulk-action-severity-medium')); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); + expect(res.getByText('Actions')).toBeInTheDocument(); + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); }); - }); - it('copies the case id to the clipboard', async () => { - const originalClipboard = global.window.navigator.clipboard; + it('change the status of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - Object.defineProperty(navigator, 'clipboard', { - value: { - writeText: jest.fn().mockImplementation(() => Promise.resolve()), - }, - writable: true, - }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + userEvent.click(res.getByTestId(`case-action-status-panel-${basicCase.id}`)); + await waitForEuiContextMenuPanelTransition(); - userEvent.click(res.getByTestId('cases-action-copy-id')); + expect(res.getByTestId('cases-bulk-action-status-open')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-status-in-progress')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-status-closed')).toBeInTheDocument(); - expect(navigator.clipboard.writeText).toHaveBeenCalledWith(basicCase.id); + userEvent.click(res.getByTestId('cases-bulk-action-status-in-progress')); - Object.defineProperty(navigator, 'clipboard', { - value: originalClipboard, + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); }); - }); - describe('Modals', () => { - it('delete a case', async () => { - const deleteSpy = jest.spyOn(api, 'deleteCases'); + it('change the severity of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); const { result } = renderHook(() => useActions({ disableActions: false }), { wrapper: appMockRender.AppWrapper, @@ -188,20 +131,31 @@ describe('useActions', () => { userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('cases-bulk-action-delete')); + userEvent.click(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)); + await waitForEuiContextMenuPanelTransition(); - await waitFor(() => { - expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); - }); + expect(res.getByTestId('cases-bulk-action-severity-low')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-medium')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-high')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-critical')).toBeInTheDocument(); - userEvent.click(res.getByTestId('confirmModalConfirmButton')); + userEvent.click(res.getByTestId('cases-bulk-action-severity-medium')); await waitFor(() => { - expect(deleteSpy).toHaveBeenCalled(); + expect(updateCasesSpy).toHaveBeenCalled(); }); }); - it('closes the modal', async () => { + it('copies the case id to the clipboard', async () => { + const originalClipboard = global.window.navigator.clipboard; + + Object.defineProperty(navigator, 'clipboard', { + value: { + writeText: jest.fn().mockImplementation(() => Promise.resolve()), + }, + writable: true, + }); + const { result } = renderHook(() => useActions({ disableActions: false }), { wrapper: appMockRender.AppWrapper, }); @@ -212,169 +166,217 @@ describe('useActions', () => { userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('cases-bulk-action-delete')); + userEvent.click(res.getByTestId('cases-action-copy-id')); - await waitFor(() => { - expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); + expect(navigator.clipboard.writeText).toHaveBeenCalledWith(basicCase.id); + + Object.defineProperty(navigator, 'clipboard', { + value: originalClipboard, }); + }); - userEvent.click(res.getByTestId('confirmModalCancelButton')); + describe('Modals', () => { + it('delete a case', async () => { + const deleteSpy = jest.spyOn(api, 'deleteCases'); - expect(res.queryByTestId('confirm-delete-case-modal')).toBeFalsy(); - }); - }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - describe('Flyouts', () => { - it('change the tags of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId('cases-bulk-action-delete')); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + await waitFor(() => { + expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); + }); - userEvent.click(res.getByTestId('cases-bulk-action-tags')); + userEvent.click(res.getByTestId('confirmModalConfirmButton')); - await waitFor(() => { - expect(res.getByTestId('cases-edit-tags-flyout')).toBeInTheDocument(); + await waitFor(() => { + expect(deleteSpy).toHaveBeenCalled(); + }); }); - await waitFor(() => { - expect(res.getByText('coke')).toBeInTheDocument(); - }); + it('closes the modal', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - userEvent.click(res.getByText('coke')); - userEvent.click(res.getByTestId('cases-edit-tags-flyout-submit')); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - await waitFor(() => { - expect(res.queryByTestId('cases-edit-tags-flyout')).toBeFalsy(); + userEvent.click(res.getByTestId('cases-bulk-action-delete')); + + await waitFor(() => { + expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); + }); + + userEvent.click(res.getByTestId('confirmModalCancelButton')); + + expect(res.queryByTestId('confirm-delete-case-modal')).toBeFalsy(); }); }); - it('change the assignees of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); + describe('Flyouts', () => { + it('change the tags of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('cases-bulk-action-assignees')); + userEvent.click(res.getByTestId('cases-bulk-action-tags')); - await waitFor(() => { - expect(res.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); - }); + await waitFor(() => { + expect(res.getByTestId('cases-edit-tags-flyout')).toBeInTheDocument(); + }); - await waitFor(() => { - expect(res.getByText('Damaged Raccoon')).toBeInTheDocument(); - }); + await waitFor(() => { + expect(res.getByText('coke')).toBeInTheDocument(); + }); - userEvent.click(res.getByText('Damaged Raccoon')); - userEvent.click(res.getByTestId('cases-edit-assignees-flyout-submit')); + userEvent.click(res.getByText('coke')); + userEvent.click(res.getByTestId('cases-edit-tags-flyout-submit')); - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); - await waitFor(() => { - expect(res.queryByTestId('cases-edit-assignees-flyout')).toBeFalsy(); + await waitFor(() => { + expect(res.queryByTestId('cases-edit-tags-flyout')).toBeFalsy(); + }); }); - }); - }); - describe('Permissions', () => { - it('shows the correct actions with all permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: allCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + it('change the assignees of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.getByTestId(`actions-separator-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); + + userEvent.click(res.getByTestId('cases-bulk-action-assignees')); + + await waitFor(() => { + expect(res.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); + }); + + await waitFor(() => { + expect(res.getByText('Damaged Raccoon')).toBeInTheDocument(); + }); + + userEvent.click(res.getByText('Damaged Raccoon')); + userEvent.click(res.getByTestId('cases-edit-assignees-flyout-submit')); + + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); + + await waitFor(() => { + expect(res.queryByTestId('cases-edit-assignees-flyout')).toBeFalsy(); + }); + }); }); - it('shows the correct actions with no delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: noDeleteCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, + describe('Permissions', () => { + it('shows the correct actions with all permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: allCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); + + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); + + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); + + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.getByTestId(`actions-separator-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + it('shows the correct actions with no delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: noDeleteCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); - expect(res.queryByTestId('cases-bulk-action-delete')).toBeFalsy(); - expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - it('shows the correct actions with only delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + expect(res.queryByTestId('cases-bulk-action-delete')).toBeFalsy(); + expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + it('shows the correct actions with only delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - expect(res.queryByTestId(`case-action-status-panel-${basicCase.id}`)).toBeFalsy(); - expect(res.queryByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeFalsy(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - it('returns null if the user does not have update or delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, + expect(res.queryByTestId(`case-action-status-panel-${basicCase.id}`)).toBeFalsy(); + expect(res.queryByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeFalsy(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); }); - expect(result.current.actions).toBe(null); - }); + it('returns null if the user does not have update or delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - it('disables the action correctly', async () => { - appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - const { result } = renderHook(() => useActions({ disableActions: true }), { - wrapper: appMockRender.AppWrapper, + expect(result.current.actions).toBe(null); }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + it('disables the action correctly', async () => { + appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + const { result } = renderHook(() => useActions({ disableActions: true }), { + wrapper: appMockRender.AppWrapper, + }); - await waitFor(() => { - expect(res.getByTestId(`case-action-popover-button-${basicCase.id}`)).toBeDisabled(); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); + + await waitFor(() => { + expect(res.getByTestId(`case-action-popover-button-${basicCase.id}`)).toBeDisabled(); + }); }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx index cfec8e298da71..a00210f9852a0 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx @@ -17,73 +17,75 @@ import { FormTestComponent } from '../../common/test_utils'; const onSubmit = jest.fn(); // FLAKY: https://github.com/elastic/kibana/issues/188951 -describe('Severity form field', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('Severity form field', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders', async () => { - appMockRender.render( - - - - ); + it('renders', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - expect(await screen.findByTestId('case-severity-selection')).not.toHaveAttribute('disabled'); - }); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('case-severity-selection')).not.toHaveAttribute('disabled'); + }); - // default to LOW in this test configuration - it('defaults to the correct value', async () => { - appMockRender.render( - - - - ); + // default to LOW in this test configuration + it('defaults to the correct value', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - expect(await screen.findByTestId('case-severity-selection-low')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('case-severity-selection-low')).toBeInTheDocument(); + }); - it('selects the correct value when changed', async () => { - appMockRender.render( - - - - ); + it('selects the correct value when changed', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('case-severity-selection')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('case-severity-selection')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('case-severity-selection-high')); + userEvent.click(await screen.findByTestId('case-severity-selection-high')); - userEvent.click(await screen.findByTestId('form-test-component-submit-button')); + userEvent.click(await screen.findByTestId('form-test-component-submit-button')); - await waitFor(() => { - // data, isValid - expect(onSubmit).toBeCalledWith({ severity: 'high' }, true); + await waitFor(() => { + // data, isValid + expect(onSubmit).toBeCalledWith({ severity: 'high' }, true); + }); }); - }); - it('disables when loading data', async () => { - appMockRender.render( - - - - ); + it('disables when loading data', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('case-severity-selection')).toHaveAttribute('disabled'); + expect(await screen.findByTestId('case-severity-selection')).toHaveAttribute('disabled'); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx index 74d4ff3ac39c5..529bc21e92220 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx @@ -15,77 +15,79 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; // Failing: See https://github.com/elastic/kibana/issues/190270 -describe('SyncAlertsToggle', () => { - let appMockRender: AppMockRenderer; - const onSubmit = jest.fn(); - const defaultFormProps = { - onSubmit, - formDefaultValue: { syncAlerts: true }, - schema: { - syncAlerts: schema.syncAlerts, - }, - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); +for (let i = 0; i < 20; i++) { + describe('SyncAlertsToggle', () => { + let appMockRender: AppMockRenderer; + const onSubmit = jest.fn(); + const defaultFormProps = { + onSubmit, + formDefaultValue: { syncAlerts: true }, + schema: { + syncAlerts: schema.syncAlerts, + }, + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('it renders', async () => { - appMockRender.render( - - - - ); + it('it renders', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSyncAlerts')).toBeInTheDocument(); - expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'true'); - expect(await screen.findByText('On')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('caseSyncAlerts')).toBeInTheDocument(); + expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'true'); + expect(await screen.findByText('On')).toBeInTheDocument(); + }); - it('it toggles the switch', async () => { - appMockRender.render( - - - - ); + it('it toggles the switch', async () => { + appMockRender.render( + + + + ); - const synAlerts = await screen.findByTestId('caseSyncAlerts'); + const synAlerts = await screen.findByTestId('caseSyncAlerts'); - userEvent.click(within(synAlerts).getByRole('switch')); + userEvent.click(within(synAlerts).getByRole('switch')); - expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'false'); - expect(await screen.findByText('Off')).toBeInTheDocument(); - }); + expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'false'); + expect(await screen.findByText('Off')).toBeInTheDocument(); + }); - it('calls onSubmit with correct data', async () => { - appMockRender.render( - - - - ); + it('calls onSubmit with correct data', async () => { + appMockRender.render( + + + + ); - const synAlerts = await screen.findByTestId('caseSyncAlerts'); + const synAlerts = await screen.findByTestId('caseSyncAlerts'); - userEvent.click(within(synAlerts).getByRole('switch')); + userEvent.click(within(synAlerts).getByRole('switch')); - userEvent.click(screen.getByText('Submit')); + userEvent.click(screen.getByText('Submit')); - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - syncAlerts: false, - }, - true - ); + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + syncAlerts: false, + }, + true + ); + }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx index 609e29f38ec27..f224d2814a27d 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx @@ -27,94 +27,96 @@ const caseData: CaseUI = { }; // FLAKY: https://github.com/elastic/kibana/issues/185046 -describe('Case View Page files tab', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('Case View Page files tab', () => { + let appMockRender: AppMockRenderer; - useGetCaseFilesMock.mockReturnValue({ - data: { files: [], total: 11 }, - isLoading: false, - }); + useGetCaseFilesMock.mockReturnValue({ + data: { files: [], total: 11 }, + isLoading: false, + }); - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('should render the utility bar for the files table', async () => { - appMockRender.render(); + it('should render the utility bar for the files table', async () => { + appMockRender.render(); - expect((await screen.findAllByTestId('cases-files-add')).length).toBe(2); - expect(await screen.findByTestId('cases-files-search')).toBeInTheDocument(); - }); + expect((await screen.findAllByTestId('cases-files-add')).length).toBe(2); + expect(await screen.findByTestId('cases-files-search')).toBeInTheDocument(); + }); - it('should render the files table', async () => { - appMockRender.render(); + it('should render the files table', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + }); - it('clicking table pagination triggers calls to useGetCaseFiles', async () => { - appMockRender.render(); + it('clicking table pagination triggers calls to useGetCaseFiles', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('pagination-button-next')); + userEvent.click(await screen.findByTestId('pagination-button-next')); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page + 1, - perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, - }) - ); - }); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page + 1, + perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, + }) + ); + }); - it('changing perPage value triggers calls to useGetCaseFiles', async () => { - const targetPagination = 50; + it('changing perPage value triggers calls to useGetCaseFiles', async () => { + const targetPagination = 50; - appMockRender.render(); + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - userEvent.click(screen.getByTestId('tablePaginationPopoverButton')); + userEvent.click(screen.getByTestId('tablePaginationPopoverButton')); - const pageSizeOption = screen.getByTestId('tablePagination-50-rows'); + const pageSizeOption = screen.getByTestId('tablePagination-50-rows'); - pageSizeOption.style.pointerEvents = 'all'; + pageSizeOption.style.pointerEvents = 'all'; - userEvent.click(pageSizeOption); + userEvent.click(pageSizeOption); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, - perPage: targetPagination, - }) - ); - }); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, + perPage: targetPagination, + }) + ); + }); - it('search by word triggers calls to useGetCaseFiles', async () => { - appMockRender.render(); + it('search by word triggers calls to useGetCaseFiles', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - await userEvent.type(screen.getByTestId('cases-files-search'), 'Foobar{enter}'); + await userEvent.type(screen.getByTestId('cases-files-search'), 'Foobar{enter}'); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, - perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, - searchTerm: 'Foobar', - }) - ); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, + perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, + searchTerm: 'Foobar', + }) + ); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx index d8fa7d0d5aeec..361f2b040035e 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx @@ -16,238 +16,240 @@ import { customFieldsMock, customFieldsConfigurationMock } from '../../../contai import userEvent from '@testing-library/user-event'; import { CustomFieldTypes } from '../../../../common/types/domain'; -describe('Case View Page files tab', () => { - const onSubmit = jest.fn(); - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('Case View Page files tab', () => { + const onSubmit = jest.fn(); + let appMockRender: AppMockRenderer; + + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + it('should render the custom fields correctly', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_3')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_4')).toBeInTheDocument(); + }); - it('should render the custom fields correctly', async () => { - appMockRender.render( - - ); - - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_3')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_4')).toBeInTheDocument(); - }); + it('should render the custom fields types when the custom fields are empty', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); + }); - it('should render the custom fields types when the custom fields are empty', async () => { - appMockRender.render( - - ); - - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); - }); + it('should not show the custom fields if the configuration is empty', () => { + appMockRender.render( + + ); + + expect(screen.queryByTestId('case-custom-field-wrapper-test_key_1')).not.toBeInTheDocument(); + expect(screen.queryByTestId('case-custom-field-wrapper-test_key_2')).not.toBeInTheDocument(); + }); - it('should not show the custom fields if the configuration is empty', () => { - appMockRender.render( - - ); - - expect(screen.queryByTestId('case-custom-field-wrapper-test_key_1')).not.toBeInTheDocument(); - expect(screen.queryByTestId('case-custom-field-wrapper-test_key_2')).not.toBeInTheDocument(); - }); + it('should sort the custom fields correctly', async () => { + const reversedConfiguration = [...customFieldsConfigurationMock].reverse(); - it('should sort the custom fields correctly', async () => { - const reversedConfiguration = [...customFieldsConfigurationMock].reverse(); + appMockRender.render( + + ); - appMockRender.render( - - ); + const customFields = await screen.findAllByTestId('case-custom-field-wrapper', { + exact: false, + }); - const customFields = await screen.findAllByTestId('case-custom-field-wrapper', { - exact: false, + expect(customFields.length).toBe(4); + + expect(await within(customFields[0]).findByRole('heading')).toHaveTextContent( + 'My test label 1' + ); + expect(await within(customFields[1]).findByRole('heading')).toHaveTextContent( + 'My test label 2' + ); + expect(await within(customFields[2]).findByRole('heading')).toHaveTextContent( + 'My test label 3' + ); + expect(await within(customFields[3]).findByRole('heading')).toHaveTextContent( + 'My test label 4' + ); }); - expect(customFields.length).toBe(4); - - expect(await within(customFields[0]).findByRole('heading')).toHaveTextContent( - 'My test label 1' - ); - expect(await within(customFields[1]).findByRole('heading')).toHaveTextContent( - 'My test label 2' - ); - expect(await within(customFields[2]).findByRole('heading')).toHaveTextContent( - 'My test label 3' - ); - expect(await within(customFields[3]).findByRole('heading')).toHaveTextContent( - 'My test label 4' - ); - }); - - it('pass the permissions to custom fields correctly', async () => { - appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); - - appMockRender.render( - - ); - - expect( - screen.queryByTestId('case-text-custom-field-edit-button-test_key_1') - ).not.toBeInTheDocument(); - }); + it('pass the permissions to custom fields correctly', async () => { + appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); + + appMockRender.render( + + ); + + expect( + screen.queryByTestId('case-text-custom-field-edit-button-test_key_1') + ).not.toBeInTheDocument(); + }); - it('removes extra custom fields', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByRole('switch')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: false, + it('removes extra custom fields', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByRole('switch')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: false, + }); }); }); - }); - it('updates an existing toggle field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click((await screen.findAllByRole('switch'))[0]); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: false, + it('updates an existing toggle field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click((await screen.findAllByRole('switch'))[0]); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: false, + }); }); }); - }); - it('updates new toggle field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click((await screen.findAllByRole('switch'))[0]); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: true, + it('updates new toggle field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click((await screen.findAllByRole('switch'))[0]); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: true, + }); }); }); - }); - it('updates existing text field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click( - await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) - ); - - userEvent.paste( - await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), - '!!!' - ); - - userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - ...customFieldsMock[0], - value: 'My text test value 1!!!', + it('updates existing text field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click( + await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) + ); + + userEvent.paste( + await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), + '!!!' + ); + + userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + ...customFieldsMock[0], + value: 'My text test value 1!!!', + }); }); }); - }); - it('updates new text field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click( - await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) - ); - - expect( - await screen.findByText('This field is populated with the default value.') - ).toBeInTheDocument(); - - userEvent.paste( - await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), - ' updated!!' - ); - - userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - ...customFieldsMock[0], - value: `${customFieldsConfigurationMock[0].defaultValue} updated!!`, + it('updates new text field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click( + await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) + ); + + expect( + await screen.findByText('This field is populated with the default value.') + ).toBeInTheDocument(); + + userEvent.paste( + await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), + ' updated!!' + ); + + userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + ...customFieldsMock[0], + value: `${customFieldsConfigurationMock[0].defaultValue} updated!!`, + }); }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index d969256357a20..cc3704442bba9 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -20,85 +20,89 @@ jest.mock('../../common/lib/kibana'); const useKibanaMock = useKibana as jest.Mocked; // FLAKY: https://github.com/elastic/kibana/issues/189530 -describe('ConnectorSelector', () => { - const handleChange = jest.fn(); - const defaultProps = { - connectors: [], - handleChange, - dataTestSubj: 'connectors', - disabled: false, - idAria: 'connectors', - isLoading: false, - }; +for (let i = 0; i < 20; i++) { + describe('ConnectorSelector', () => { + const handleChange = jest.fn(); + const defaultProps = { + connectors: [], + handleChange, + dataTestSubj: 'connectors', + disabled: false, + idAria: 'connectors', + isLoading: false, + }; - let appMock: AppMockRenderer; + let appMock: AppMockRenderer; - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - beforeEach(() => { - useKibanaMock().services.triggersActionsUi.actionTypeRegistry.get = jest.fn().mockReturnValue({ - actionTypeTitle: 'test', - iconClass: 'logoSecurity', + beforeEach(() => { + useKibanaMock().services.triggersActionsUi.actionTypeRegistry.get = jest + .fn() + .mockReturnValue({ + actionTypeTitle: 'test', + iconClass: 'logoSecurity', + }); }); - }); - afterEach(async () => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('should render', async () => { - appMock.render( - - - - ); + it('should render', async () => { + appMock.render( + + + + ); - expect(await screen.findByTestId(defaultProps.dataTestSubj)); - }); + expect(await screen.findByTestId(defaultProps.dataTestSubj)); + }); - it('should set the selected connector to none if the connector is not available', async () => { - appMock.render( - - - - ); + it('should set the selected connector to none if the connector is not available', async () => { + appMock.render( + + + + ); - expect(await screen.findByText('No connector selected')); - }); + expect(await screen.findByText('No connector selected')); + }); - it('should set the selected connector correctly', async () => { - appMock.render( - - - - ); + it('should set the selected connector correctly', async () => { + appMock.render( + + + + ); - expect(await screen.findByText(connectorsMock[0].name)); + expect(await screen.findByText(connectorsMock[0].name)); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/create/template.test.tsx b/x-pack/plugins/cases/public/components/create/template.test.tsx index 86942f4b229cb..b3b0424eae42f 100644 --- a/x-pack/plugins/cases/public/components/create/template.test.tsx +++ b/x-pack/plugins/cases/public/components/create/template.test.tsx @@ -14,76 +14,78 @@ import { templatesConfigurationMock } from '../../containers/mock'; import { TemplateSelector } from './templates'; // FLAKY: https://github.com/elastic/kibana/issues/178457 -describe('CustomFields', () => { - let appMockRender: AppMockRenderer; - const onTemplateChange = jest.fn(); +for (let i = 0; i < 20; i++) { + describe('CustomFields', () => { + let appMockRender: AppMockRenderer; + const onTemplateChange = jest.fn(); - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders correctly', async () => { - appMockRender.render( - - ); + it('renders correctly', async () => { + appMockRender.render( + + ); - expect(await screen.findByText('Template name')).toBeInTheDocument(); - expect(await screen.findByTestId('create-case-template-select')).toBeInTheDocument(); - }); + expect(await screen.findByText('Template name')).toBeInTheDocument(); + expect(await screen.findByTestId('create-case-template-select')).toBeInTheDocument(); + }); - it('selects a template correctly', async () => { - const selectedTemplate = templatesConfigurationMock[2]; + it('selects a template correctly', async () => { + const selectedTemplate = templatesConfigurationMock[2]; - appMockRender.render( - - ); + appMockRender.render( + + ); - userEvent.selectOptions( - await screen.findByTestId('create-case-template-select'), - selectedTemplate.key - ); + userEvent.selectOptions( + await screen.findByTestId('create-case-template-select'), + selectedTemplate.key + ); - await waitFor(() => { - expect(onTemplateChange).toHaveBeenCalledWith(selectedTemplate.caseFields); + await waitFor(() => { + expect(onTemplateChange).toHaveBeenCalledWith(selectedTemplate.caseFields); + }); }); - }); - it('shows the selected option correctly', async () => { - const selectedTemplate = templatesConfigurationMock[2]; + it('shows the selected option correctly', async () => { + const selectedTemplate = templatesConfigurationMock[2]; - appMockRender.render( - - ); + appMockRender.render( + + ); - userEvent.selectOptions( - await screen.findByTestId('create-case-template-select'), - selectedTemplate.key - ); + userEvent.selectOptions( + await screen.findByTestId('create-case-template-select'), + selectedTemplate.key + ); - expect( - (await screen.findByRole('option', { name: selectedTemplate.name })) - .selected - ).toBe(true); + expect( + (await screen.findByRole('option', { name: selectedTemplate.name })) + .selected + ).toBe(true); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx index b7a2fe7986ce3..50a7c25866e1c 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx @@ -16,68 +16,70 @@ import { CustomFieldTypes } from '../../../common/types/domain'; import { FormFields } from './form_fields'; // FLAKY: https://github.com/elastic/kibana/issues/188450 -describe('FormFields ', () => { - let appMockRender: AppMockRenderer; - const onSubmit = jest.fn(); +for (let i = 0; i < 20; i++) { + describe('FormFields ', () => { + let appMockRender: AppMockRenderer; + const onSubmit = jest.fn(); - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders correctly', async () => { - appMockRender.render( - - - - ); + it('renders correctly', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('custom-field-label-input')).toBeInTheDocument(); - expect(await screen.findByTestId('custom-field-type-selector')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('custom-field-label-input')).toBeInTheDocument(); + expect(await screen.findByTestId('custom-field-type-selector')).toBeInTheDocument(); + }); - it('disables field type selector on edit mode', async () => { - appMockRender.render( - - - - ); + it('disables field type selector on edit mode', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('custom-field-type-selector')).toHaveAttribute('disabled'); - }); + expect(await screen.findByTestId('custom-field-type-selector')).toHaveAttribute('disabled'); + }); - it('submit data correctly', async () => { - appMockRender.render( - - - - ); + it('submit data correctly', async () => { + appMockRender.render( + + + + ); - fireEvent.change(await screen.findByTestId('custom-field-type-selector'), { - target: { value: CustomFieldTypes.TOGGLE }, - }); + fireEvent.change(await screen.findByTestId('custom-field-type-selector'), { + target: { value: CustomFieldTypes.TOGGLE }, + }); - userEvent.type(await screen.findByTestId('custom-field-label-input'), 'hello'); - userEvent.click(await screen.findByText('Submit')); + userEvent.type(await screen.findByTestId('custom-field-label-input'), 'hello'); + userEvent.click(await screen.findByText('Submit')); - await waitFor(() => { - // data, isValid - expect(onSubmit).toBeCalledWith( - { - label: 'hello', - type: CustomFieldTypes.TOGGLE, - defaultValue: false, - }, - true - ); + await waitFor(() => { + // data, isValid + expect(onSubmit).toBeCalledWith( + { + label: 'hello', + type: CustomFieldTypes.TOGGLE, + defaultValue: false, + }, + true + ); + }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index 84c9f27cce0d2..fd1e2b8e48077 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -28,150 +28,156 @@ const defaultProps = { }; // Failing: See https://github.com/elastic/kibana/issues/185879 -describe('Description', () => { - const onUpdateField = jest.fn(); - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('Description', () => { + const onUpdateField = jest.fn(); + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders description correctly', async () => { - appMockRender.render(); + it('renders description correctly', async () => { + appMockRender.render(); - expect(await screen.findByTestId('description')).toBeInTheDocument(); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('description')).toBeInTheDocument(); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - it('hides and shows the description correctly when collapse button clicked', async () => { - appMockRender.render(); + it('hides and shows the description correctly when collapse button clicked', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); - await waitFor(() => { - expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument(); - }); + await waitFor(() => { + expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument(); + }); - userEvent.click(await screen.findByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - }); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - it('shows textarea on edit click', async () => { - appMockRender.render(); + it('shows textarea on edit click', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument(); + }); - it('edits the description correctly when saved', async () => { - const editedDescription = 'New updated description'; - appMockRender.render(); + it('edits the description correctly when saved', async () => { + const editedDescription = 'New updated description'; + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + userEvent.click(await screen.findByTestId('editable-save-markdown')); - await waitFor(() => { - expect(onUpdateField).toHaveBeenCalledWith({ - key: 'description', - value: editedDescription, + await waitFor(() => { + expect(onUpdateField).toHaveBeenCalledWith({ + key: 'description', + value: editedDescription, + }); }); }); - }); - - it('keeps the old description correctly when canceled', async () => { - const editedDescription = 'New updated description'; - appMockRender.render(); - - userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); + it('keeps the old description correctly when canceled', async () => { + const editedDescription = 'New updated description'; + appMockRender.render(); - expect(await screen.findByText(editedDescription)).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.click(await screen.findByTestId('editable-cancel-markdown')); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - await waitFor(() => { - expect(onUpdateField).not.toHaveBeenCalled(); - }); - - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - }); + expect(await screen.findByText(editedDescription)).toBeInTheDocument(); - it('shows an error when description is too long', async () => { - const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1); + userEvent.click(await screen.findByTestId('editable-cancel-markdown')); - appMockRender.render(); - - userEvent.click(await screen.findByTestId('description-edit-icon')); + await waitFor(() => { + expect(onUpdateField).not.toHaveBeenCalled(); + }); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - expect( - await screen.findByText( - 'The length of the description is too long. The maximum length is 30000 characters.' - ) - ).toBeInTheDocument(); + it('shows an error when description is too long', async () => { + const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1); - expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled'); - }); + appMockRender.render(); - it('should hide the edit button when the user does not have update permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() }); - appMockRender.render(); + userEvent.click(await screen.findByTestId('description-edit-icon')); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument(); - }); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription); - it('should display description when case is loading', async () => { - appMockRender.render( - - ); + expect( + await screen.findByText( + 'The length of the description is too long. The maximum length is 30000 characters.' + ) + ).toBeInTheDocument(); - expect(await screen.findByTestId('description')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled'); + }); - describe('draft message', () => { - const draftStorageKey = `cases.securitySolution.basic-case-id.description.markdownEditor`; + it('should hide the edit button when the user does not have update permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() }); + appMockRender.render(); - beforeEach(() => { - sessionStorage.setItem(draftStorageKey, 'value set in storage'); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument(); }); - it('should not show unsaved draft message when loading', async () => { + it('should display description when case is loading', async () => { appMockRender.render( ); - expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); + expect(await screen.findByTestId('description')).toBeInTheDocument(); }); - it('should not show unsaved draft message when description and storage value are same', async () => { - const props = { - ...defaultProps, - caseData: { ...defaultProps.caseData, description: 'value set in storage' }, - }; + describe('draft message', () => { + const draftStorageKey = `cases.securitySolution.basic-case-id.description.markdownEditor`; - appMockRender.render(); + beforeEach(() => { + sessionStorage.setItem(draftStorageKey, 'value set in storage'); + }); - expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); + it('should not show unsaved draft message when loading', async () => { + appMockRender.render( + + ); + + expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); + }); + + it('should not show unsaved draft message when description and storage value are same', async () => { + const props = { + ...defaultProps, + caseData: { ...defaultProps.caseData, description: 'value set in storage' }, + }; + + appMockRender.render(); + + expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); + }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index 0b9fea203fa7d..27af4e258bda7 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -17,33 +17,35 @@ import { basicFileMock } from '../../containers/mock'; import { FileAttachmentEvent } from './file_attachment_event'; // FLAKY: https://github.com/elastic/kibana/issues/174661 -describe('FileAttachmentEvent', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('FileAttachmentEvent', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders clickable name', async () => { - appMockRender.render( - - ); + it('renders clickable name', async () => { + appMockRender.render( + + ); - const nameLink = await screen.findByTestId('cases-files-name-link'); + const nameLink = await screen.findByTestId('cases-files-name-link'); - expect(nameLink).toBeInTheDocument(); + expect(nameLink).toBeInTheDocument(); - userEvent.click(nameLink); + userEvent.click(nameLink); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx index 952c919993e13..bae3fd984eb08 100644 --- a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx @@ -17,51 +17,55 @@ import { basicFileMock } from '../../containers/mock'; import { FilePreview } from './file_preview'; // FLAKY: https://github.com/elastic/kibana/issues/182364 -describe('FilePreview', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('FilePreview', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('FilePreview rendered correctly', async () => { - appMockRender.render(); + it('FilePreview rendered correctly', async () => { + appMockRender.render(); - await waitFor(() => - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - id: basicFileMock.id, - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - }) - ); + await waitFor(() => + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + id: basicFileMock.id, + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + }) + ); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + }); - it('pressing escape calls closePreview', async () => { - const closePreview = jest.fn(); + it('pressing escape calls closePreview', async () => { + const closePreview = jest.fn(); - appMockRender.render(); + appMockRender.render( + + ); - await waitFor(() => - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - id: basicFileMock.id, - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - }) - ); + await waitFor(() => + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + id: basicFileMock.id, + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + }) + ); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - userEvent.keyboard('{esc}'); + userEvent.keyboard('{esc}'); - await waitFor(() => expect(closePreview).toHaveBeenCalled()); + await waitFor(() => expect(closePreview).toHaveBeenCalled()); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index b052ce16079f7..360b3cd496b1e 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -18,183 +18,188 @@ import { getFileType } from './file_type'; import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; // FLAKY: https://github.com/elastic/kibana/issues/175841 -describe('getFileType', () => { - const fileType = getFileType(); - - it('invalid props return blank FileAttachmentViewObject', () => { - expect(fileType).toStrictEqual({ - id: FILE_ATTACHMENT_TYPE, - icon: 'document', - displayName: 'Files', - getAttachmentViewObject: expect.any(Function), - getAttachmentRemovalObject: expect.any(Function), +for (let i = 0; i < 20; i++) { + describe('getFileType', () => { + const fileType = getFileType(); + + it('invalid props return blank FileAttachmentViewObject', () => { + expect(fileType).toStrictEqual({ + id: FILE_ATTACHMENT_TYPE, + icon: 'document', + displayName: 'Files', + getAttachmentViewObject: expect.any(Function), + getAttachmentRemovalObject: expect.any(Function), + }); }); - }); - describe('getFileAttachmentViewObject', () => { - let appMockRender: AppMockRenderer; + describe('getFileAttachmentViewObject', () => { + let appMockRender: AppMockRenderer; - const attachmentViewProps: ExternalReferenceAttachmentViewProps = { - externalReferenceId: basicFileMock.id, - // @ts-expect-error: files is a proper JSON - externalReferenceMetadata: { files: [basicFileMock] }, - caseData: { title: basicCase.title, id: basicCase.id }, - }; + const attachmentViewProps: ExternalReferenceAttachmentViewProps = { + externalReferenceId: basicFileMock.id, + // @ts-expect-error: files is a proper JSON + externalReferenceMetadata: { files: [basicFileMock] }, + caseData: { title: basicCase.title, id: basicCase.id }, + }; - beforeEach(() => { - jest.clearAllMocks(); - }); + beforeEach(() => { + jest.clearAllMocks(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('event renders a clickable name if the file is an image', async () => { - appMockRender = createAppMockRenderer(); + it('event renders a clickable name if the file is an image', async () => { + appMockRender = createAppMockRenderer(); - // @ts-expect-error: event is defined - appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); + // @ts-expect-error: event is defined + appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); - expect(await screen.findByText('my-super-cool-screenshot.png')).toBeInTheDocument(); - expect(screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); - }); + expect(await screen.findByText('my-super-cool-screenshot.png')).toBeInTheDocument(); + expect(screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); + }); - it('clicking the name rendered in event opens the file preview', async () => { - appMockRender = createAppMockRenderer(); + it('clicking the name rendered in event opens the file preview', async () => { + appMockRender = createAppMockRenderer(); - // @ts-expect-error: event is a React element - appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); + // @ts-expect-error: event is a React element + appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); - userEvent.click(await screen.findByText('my-super-cool-screenshot.png')); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - }); + userEvent.click(await screen.findByText('my-super-cool-screenshot.png')); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + }); - it('getActions renders a download button', async () => { - appMockRender = createAppMockRenderer(); + it('getActions renders a download button', async () => { + appMockRender = createAppMockRenderer(); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(attachmentViewObject).not.toBeUndefined(); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - expect(actions.length).toBe(2); - expect(actions[0]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(actions.length).toBe(2); + expect(actions[0]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), + }); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[0].render()); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[0].render()); - expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument(); + }); - it('getActions renders a delete button', async () => { - appMockRender = createAppMockRenderer(); + it('getActions renders a delete button', async () => { + appMockRender = createAppMockRenderer(); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(attachmentViewObject).not.toBeUndefined(); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - expect(actions.length).toBe(2); - expect(actions[1]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(actions.length).toBe(2); + expect(actions[1]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), + }); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[1].render()); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[1].render()); - expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); + }); - it('clicking the delete button in actions opens deletion modal', async () => { - appMockRender = createAppMockRenderer(); + it('clicking the delete button in actions opens deletion modal', async () => { + appMockRender = createAppMockRenderer(); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(attachmentViewObject).not.toBeUndefined(); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - expect(actions.length).toBe(2); - expect(actions[1]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(actions.length).toBe(2); + expect(actions[1]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), + }); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[1].render()); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[1].render()); - const deleteButton = await screen.findByTestId('cases-files-delete-button'); + const deleteButton = await screen.findByTestId('cases-files-delete-button'); - expect(deleteButton).toBeInTheDocument(); + expect(deleteButton).toBeInTheDocument(); - userEvent.click(deleteButton); + userEvent.click(deleteButton); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + }); - it('empty externalReferenceMetadata returns blank FileAttachmentViewObject', () => { - expect( - fileType.getAttachmentViewObject({ ...attachmentViewProps, externalReferenceMetadata: {} }) - ).toEqual({ - event: 'added an unknown file', - hideDefaultActions: true, - timelineAvatar: 'document', - getActions: expect.any(Function), + it('empty externalReferenceMetadata returns blank FileAttachmentViewObject', () => { + expect( + fileType.getAttachmentViewObject({ + ...attachmentViewProps, + externalReferenceMetadata: {}, + }) + ).toEqual({ + event: 'added an unknown file', + hideDefaultActions: true, + timelineAvatar: 'document', + getActions: expect.any(Function), + }); }); - }); - it('timelineAvatar is image if file is an image', () => { - expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( - expect.objectContaining({ - timelineAvatar: 'image', - }) - ); - }); + it('timelineAvatar is image if file is an image', () => { + expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( + expect.objectContaining({ + timelineAvatar: 'image', + }) + ); + }); - it('timelineAvatar is document if file is not an image', () => { - expect( - fileType.getAttachmentViewObject({ - ...attachmentViewProps, - externalReferenceMetadata: { - files: [{ ...basicFileMock, mimeType: 'text/csv' } as JsonValue], - }, - }) - ).toEqual( - expect.objectContaining({ - timelineAvatar: 'document', - }) - ); - }); + it('timelineAvatar is document if file is not an image', () => { + expect( + fileType.getAttachmentViewObject({ + ...attachmentViewProps, + externalReferenceMetadata: { + files: [{ ...basicFileMock, mimeType: 'text/csv' } as JsonValue], + }, + }) + ).toEqual( + expect.objectContaining({ + timelineAvatar: 'document', + }) + ); + }); - it('default actions should be hidden', () => { - expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( - expect.objectContaining({ - hideDefaultActions: true, - }) - ); + it('default actions should be hidden', () => { + expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( + expect.objectContaining({ + hideDefaultActions: true, + }) + ); + }); }); - }); - describe('getFileAttachmentRemovalObject', () => { - it('event renders the right message', async () => { - // @ts-expect-error: object is defined - expect(fileType.getAttachmentRemovalObject().event).toBe('removed file'); + describe('getFileAttachmentRemovalObject', () => { + it('event renders the right message', async () => { + // @ts-expect-error: object is defined + expect(fileType.getAttachmentRemovalObject().event).toBe('removed file'); + }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx index b9b7c4d648cc1..14030f0eb075c 100644 --- a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx +++ b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx @@ -16,129 +16,46 @@ import { createAppMockRenderer } from '../../common/mock'; import { FilterPopover } from '.'; // FLAKY: https://github.com/elastic/kibana/issues/176679 -describe('FilterPopover ', () => { - let appMockRender: AppMockRenderer; - const onSelectedOptionsChanged = jest.fn(); - const tags: string[] = ['coke', 'pepsi']; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); - - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); - - it('renders button label correctly', async () => { - appMockRender.render( - - ); - - expect(await screen.findByTestId('options-filter-popover-button-Tags')).toBeInTheDocument(); - }); - - it('renders empty label correctly', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - expect(await screen.findByText('No options available')).toBeInTheDocument(); - }); - - it('renders string type options correctly', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - expect(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)).toBeInTheDocument(); - expect(await screen.findByTestId(`options-filter-popover-item-${tags[1]}`)).toBeInTheDocument(); - }); - - it('should call onSelectionChange with selected option', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); - - await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([tags[0]]); +for (let i = 0; i < 20; i++) { + describe('FilterPopover ', () => { + let appMockRender: AppMockRenderer; + const onSelectedOptionsChanged = jest.fn(); + const tags: string[] = ['coke', 'pepsi']; + + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); }); - }); - it('should call onSelectionChange with empty array when option is deselected', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - await waitForEuiPopoverOpen(); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); + it('renders button label correctly', async () => { + appMockRender.render( + + ); - await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([]); + expect(await screen.findByTestId('options-filter-popover-button-Tags')).toBeInTheDocument(); }); - }); - describe('maximum limit', () => { - const newTags = ['coke', 'pepsi', 'sprite', 'juice', 'water']; - const maxLength = 3; - const maxLengthLabel = `You have selected maximum number of ${maxLength} tags to filter`; - - it('should show message when maximum options are selected', async () => { + it('renders empty label correctly', async () => { appMockRender.render( ); @@ -146,24 +63,16 @@ describe('FilterPopover ', () => { await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('maximum-length-warning')).toHaveTextContent(maxLengthLabel); - - expect(await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`)).toHaveProperty( - 'disabled' - ); - expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( - 'disabled' - ); + expect(await screen.findByText('No options available')).toBeInTheDocument(); }); - it('should not show message when maximum length label is missing', async () => { + it('renders string type options correctly', async () => { appMockRender.render( ); @@ -171,23 +80,21 @@ describe('FilterPopover ', () => { await waitForEuiPopoverOpen(); - expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); - expect(await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`)).toHaveProperty( - 'disabled' - ); - expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( - 'disabled' - ); + expect( + await screen.findByTestId(`options-filter-popover-item-${tags[0]}`) + ).toBeInTheDocument(); + expect( + await screen.findByTestId(`options-filter-popover-item-${tags[1]}`) + ).toBeInTheDocument(); }); - it('should not show message and disable options when maximum length property is missing', async () => { + it('should call onSelectionChange with selected option', async () => { appMockRender.render( ); @@ -195,20 +102,20 @@ describe('FilterPopover ', () => { await waitForEuiPopoverOpen(); - expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); - expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( - 'disabled', - false - ); + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); + + await waitFor(() => { + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([tags[0]]); + }); }); - it('should allow to select more options when maximum length property is missing', async () => { + it('should call onSelectionChange with empty array when option is deselected', async () => { appMockRender.render( ); @@ -216,11 +123,115 @@ describe('FilterPopover ', () => { await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${newTags[1]}`)); + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([newTags[0], newTags[2], newTags[1]]); + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([]); + }); + }); + + describe('maximum limit', () => { + const newTags = ['coke', 'pepsi', 'sprite', 'juice', 'water']; + const maxLength = 3; + const maxLengthLabel = `You have selected maximum number of ${maxLength} tags to filter`; + + it('should show message when maximum options are selected', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + expect(await screen.findByTestId('maximum-length-warning')).toHaveTextContent( + maxLengthLabel + ); + + expect( + await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`) + ).toHaveProperty('disabled'); + expect( + await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) + ).toHaveProperty('disabled'); + }); + + it('should not show message when maximum length label is missing', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); + expect( + await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`) + ).toHaveProperty('disabled'); + expect( + await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) + ).toHaveProperty('disabled'); + }); + + it('should not show message and disable options when maximum length property is missing', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); + expect( + await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) + ).toHaveProperty('disabled', false); + }); + + it('should allow to select more options when maximum length property is missing', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${newTags[1]}`)); + + await waitFor(() => { + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([ + newTags[0], + newTags[2], + newTags[1], + ]); + }); }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx index ab592c2f9cb51..6e28ad8d2fa80 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx @@ -62,176 +62,178 @@ const defaultProps = { }; // FLAKY: https://github.com/elastic/kibana/issues/171177 -describe('EditableMarkdown', () => { - let appMockRender: AppMockRenderer; +for (let i = 0; i < 20; i++) { + describe('EditableMarkdown', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); - - afterEach(() => { - sessionStorage.removeItem(draftStorageKey); - }); - - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); - - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); - - it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { - appMockRender.render(); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, + afterEach(() => { + sessionStorage.removeItem(draftStorageKey); }); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - await waitFor(() => { - expect(onSaveContent).toHaveBeenCalledWith(newValue); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); }); - }); - it('Does not call onSaveContent if no change from current text', async () => { - appMockRender.render(); + it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { + appMockRender.render(); + + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, + }); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + userEvent.click(await screen.findByTestId('editable-save-markdown')); - await waitFor(() => { - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + await waitFor(() => { + expect(onSaveContent).toHaveBeenCalledWith(newValue); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + }); }); - expect(onSaveContent).not.toHaveBeenCalled(); - }); - it('Cancel button click calls only onChangeEditable', async () => { - appMockRender.render(); + it('Does not call onSaveContent if no change from current text', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('editable-cancel-markdown')); + userEvent.click(await screen.findByTestId('editable-save-markdown')); - await waitFor(() => { + await waitFor(() => { + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + }); expect(onSaveContent).not.toHaveBeenCalled(); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); }); - }); - describe('errors', () => { - it('Shows error message and save button disabled if current text is empty', async () => { + it('Cancel button click calls only onChangeEditable', async () => { appMockRender.render(); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ''); + userEvent.click(await screen.findByTestId('editable-cancel-markdown')); - expect(await screen.findByText('Required field')).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + await waitFor(() => { + expect(onSaveContent).not.toHaveBeenCalled(); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + }); }); - it('Shows error message and save button disabled if current text is of empty characters', async () => { - appMockRender.render(); + describe('errors', () => { + it('Shows error message and save button disabled if current text is empty', async () => { + appMockRender.render(); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ' '); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ''); - expect(await screen.findByText('Required field')).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); - }); + expect(await screen.findByText('Required field')).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + }); - it('Shows error message and save button disabled if current text is too long', async () => { - const longComment = 'b'.repeat(maxLength + 1); + it('Shows error message and save button disabled if current text is of empty characters', async () => { + appMockRender.render(); - appMockRender.render(); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ' '); - const markdown = await screen.findByTestId('euiMarkdownEditorTextArea'); + expect(await screen.findByText('Required field')).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + }); - userEvent.paste(markdown, longComment); + it('Shows error message and save button disabled if current text is too long', async () => { + const longComment = 'b'.repeat(maxLength + 1); - expect( - await screen.findByText( - `The length of the textarea is too long. The maximum length is ${maxLength} characters.` - ) - ).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); - }); - }); + appMockRender.render(); - describe('draft comment ', () => { - beforeAll(() => { - jest.useFakeTimers(); - }); + const markdown = await screen.findByTestId('euiMarkdownEditorTextArea'); - afterEach(() => { - jest.clearAllTimers(); - }); + userEvent.paste(markdown, longComment); - afterAll(() => { - jest.useRealTimers(); - sessionStorage.removeItem(draftStorageKey); + expect( + await screen.findByText( + `The length of the textarea is too long. The maximum length is ${maxLength} characters.` + ) + ).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + }); }); - beforeEach(() => { - jest.clearAllMocks(); - }); + describe('draft comment ', () => { + beforeAll(() => { + jest.useFakeTimers(); + }); - it('Save button click clears session storage', async () => { - appMockRender.render(); + afterEach(() => { + jest.clearAllTimers(); + }); - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, + afterAll(() => { + jest.useRealTimers(); + sessionStorage.removeItem(draftStorageKey); }); - act(() => { - jest.advanceTimersByTime(1000); + beforeEach(() => { + jest.clearAllMocks(); }); - expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); + it('Save button click clears session storage', async () => { + appMockRender.render(); - fireEvent.click(await screen.findByTestId(`editable-save-markdown`)); + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, + }); - await waitFor(() => { - expect(onSaveContent).toHaveBeenCalledWith(newValue); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); - expect(sessionStorage.getItem(draftStorageKey)).toBe(null); - }); - }); + act(() => { + jest.advanceTimersByTime(1000); + }); - it('Cancel button click clears session storage', async () => { - appMockRender.render(); + expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); - expect(sessionStorage.getItem(draftStorageKey)).toBe(''); + fireEvent.click(await screen.findByTestId(`editable-save-markdown`)); - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, + await waitFor(() => { + expect(onSaveContent).toHaveBeenCalledWith(newValue); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + expect(sessionStorage.getItem(draftStorageKey)).toBe(null); + }); }); - act(() => { - jest.advanceTimersByTime(1000); - }); + it('Cancel button click clears session storage', async () => { + appMockRender.render(); - await waitFor(() => { - expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); - }); + expect(sessionStorage.getItem(draftStorageKey)).toBe(''); - fireEvent.click(await screen.findByTestId('editable-cancel-markdown')); + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, + }); - await waitFor(() => { - expect(sessionStorage.getItem(draftStorageKey)).toBe(null); - }); - }); + act(() => { + jest.advanceTimersByTime(1000); + }); - describe('existing storage key', () => { - beforeEach(() => { - sessionStorage.setItem(draftStorageKey, 'value set in storage'); + await waitFor(() => { + expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); + }); + + fireEvent.click(await screen.findByTestId('editable-cancel-markdown')); + + await waitFor(() => { + expect(sessionStorage.getItem(draftStorageKey)).toBe(null); + }); }); - it('should have session storage value same as draft comment', async () => { - appMockRender.render(); + describe('existing storage key', () => { + beforeEach(() => { + sessionStorage.setItem(draftStorageKey, 'value set in storage'); + }); + + it('should have session storage value same as draft comment', async () => { + appMockRender.render(); - expect(await screen.findByText('value set in storage')).toBeInTheDocument(); + expect(await screen.findByText('value set in storage')).toBeInTheDocument(); + }); }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx index 404cd3543b729..33d5f2b88a73e 100644 --- a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx @@ -14,137 +14,139 @@ import { FormTestComponent } from '../../common/test_utils'; import { TemplateFields } from './template_fields'; // FLAKY: https://github.com/elastic/kibana/issues/187854 -describe('Template fields', () => { - let appMockRenderer: AppMockRenderer; - const onSubmit = jest.fn(); - const formDefaultValue = { templateTags: [] }; - const defaultProps = { - isLoading: false, - configurationTemplateTags: [], - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRenderer = createAppMockRenderer(); - }); +for (let i = 0; i < 20; i++) { + describe('Template fields', () => { + let appMockRenderer: AppMockRenderer; + const onSubmit = jest.fn(); + const formDefaultValue = { templateTags: [] }; + const defaultProps = { + isLoading: false, + configurationTemplateTags: [], + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRenderer = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - it('renders template fields correctly', async () => { - appMockRenderer.render( - - - - ); + it('renders template fields correctly', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-name-input')).toBeInTheDocument(); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - expect(await screen.findByTestId('template-description-input')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('template-name-input')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-description-input')).toBeInTheDocument(); + }); - it('renders template fields with existing value', async () => { - appMockRenderer.render( - - - - ); - - expect(await screen.findByTestId('template-name-input')).toHaveValue('Sample template'); - - const templateTags = await screen.findByTestId('template-tags'); - - expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( - 'template-1' - ); - expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( - 'template-2' - ); - - expect(await screen.findByTestId('template-description-input')).toHaveTextContent( - 'This is a template description' - ); - }); + it('renders template fields with existing value', async () => { + appMockRenderer.render( + + + + ); + + expect(await screen.findByTestId('template-name-input')).toHaveValue('Sample template'); + + const templateTags = await screen.findByTestId('template-tags'); - it('calls onSubmit with template fields', async () => { - appMockRenderer.render( - - - - ); + expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( + 'template-1' + ); + expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( + 'template-2' + ); - userEvent.paste(await screen.findByTestId('template-name-input'), 'Template 1'); + expect(await screen.findByTestId('template-description-input')).toHaveTextContent( + 'This is a template description' + ); + }); - const templateTags = await screen.findByTestId('template-tags'); + it('calls onSubmit with template fields', async () => { + appMockRenderer.render( + + + + ); - userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); - userEvent.keyboard('{enter}'); + userEvent.paste(await screen.findByTestId('template-name-input'), 'Template 1'); - userEvent.paste( - await screen.findByTestId('template-description-input'), - 'this is a first template' - ); + const templateTags = await screen.findByTestId('template-tags'); - userEvent.click(screen.getByText('Submit')); + userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); + userEvent.keyboard('{enter}'); - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - name: 'Template 1', - templateDescription: 'this is a first template', - templateTags: ['first'], - }, - true + userEvent.paste( + await screen.findByTestId('template-description-input'), + 'this is a first template' ); + + userEvent.click(screen.getByText('Submit')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + name: 'Template 1', + templateDescription: 'this is a first template', + templateTags: ['first'], + }, + true + ); + }); }); - }); - it('calls onSubmit with updated template fields', async () => { - appMockRenderer.render( - - - - ); - - userEvent.paste(await screen.findByTestId('template-name-input'), '!!'); - - const templateTags = await screen.findByTestId('template-tags'); - - userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); - userEvent.keyboard('{enter}'); - - userEvent.paste(await screen.findByTestId('template-description-input'), '..'); - - userEvent.click(screen.getByText('Submit')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - name: 'Sample template!!', - templateDescription: 'This is a template description..', - templateTags: ['template-1', 'template-2', 'first'], - }, - true + it('calls onSubmit with updated template fields', async () => { + appMockRenderer.render( + + + ); + + userEvent.paste(await screen.findByTestId('template-name-input'), '!!'); + + const templateTags = await screen.findByTestId('template-tags'); + + userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); + userEvent.keyboard('{enter}'); + + userEvent.paste(await screen.findByTestId('template-description-input'), '..'); + + userEvent.click(screen.getByText('Submit')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + name: 'Sample template!!', + templateDescription: 'This is a template description..', + templateTags: ['template-1', 'template-2', 'first'], + }, + true + ); + }); }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx index 922df965ea7de..76a0979bf8d5d 100644 --- a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx @@ -16,122 +16,124 @@ import { TemplateTags } from './template_tags'; import { showEuiComboBoxOptions } from '@elastic/eui/lib/test/rtl'; // FLAKY: https://github.com/elastic/kibana/issues/189293 -describe('TemplateTags', () => { - let appMockRenderer: AppMockRenderer; - const onSubmit = jest.fn(); - const formDefaultValue = { templateTags: [] }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRenderer = createAppMockRenderer(); - }); +for (let i = 0; i < 20; i++) { + describe('TemplateTags', () => { + let appMockRenderer: AppMockRenderer; + const onSubmit = jest.fn(); + const formDefaultValue = { templateTags: [] }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRenderer = createAppMockRenderer(); + }); - afterEach(async () => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - it('renders template tags', async () => { - appMockRenderer.render( - - - - ); + it('renders template tags', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + }); - it('renders loading state', async () => { - appMockRenderer.render( - - - - ); + it('renders loading state', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByRole('progressbar')).toBeInTheDocument(); - expect(await screen.findByLabelText('Loading')).toBeInTheDocument(); - }); + expect(await screen.findByRole('progressbar')).toBeInTheDocument(); + expect(await screen.findByLabelText('Loading')).toBeInTheDocument(); + }); - it('shows template tags options', async () => { - appMockRenderer.render( - - - - ); + it('shows template tags options', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - await showEuiComboBoxOptions(); + await showEuiComboBoxOptions(); - expect(await screen.findByText('foo')).toBeInTheDocument(); - }); + expect(await screen.findByText('foo')).toBeInTheDocument(); + }); - it('shows template tags with current values', async () => { - appMockRenderer.render( - - - - ); + it('shows template tags with current values', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - expect(await screen.findByText('foo')).toBeInTheDocument(); + expect(await screen.findByText('foo')).toBeInTheDocument(); - expect(await screen.findByText('bar')).toBeInTheDocument(); - }); + expect(await screen.findByText('bar')).toBeInTheDocument(); + }); - it('adds template tag ', async () => { - appMockRenderer.render( - - - - ); - - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - - const comboBoxEle = await screen.findByRole('combobox'); - userEvent.paste(comboBoxEle, 'test'); - userEvent.keyboard('{enter}'); - userEvent.paste(comboBoxEle, 'template'); - userEvent.keyboard('{enter}'); - - userEvent.click(screen.getByText('Submit')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - templateTags: ['test', 'template'], - }, - true + it('adds template tag ', async () => { + appMockRenderer.render( + + + ); - }); - }); - it('adds new template tag to existing tags', async () => { - appMockRenderer.render( - - - - ); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + const comboBoxEle = await screen.findByRole('combobox'); + userEvent.paste(comboBoxEle, 'test'); + userEvent.keyboard('{enter}'); + userEvent.paste(comboBoxEle, 'template'); + userEvent.keyboard('{enter}'); - const comboBoxEle = await screen.findByRole('combobox'); - userEvent.paste(comboBoxEle, 'test'); - userEvent.keyboard('{enter}'); + userEvent.click(screen.getByText('Submit')); - userEvent.click(screen.getByText('Submit')); + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + templateTags: ['test', 'template'], + }, + true + ); + }); + }); - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - templateTags: ['foo', 'bar', 'test'], - }, - true + it('adds new template tag to existing tags', async () => { + appMockRenderer.render( + + + ); + + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + + const comboBoxEle = await screen.findByRole('combobox'); + userEvent.paste(comboBoxEle, 'test'); + userEvent.keyboard('{enter}'); + + userEvent.click(screen.getByText('Submit')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + templateTags: ['foo', 'bar', 'test'], + }, + true + ); + }); }); }); -}); +} 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 13fd336ca967e..e429dc8c6732d 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 @@ -7,7 +7,7 @@ import React from 'react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; -import { waitFor, screen, act } from '@testing-library/react'; +import { waitFor, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { @@ -18,91 +18,93 @@ import { import { AlertPropertyActions } from './alert_property_actions'; // FLAKY: https://github.com/elastic/kibana/issues/174667 -describe('AlertPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - totalAlerts: 1, - onDelete: jest.fn(), - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); +for (let i = 0; i < 20; i++) { + describe('AlertPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + totalAlerts: 1, + onDelete: jest.fn(), + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - afterEach(async () => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 1 - ); + expect( + (await screen.findByTestId('property-actions-user-action-group')).children.length + ).toBe(1); - expect( - await screen.findByTestId('property-actions-user-action-minusInCircle') - ).toBeInTheDocument(); - }); + expect( + await screen.findByTestId('property-actions-user-action-minusInCircle') + ).toBeInTheDocument(); + }); - it('renders the modal info correctly for multiple alert', async () => { - appMock.render(); + it('renders the modal info correctly for multiple alert', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); - expect(await screen.findByText('Remove')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); + expect(await screen.findByText('Remove')).toBeInTheDocument(); + }); - it('remove alerts correctly', async () => { - appMock.render(); + it('remove alerts correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(await screen.findByText('Remove')); + userEvent.click(await screen.findByText('Remove')); - await waitFor(() => { - expect(props.onDelete).toHaveBeenCalled(); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); + }); }); - }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index 9a041b4feb327..520c9d1c549b0 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -19,125 +19,129 @@ import { RegisteredAttachmentsPropertyActions } from './registered_attachments_p import { AttachmentActionType } from '../../../client/attachment_framework/types'; // Failing: See https://github.com/elastic/kibana/issues/174384 -describe('RegisteredAttachmentsPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - registeredAttachmentActions: [], - onDelete: jest.fn(), - hideDefaultActions: false, - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); +for (let i = 0; i < 20; i++) { + describe('RegisteredAttachmentsPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + registeredAttachmentActions: [], + onDelete: jest.fn(), + hideDefaultActions: false, + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - afterEach(async () => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument(); + }); - it('renders the modal info correctly', async () => { - appMock.render(); + it('renders the modal info correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( - 'Delete attachment' - ); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( + 'Delete attachment' + ); - expect(await screen.findByText('Delete')).toBeInTheDocument(); - }); + expect(await screen.findByText('Delete')).toBeInTheDocument(); + }); - it('remove attachments correctly', async () => { - appMock.render(); + it('remove attachments correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(await screen.findByText('Delete')); + userEvent.click(await screen.findByText('Delete')); - await waitFor(() => { - expect(props.onDelete).toHaveBeenCalled(); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); + }); }); - }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); - - it('does not show the property actions when hideDefaultActions is enabled', async () => { - appMock.render(); - - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); - - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); - - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - }); - - it('renders correctly registered attachments', async () => { - const onClick = jest.fn(); - const action = [ - { - type: AttachmentActionType.BUTTON as const, - label: 'My button', - iconType: 'download', - onClick, - }, - ]; + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - appMock.render( - - ); + it('does not show the property actions when hideDefaultActions is enabled', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 2 - ); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); - expect(await screen.findByTestId('property-actions-user-action-download')).toBeInTheDocument(); + it('renders correctly registered attachments', async () => { + const onClick = jest.fn(); + const action = [ + { + type: AttachmentActionType.BUTTON as const, + label: 'My button', + iconType: 'download', + onClick, + }, + ]; + + appMock.render( + + ); + + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); + + expect( + (await screen.findByTestId('property-actions-user-action-group')).children.length + ).toBe(2); + + expect( + await screen.findByTestId('property-actions-user-action-download') + ).toBeInTheDocument(); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index ccad2f74f3772..f3a4be9722370 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -18,106 +18,108 @@ import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; // FLAKY: https://github.com/elastic/kibana/issues/175310 -describe('UserCommentPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - onEdit: jest.fn(), - onQuote: jest.fn(), - onDelete: jest.fn(), - }; - - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); +for (let i = 0; i < 20; i++) { + describe('UserCommentPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + onEdit: jest.fn(), + onQuote: jest.fn(), + onDelete: jest.fn(), + }; + + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( - 3 - ); - expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - }); + expect( + (await screen.findByTestId('property-actions-user-action-group')).children.length + ).toBe(3); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + }); - it('edits the comment correctly', async () => { - appMock.render(); + it('edits the comment correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); + userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); - expect(props.onEdit).toHaveBeenCalled(); - }); + expect(props.onEdit).toHaveBeenCalled(); + }); - it('quotes the comment correctly', async () => { - appMock.render(); + it('quotes the comment correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); + userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); - expect(props.onQuote).toHaveBeenCalled(); - }); + expect(props.onQuote).toHaveBeenCalled(); + }); - it('deletes the comment correctly', async () => { - appMock.render(); + it('deletes the comment correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - await waitFor(() => { - expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + await waitFor(() => { + expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + }); - userEvent.click(await screen.findByText('Delete')); - expect(props.onDelete).toHaveBeenCalled(); - }); + userEvent.click(await screen.findByText('Delete')); + expect(props.onDelete).toHaveBeenCalled(); + }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); }); -}); +} diff --git a/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts b/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts index 63bd94d55763b..4edc105b8d349 100644 --- a/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts +++ b/x-pack/plugins/cases/public/containers/user_profiles/use_bulk_get_user_profiles.test.ts @@ -13,7 +13,6 @@ import * as api from './api'; import { useBulkGetUserProfiles } from './use_bulk_get_user_profiles'; import { userProfilesIds } from './api.mock'; import { createStartServicesMock } from '../../common/lib/kibana/kibana_react.mock'; -import { waitFor } from '@testing-library/react'; jest.mock('../../common/lib/kibana'); jest.mock('./api'); @@ -21,7 +20,7 @@ jest.mock('./api'); const useKibanaMock = useKibana as jest.Mock; // FLAKY: https://github.com/elastic/kibana/issues/176335 -describe('useBulkGetUserProfiles', () => { +describe.skip('useBulkGetUserProfiles', () => { const props = { uids: userProfilesIds, }; @@ -39,14 +38,6 @@ describe('useBulkGetUserProfiles', () => { }); }); - afterEach(async () => { - appMockRender.queryClient.getQueryCache().clear(); - }); - - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); - it('calls bulkGetUserProfiles with correct arguments', async () => { const spyOnBulkGetUserProfiles = jest.spyOn(api, 'bulkGetUserProfiles'); From da6400dadeb70cf4396e2e4a0e959e5546b37e6d Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Tue, 27 Aug 2024 10:17:09 +0100 Subject: [PATCH 3/6] loop each test for 50 times --- .../cases/public/components/all_cases/columns_popover.test.tsx | 2 +- .../cases/public/components/all_cases/use_actions.test.tsx | 2 +- .../cases/public/components/case_form_fields/severity.test.tsx | 2 +- .../components/case_form_fields/sync_alerts_toggle.test.tsx | 2 +- .../components/case_view/components/case_view_files.test.tsx | 2 +- .../components/case_view/components/custom_fields.test.tsx | 2 +- .../cases/public/components/connector_selector/form.test.tsx | 2 +- x-pack/plugins/cases/public/components/create/template.test.tsx | 2 +- .../cases/public/components/custom_fields/form_fields.test.tsx | 2 +- .../plugins/cases/public/components/description/index.test.tsx | 2 +- .../public/components/files/file_attachment_event.test.tsx | 2 +- .../plugins/cases/public/components/files/file_preview.test.tsx | 2 +- x-pack/plugins/cases/public/components/files/file_type.test.tsx | 2 +- .../cases/public/components/filter_popover/index.test.tsx | 2 +- .../markdown_editor/editable_markdown_renderer.test.tsx | 2 +- .../cases/public/components/templates/template_fields.test.tsx | 2 +- .../cases/public/components/templates/template_tags.test.tsx | 2 +- .../property_actions/alert_property_actions.test.tsx | 2 +- .../registered_attachments_property_actions.test.tsx | 2 +- .../property_actions/user_comment_property_actions.test.tsx | 2 +- 20 files changed, 20 insertions(+), 20 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 dda96100a2012..06f7544bd1e72 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 @@ -15,7 +15,7 @@ import { createAppMockRenderer } from '../../common/mock'; import { ColumnsPopover } from './columns_popover'; // FLAKY: https://github.com/elastic/kibana/issues/174682 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('ColumnsPopover', () => { let appMockRenderer: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx index e17a3ab9fcb1b..c0ea532acf1f3 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx @@ -29,7 +29,7 @@ jest.mock('../../containers/api'); jest.mock('../../containers/user_profiles/api'); // FLAKY: https://github.com/elastic/kibana/issues/188361 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('useActions', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx index a00210f9852a0..412b66671fb6e 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx @@ -17,7 +17,7 @@ import { FormTestComponent } from '../../common/test_utils'; const onSubmit = jest.fn(); // FLAKY: https://github.com/elastic/kibana/issues/188951 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('Severity form field', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx index 529bc21e92220..02418b8114f61 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx @@ -15,7 +15,7 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; // Failing: See https://github.com/elastic/kibana/issues/190270 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('SyncAlertsToggle', () => { let appMockRender: AppMockRenderer; const onSubmit = jest.fn(); diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx index f224d2814a27d..0095526ff9fb7 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx @@ -27,7 +27,7 @@ const caseData: CaseUI = { }; // FLAKY: https://github.com/elastic/kibana/issues/185046 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('Case View Page files tab', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx index 361f2b040035e..a4eb95ecfd553 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx @@ -16,7 +16,7 @@ import { customFieldsMock, customFieldsConfigurationMock } from '../../../contai import userEvent from '@testing-library/user-event'; import { CustomFieldTypes } from '../../../../common/types/domain'; -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('Case View Page files tab', () => { const onSubmit = jest.fn(); let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index cc3704442bba9..10b8ad2da9de8 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -20,7 +20,7 @@ jest.mock('../../common/lib/kibana'); const useKibanaMock = useKibana as jest.Mocked; // FLAKY: https://github.com/elastic/kibana/issues/189530 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('ConnectorSelector', () => { const handleChange = jest.fn(); const defaultProps = { diff --git a/x-pack/plugins/cases/public/components/create/template.test.tsx b/x-pack/plugins/cases/public/components/create/template.test.tsx index b3b0424eae42f..53ddff8fe4183 100644 --- a/x-pack/plugins/cases/public/components/create/template.test.tsx +++ b/x-pack/plugins/cases/public/components/create/template.test.tsx @@ -14,7 +14,7 @@ import { templatesConfigurationMock } from '../../containers/mock'; import { TemplateSelector } from './templates'; // FLAKY: https://github.com/elastic/kibana/issues/178457 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('CustomFields', () => { let appMockRender: AppMockRenderer; const onTemplateChange = jest.fn(); diff --git a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx index 50a7c25866e1c..7ac62b19bd2a8 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx @@ -16,7 +16,7 @@ import { CustomFieldTypes } from '../../../common/types/domain'; import { FormFields } from './form_fields'; // FLAKY: https://github.com/elastic/kibana/issues/188450 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('FormFields ', () => { let appMockRender: AppMockRenderer; const onSubmit = jest.fn(); diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index fd1e2b8e48077..a61ed6c5d9736 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -28,7 +28,7 @@ const defaultProps = { }; // Failing: See https://github.com/elastic/kibana/issues/185879 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('Description', () => { const onUpdateField = jest.fn(); let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index 27af4e258bda7..d1f920a982e96 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -17,7 +17,7 @@ import { basicFileMock } from '../../containers/mock'; import { FileAttachmentEvent } from './file_attachment_event'; // FLAKY: https://github.com/elastic/kibana/issues/174661 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('FileAttachmentEvent', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx index bae3fd984eb08..806e930998d40 100644 --- a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx @@ -17,7 +17,7 @@ import { basicFileMock } from '../../containers/mock'; import { FilePreview } from './file_preview'; // FLAKY: https://github.com/elastic/kibana/issues/182364 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('FilePreview', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index 360b3cd496b1e..b2ff448473771 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -18,7 +18,7 @@ import { getFileType } from './file_type'; import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; // FLAKY: https://github.com/elastic/kibana/issues/175841 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('getFileType', () => { const fileType = getFileType(); diff --git a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx index 14030f0eb075c..cfee7af9064b4 100644 --- a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx +++ b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx @@ -16,7 +16,7 @@ import { createAppMockRenderer } from '../../common/mock'; import { FilterPopover } from '.'; // FLAKY: https://github.com/elastic/kibana/issues/176679 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('FilterPopover ', () => { let appMockRender: AppMockRenderer; const onSelectedOptionsChanged = jest.fn(); diff --git a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx index 6e28ad8d2fa80..41a83c3d113d5 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx @@ -62,7 +62,7 @@ const defaultProps = { }; // FLAKY: https://github.com/elastic/kibana/issues/171177 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('EditableMarkdown', () => { let appMockRender: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx index 33d5f2b88a73e..0eac04a056adc 100644 --- a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx @@ -14,7 +14,7 @@ import { FormTestComponent } from '../../common/test_utils'; import { TemplateFields } from './template_fields'; // FLAKY: https://github.com/elastic/kibana/issues/187854 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('Template fields', () => { let appMockRenderer: AppMockRenderer; const onSubmit = jest.fn(); diff --git a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx index 76a0979bf8d5d..562670f917977 100644 --- a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx @@ -16,7 +16,7 @@ import { TemplateTags } from './template_tags'; import { showEuiComboBoxOptions } from '@elastic/eui/lib/test/rtl'; // FLAKY: https://github.com/elastic/kibana/issues/189293 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('TemplateTags', () => { let appMockRenderer: AppMockRenderer; const onSubmit = jest.fn(); 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 e429dc8c6732d..fb3e4626178f2 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 @@ -18,7 +18,7 @@ import { import { AlertPropertyActions } from './alert_property_actions'; // FLAKY: https://github.com/elastic/kibana/issues/174667 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('AlertPropertyActions', () => { let appMock: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index 520c9d1c549b0..52f12ae2a4421 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -19,7 +19,7 @@ import { RegisteredAttachmentsPropertyActions } from './registered_attachments_p import { AttachmentActionType } from '../../../client/attachment_framework/types'; // Failing: See https://github.com/elastic/kibana/issues/174384 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('RegisteredAttachmentsPropertyActions', () => { let appMock: AppMockRenderer; diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index f3a4be9722370..54a88f2dab576 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -18,7 +18,7 @@ import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; // FLAKY: https://github.com/elastic/kibana/issues/175310 -for (let i = 0; i < 20; i++) { +for (let i = 0; i < 50; i++) { describe('UserCommentPropertyActions', () => { let appMock: AppMockRenderer; From be547685fa8f2595f83c3df97e6a22ca35f6d8b9 Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Tue, 27 Aug 2024 14:34:32 +0100 Subject: [PATCH 4/6] remove loop --- .../all_cases/columns_popover.test.tsx | 307 ++++++------ .../components/all_cases/use_actions.test.tsx | 473 +++++++++--------- .../case_form_fields/severity.test.tsx | 109 ++-- .../sync_alerts_toggle.test.tsx | 121 +++-- .../components/case_view_files.test.tsx | 135 +++-- .../components/custom_fields.test.tsx | 418 ++++++++-------- .../connector_selector/form.test.tsx | 143 +++--- .../components/create/template.test.tsx | 119 +++-- .../custom_fields/form_fields.test.tsx | 107 ++-- .../components/description/index.test.tsx | 207 ++++---- .../files/file_attachment_event.test.tsx | 45 +- .../components/files/file_preview.test.tsx | 75 ++- .../components/files/file_type.test.tsx | 279 +++++------ .../components/filter_popover/index.test.tsx | 304 ++++++----- .../editable_markdown_renderer.test.tsx | 237 +++++---- .../templates/template_fields.test.tsx | 235 +++++---- .../templates/template_tags.test.tsx | 193 ++++--- .../alert_property_actions.test.tsx | 127 +++-- ...ered_attachments_property_actions.test.tsx | 187 ++++--- .../user_comment_property_actions.test.tsx | 149 +++--- 20 files changed, 1945 insertions(+), 2025 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 06f7544bd1e72..9d538001857c1 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,195 +14,190 @@ import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; import { ColumnsPopover } from './columns_popover'; -// FLAKY: https://github.com/elastic/kibana/issues/174682 -for (let i = 0; i < 50; i++) { - describe('ColumnsPopover', () => { - let appMockRenderer: AppMockRenderer; - - beforeEach(() => { - appMockRenderer = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); +describe('ColumnsPopover', () => { + let appMockRenderer: AppMockRenderer; - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); + 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 }, - ]; + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - it('renders correctly a list of selected columns', async () => { - appMockRenderer.render( - {}} /> - ); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - userEvent.click(await screen.findByTestId('column-selection-popover-button')); + const selectedColumns = [ + { field: 'title', name: 'Title', isChecked: true }, + { field: 'category', name: 'Category', isChecked: false }, + { field: 'tags', name: 'Tags', isChecked: false }, + ]; - await waitForEuiPopoverOpen(); + it('renders correctly a list of selected columns', async () => { + appMockRenderer.render( + {}} /> + ); - expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('column-selection-popover-button')); - selectedColumns.forEach(({ field, name, isChecked }) => { - expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( - 'aria-checked', - isChecked.toString() - ); - expect(screen.getByText(name)).toBeInTheDocument(); - }); - }); + await waitForEuiPopoverOpen(); - it('clicking a switch calls onSelectedColumnsChange with the right params', async () => { - const onSelectedColumnsChange = jest.fn(); + expect(await screen.findByTestId('column-selection-popover')).toBeInTheDocument(); - appMockRenderer.render( - + selectedColumns.forEach(({ field, name, isChecked }) => { + expect(screen.getByTestId(`column-selection-switch-${field}`)).toHaveAttribute( + 'aria-checked', + isChecked.toString() ); - - 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], - ]); - }); + 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(); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx index c0ea532acf1f3..e896d5541cefd 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx @@ -28,30 +28,28 @@ import { jest.mock('../../containers/api'); jest.mock('../../containers/user_profiles/api'); -// FLAKY: https://github.com/elastic/kibana/issues/188361 -for (let i = 0; i < 50; i++) { - describe('useActions', () => { - let appMockRender: AppMockRenderer; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); +describe('useActions', () => { + let appMockRender: AppMockRenderer; - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - it('renders column actions', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + + it('renders column actions', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - expect(result.current).toMatchInlineSnapshot(` + expect(result.current).toMatchInlineSnapshot(` Object { "actions": Object { "align": "right", @@ -61,65 +59,123 @@ for (let i = 0; i < 50; i++) { }, } `); + }); + + it('renders the popover', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('renders the popover', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + expect(res.getByTestId(`case-action-popover-${basicCase.id}`)).toBeInTheDocument(); + }); - expect(res.getByTestId(`case-action-popover-${basicCase.id}`)).toBeInTheDocument(); + it('open the action popover', async () => { + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('open the action popover', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + expect(res.getByText('Actions')).toBeInTheDocument(); + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + }); - expect(res.getByText('Actions')).toBeInTheDocument(); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + it('change the status of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); + + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('change the status of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-status-panel-${basicCase.id}`)); + await waitForEuiContextMenuPanelTransition(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + expect(res.getByTestId('cases-bulk-action-status-open')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-status-in-progress')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-status-closed')).toBeInTheDocument(); + + userEvent.click(res.getByTestId('cases-bulk-action-status-in-progress')); - userEvent.click(res.getByTestId(`case-action-status-panel-${basicCase.id}`)); - await waitForEuiContextMenuPanelTransition(); + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); + }); - expect(res.getByTestId('cases-bulk-action-status-open')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-status-in-progress')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-status-closed')).toBeInTheDocument(); + it('change the severity of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - userEvent.click(res.getByTestId('cases-bulk-action-status-in-progress')); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); + + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); + + userEvent.click(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)); + await waitForEuiContextMenuPanelTransition(); + + expect(res.getByTestId('cases-bulk-action-severity-low')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-medium')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-high')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-severity-critical')).toBeInTheDocument(); + + userEvent.click(res.getByTestId('cases-bulk-action-severity-medium')); + + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); }); + }); - it('change the severity of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); + it('copies the case id to the clipboard', async () => { + const originalClipboard = global.window.navigator.clipboard; + + Object.defineProperty(navigator, 'clipboard', { + value: { + writeText: jest.fn().mockImplementation(() => Promise.resolve()), + }, + writable: true, + }); + + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); + + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); + + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); + + userEvent.click(res.getByTestId('cases-action-copy-id')); + + expect(navigator.clipboard.writeText).toHaveBeenCalledWith(basicCase.id); + + Object.defineProperty(navigator, 'clipboard', { + value: originalClipboard, + }); + }); + + describe('Modals', () => { + it('delete a case', async () => { + const deleteSpy = jest.spyOn(api, 'deleteCases'); const { result } = renderHook(() => useActions({ disableActions: false }), { wrapper: appMockRender.AppWrapper, @@ -131,31 +187,20 @@ for (let i = 0; i < 50; i++) { userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)); - await waitForEuiContextMenuPanelTransition(); - - expect(res.getByTestId('cases-bulk-action-severity-low')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-medium')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-high')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-severity-critical')).toBeInTheDocument(); - - userEvent.click(res.getByTestId('cases-bulk-action-severity-medium')); + userEvent.click(res.getByTestId('cases-bulk-action-delete')); await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); + expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); }); - }); - it('copies the case id to the clipboard', async () => { - const originalClipboard = global.window.navigator.clipboard; + userEvent.click(res.getByTestId('confirmModalConfirmButton')); - Object.defineProperty(navigator, 'clipboard', { - value: { - writeText: jest.fn().mockImplementation(() => Promise.resolve()), - }, - writable: true, + await waitFor(() => { + expect(deleteSpy).toHaveBeenCalled(); }); + }); + it('closes the modal', async () => { const { result } = renderHook(() => useActions({ disableActions: false }), { wrapper: appMockRender.AppWrapper, }); @@ -166,217 +211,169 @@ for (let i = 0; i < 50; i++) { userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('cases-action-copy-id')); - - expect(navigator.clipboard.writeText).toHaveBeenCalledWith(basicCase.id); + userEvent.click(res.getByTestId('cases-bulk-action-delete')); - Object.defineProperty(navigator, 'clipboard', { - value: originalClipboard, + await waitFor(() => { + expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); }); - }); - describe('Modals', () => { - it('delete a case', async () => { - const deleteSpy = jest.spyOn(api, 'deleteCases'); + userEvent.click(res.getByTestId('confirmModalCancelButton')); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + expect(res.queryByTestId('confirm-delete-case-modal')).toBeFalsy(); + }); + }); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + describe('Flyouts', () => { + it('change the tags of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - userEvent.click(res.getByTestId('cases-bulk-action-delete')); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - await waitFor(() => { - expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); - }); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('confirmModalConfirmButton')); + userEvent.click(res.getByTestId('cases-bulk-action-tags')); - await waitFor(() => { - expect(deleteSpy).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(res.getByTestId('cases-edit-tags-flyout')).toBeInTheDocument(); }); - it('closes the modal', async () => { - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); - - userEvent.click(res.getByTestId('cases-bulk-action-delete')); + await waitFor(() => { + expect(res.getByText('coke')).toBeInTheDocument(); + }); - await waitFor(() => { - expect(res.getByTestId('confirm-delete-case-modal')).toBeInTheDocument(); - }); + userEvent.click(res.getByText('coke')); + userEvent.click(res.getByTestId('cases-edit-tags-flyout-submit')); - userEvent.click(res.getByTestId('confirmModalCancelButton')); + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); - expect(res.queryByTestId('confirm-delete-case-modal')).toBeFalsy(); + await waitFor(() => { + expect(res.queryByTestId('cases-edit-tags-flyout')).toBeFalsy(); }); }); - describe('Flyouts', () => { - it('change the tags of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); - - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); - - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); - - userEvent.click(res.getByTestId('cases-bulk-action-tags')); - - await waitFor(() => { - expect(res.getByTestId('cases-edit-tags-flyout')).toBeInTheDocument(); - }); - - await waitFor(() => { - expect(res.getByText('coke')).toBeInTheDocument(); - }); - - userEvent.click(res.getByText('coke')); - userEvent.click(res.getByTestId('cases-edit-tags-flyout-submit')); - - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); + it('change the assignees of the case', async () => { + const updateCasesSpy = jest.spyOn(api, 'updateCases'); - await waitFor(() => { - expect(res.queryByTestId('cases-edit-tags-flyout')).toBeFalsy(); - }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('change the assignees of the case', async () => { - const updateCasesSpy = jest.spyOn(api, 'updateCases'); - - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId('cases-bulk-action-assignees')); + userEvent.click(res.getByTestId('cases-bulk-action-assignees')); - await waitFor(() => { - expect(res.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); - }); + await waitFor(() => { + expect(res.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); + }); - await waitFor(() => { - expect(res.getByText('Damaged Raccoon')).toBeInTheDocument(); - }); + await waitFor(() => { + expect(res.getByText('Damaged Raccoon')).toBeInTheDocument(); + }); - userEvent.click(res.getByText('Damaged Raccoon')); - userEvent.click(res.getByTestId('cases-edit-assignees-flyout-submit')); + userEvent.click(res.getByText('Damaged Raccoon')); + userEvent.click(res.getByTestId('cases-edit-assignees-flyout-submit')); - await waitFor(() => { - expect(updateCasesSpy).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(updateCasesSpy).toHaveBeenCalled(); + }); - await waitFor(() => { - expect(res.queryByTestId('cases-edit-assignees-flyout')).toBeFalsy(); - }); + await waitFor(() => { + expect(res.queryByTestId('cases-edit-assignees-flyout')).toBeFalsy(); }); }); + }); + + describe('Permissions', () => { + it('shows the correct actions with all permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: allCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, + }); - describe('Permissions', () => { - it('shows the correct actions with all permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: allCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.getByTestId(`actions-separator-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + }); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.getByTestId(`actions-separator-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + it('shows the correct actions with no delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: noDeleteCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('shows the correct actions with no delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: noDeleteCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + expect(res.queryByTestId('cases-bulk-action-delete')).toBeFalsy(); + expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); + }); - expect(res.getByTestId(`case-action-status-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeInTheDocument(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); - expect(res.queryByTestId('cases-bulk-action-delete')).toBeFalsy(); - expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); + it('shows the correct actions with only delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('shows the correct actions with only delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); + await waitForEuiPopoverOpen(); - userEvent.click(res.getByTestId(`case-action-popover-button-${basicCase.id}`)); - await waitForEuiPopoverOpen(); + expect(res.queryByTestId(`case-action-status-panel-${basicCase.id}`)).toBeFalsy(); + expect(res.queryByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeFalsy(); + expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); + expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); + expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); + }); - expect(res.queryByTestId(`case-action-status-panel-${basicCase.id}`)).toBeFalsy(); - expect(res.queryByTestId(`case-action-severity-panel-${basicCase.id}`)).toBeFalsy(); - expect(res.getByTestId('cases-action-copy-id')).toBeInTheDocument(); - expect(res.getByTestId('cases-bulk-action-delete')).toBeInTheDocument(); - expect(res.queryByTestId(`actions-separator-${basicCase.id}`)).toBeFalsy(); + it('returns null if the user does not have update or delete permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); + const { result } = renderHook(() => useActions({ disableActions: false }), { + wrapper: appMockRender.AppWrapper, }); - it('returns null if the user does not have update or delete permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); - const { result } = renderHook(() => useActions({ disableActions: false }), { - wrapper: appMockRender.AppWrapper, - }); + expect(result.current.actions).toBe(null); + }); - expect(result.current.actions).toBe(null); + it('disables the action correctly', async () => { + appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + const { result } = renderHook(() => useActions({ disableActions: true }), { + wrapper: appMockRender.AppWrapper, }); - it('disables the action correctly', async () => { - appMockRender = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - const { result } = renderHook(() => useActions({ disableActions: true }), { - wrapper: appMockRender.AppWrapper, - }); - - const comp = result.current.actions!.render(basicCase) as React.ReactElement; - const res = appMockRender.render(comp); + const comp = result.current.actions!.render(basicCase) as React.ReactElement; + const res = appMockRender.render(comp); - await waitFor(() => { - expect(res.getByTestId(`case-action-popover-button-${basicCase.id}`)).toBeDisabled(); - }); + await waitFor(() => { + expect(res.getByTestId(`case-action-popover-button-${basicCase.id}`)).toBeDisabled(); }); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx index efea537c832b8..a996dd2aed021 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx @@ -16,76 +16,73 @@ import { FormTestComponent } from '../../common/test_utils'; const onSubmit = jest.fn(); -// FLAKY: https://github.com/elastic/kibana/issues/188951 -for (let i = 0; i < 50; i++) { - describe('Severity form field', () => { - let appMockRender: AppMockRenderer; +describe('Severity form field', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders', async () => { - appMockRender.render( - - - - ); + it('renders', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - expect(await screen.findByTestId('case-severity-selection')).toBeEnabled(); - }); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('case-severity-selection')).toBeEnabled(); + }); - // default to LOW in this test configuration - it('defaults to the correct value', async () => { - appMockRender.render( - - - - ); + // default to LOW in this test configuration + it('defaults to the correct value', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - expect(await screen.findByTestId('case-severity-selection-low')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('case-severity-selection-low')).toBeInTheDocument(); + }); - it('selects the correct value when changed', async () => { - appMockRender.render( - - - - ); + it('selects the correct value when changed', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); + expect(await screen.findByTestId('caseSeverity')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('case-severity-selection')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('case-severity-selection')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('case-severity-selection-high')); + userEvent.click(await screen.findByTestId('case-severity-selection-high')); - userEvent.click(await screen.findByTestId('form-test-component-submit-button')); + userEvent.click(await screen.findByTestId('form-test-component-submit-button')); - await waitFor(() => { - // data, isValid - expect(onSubmit).toBeCalledWith({ severity: 'high' }, true); - }); + await waitFor(() => { + // data, isValid + expect(onSubmit).toBeCalledWith({ severity: 'high' }, true); }); + }); - it('disables when loading data', async () => { - appMockRender.render( - - - - ); + it('disables when loading data', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('case-severity-selection')).toBeDisabled(); - }); + expect(await screen.findByTestId('case-severity-selection')).toBeDisabled(); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx index 02418b8114f61..a7cbff3457d0f 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx @@ -14,80 +14,77 @@ import { FormTestComponent } from '../../common/test_utils'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; -// Failing: See https://github.com/elastic/kibana/issues/190270 -for (let i = 0; i < 50; i++) { - describe('SyncAlertsToggle', () => { - let appMockRender: AppMockRenderer; - const onSubmit = jest.fn(); - const defaultFormProps = { - onSubmit, - formDefaultValue: { syncAlerts: true }, - schema: { - syncAlerts: schema.syncAlerts, - }, - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); +describe('SyncAlertsToggle', () => { + let appMockRender: AppMockRenderer; + const onSubmit = jest.fn(); + const defaultFormProps = { + onSubmit, + formDefaultValue: { syncAlerts: true }, + schema: { + syncAlerts: schema.syncAlerts, + }, + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('it renders', async () => { - appMockRender.render( - - - - ); + it('it renders', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('caseSyncAlerts')).toBeInTheDocument(); - expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'true'); - expect(await screen.findByText('On')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('caseSyncAlerts')).toBeInTheDocument(); + expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'true'); + expect(await screen.findByText('On')).toBeInTheDocument(); + }); - it('it toggles the switch', async () => { - appMockRender.render( - - - - ); + it('it toggles the switch', async () => { + appMockRender.render( + + + + ); - const synAlerts = await screen.findByTestId('caseSyncAlerts'); + const synAlerts = await screen.findByTestId('caseSyncAlerts'); - userEvent.click(within(synAlerts).getByRole('switch')); + userEvent.click(within(synAlerts).getByRole('switch')); - expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'false'); - expect(await screen.findByText('Off')).toBeInTheDocument(); - }); + expect(await screen.findByRole('switch')).toHaveAttribute('aria-checked', 'false'); + expect(await screen.findByText('Off')).toBeInTheDocument(); + }); - it('calls onSubmit with correct data', async () => { - appMockRender.render( - - - - ); + it('calls onSubmit with correct data', async () => { + appMockRender.render( + + + + ); - const synAlerts = await screen.findByTestId('caseSyncAlerts'); + const synAlerts = await screen.findByTestId('caseSyncAlerts'); - userEvent.click(within(synAlerts).getByRole('switch')); + userEvent.click(within(synAlerts).getByRole('switch')); - userEvent.click(screen.getByText('Submit')); + userEvent.click(screen.getByText('Submit')); - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - syncAlerts: false, - }, - true - ); - }); + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + syncAlerts: false, + }, + true + ); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx index 0095526ff9fb7..5030dadfd9cb8 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx @@ -26,97 +26,94 @@ const caseData: CaseUI = { comments: [...basicCase.comments, alertCommentWithIndices], }; -// FLAKY: https://github.com/elastic/kibana/issues/185046 -for (let i = 0; i < 50; i++) { - describe('Case View Page files tab', () => { - let appMockRender: AppMockRenderer; +describe('Case View Page files tab', () => { + let appMockRender: AppMockRenderer; - useGetCaseFilesMock.mockReturnValue({ - data: { files: [], total: 11 }, - isLoading: false, - }); + useGetCaseFilesMock.mockReturnValue({ + data: { files: [], total: 11 }, + isLoading: false, + }); - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('should render the utility bar for the files table', async () => { - appMockRender.render(); + it('should render the utility bar for the files table', async () => { + appMockRender.render(); - expect((await screen.findAllByTestId('cases-files-add')).length).toBe(2); - expect(await screen.findByTestId('cases-files-search')).toBeInTheDocument(); - }); + expect((await screen.findAllByTestId('cases-files-add')).length).toBe(2); + expect(await screen.findByTestId('cases-files-search')).toBeInTheDocument(); + }); - it('should render the files table', async () => { - appMockRender.render(); + it('should render the files table', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + }); - it('clicking table pagination triggers calls to useGetCaseFiles', async () => { - appMockRender.render(); + it('clicking table pagination triggers calls to useGetCaseFiles', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('pagination-button-next')); + userEvent.click(await screen.findByTestId('pagination-button-next')); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page + 1, - perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, - }) - ); - }); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page + 1, + perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, + }) + ); + }); - it('changing perPage value triggers calls to useGetCaseFiles', async () => { - const targetPagination = 50; + it('changing perPage value triggers calls to useGetCaseFiles', async () => { + const targetPagination = 50; - appMockRender.render(); + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - userEvent.click(screen.getByTestId('tablePaginationPopoverButton')); + userEvent.click(screen.getByTestId('tablePaginationPopoverButton')); - const pageSizeOption = screen.getByTestId('tablePagination-50-rows'); + const pageSizeOption = screen.getByTestId('tablePagination-50-rows'); - pageSizeOption.style.pointerEvents = 'all'; + pageSizeOption.style.pointerEvents = 'all'; - userEvent.click(pageSizeOption); + userEvent.click(pageSizeOption); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, - perPage: targetPagination, - }) - ); - }); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, + perPage: targetPagination, + }) + ); + }); - it('search by word triggers calls to useGetCaseFiles', async () => { - appMockRender.render(); + it('search by word triggers calls to useGetCaseFiles', async () => { + appMockRender.render(); - expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-table')).toBeInTheDocument(); - await userEvent.type(screen.getByTestId('cases-files-search'), 'Foobar{enter}'); + await userEvent.type(screen.getByTestId('cases-files-search'), 'Foobar{enter}'); - await waitFor(() => - expect(useGetCaseFilesMock).toHaveBeenCalledWith({ - caseId: basicCase.id, - page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, - perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, - searchTerm: 'Foobar', - }) - ); - }); + await waitFor(() => + expect(useGetCaseFilesMock).toHaveBeenCalledWith({ + caseId: basicCase.id, + page: DEFAULT_CASE_FILES_FILTERING_OPTIONS.page, + perPage: DEFAULT_CASE_FILES_FILTERING_OPTIONS.perPage, + searchTerm: 'Foobar', + }) + ); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx index a4eb95ecfd553..2361282b68054 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx @@ -16,240 +16,238 @@ import { customFieldsMock, customFieldsConfigurationMock } from '../../../contai import userEvent from '@testing-library/user-event'; import { CustomFieldTypes } from '../../../../common/types/domain'; -for (let i = 0; i < 50; i++) { - describe('Case View Page files tab', () => { - const onSubmit = jest.fn(); - let appMockRender: AppMockRenderer; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); +describe('Case View Page files tab', () => { + const onSubmit = jest.fn(); + let appMockRender: AppMockRenderer; - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - it('should render the custom fields correctly', async () => { - appMockRender.render( - - ); - - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_3')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_4')).toBeInTheDocument(); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('should render the custom fields types when the custom fields are empty', async () => { - appMockRender.render( - - ); - - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); - expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); - }); + it('should render the custom fields correctly', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_3')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_4')).toBeInTheDocument(); + }); - it('should not show the custom fields if the configuration is empty', () => { - appMockRender.render( - - ); - - expect(screen.queryByTestId('case-custom-field-wrapper-test_key_1')).not.toBeInTheDocument(); - expect(screen.queryByTestId('case-custom-field-wrapper-test_key_2')).not.toBeInTheDocument(); - }); + it('should render the custom fields types when the custom fields are empty', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_1')).toBeInTheDocument(); + expect(await screen.findByTestId('case-custom-field-wrapper-test_key_2')).toBeInTheDocument(); + }); - it('should sort the custom fields correctly', async () => { - const reversedConfiguration = [...customFieldsConfigurationMock].reverse(); + it('should not show the custom fields if the configuration is empty', () => { + appMockRender.render( + + ); + + expect(screen.queryByTestId('case-custom-field-wrapper-test_key_1')).not.toBeInTheDocument(); + expect(screen.queryByTestId('case-custom-field-wrapper-test_key_2')).not.toBeInTheDocument(); + }); - appMockRender.render( - - ); + it('should sort the custom fields correctly', async () => { + const reversedConfiguration = [...customFieldsConfigurationMock].reverse(); - const customFields = await screen.findAllByTestId('case-custom-field-wrapper', { - exact: false, - }); + appMockRender.render( + + ); - expect(customFields.length).toBe(4); - - expect(await within(customFields[0]).findByRole('heading')).toHaveTextContent( - 'My test label 1' - ); - expect(await within(customFields[1]).findByRole('heading')).toHaveTextContent( - 'My test label 2' - ); - expect(await within(customFields[2]).findByRole('heading')).toHaveTextContent( - 'My test label 3' - ); - expect(await within(customFields[3]).findByRole('heading')).toHaveTextContent( - 'My test label 4' - ); + const customFields = await screen.findAllByTestId('case-custom-field-wrapper', { + exact: false, }); - it('pass the permissions to custom fields correctly', async () => { - appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); - - appMockRender.render( - - ); - - expect( - screen.queryByTestId('case-text-custom-field-edit-button-test_key_1') - ).not.toBeInTheDocument(); - }); + expect(customFields.length).toBe(4); + + expect(await within(customFields[0]).findByRole('heading')).toHaveTextContent( + 'My test label 1' + ); + expect(await within(customFields[1]).findByRole('heading')).toHaveTextContent( + 'My test label 2' + ); + expect(await within(customFields[2]).findByRole('heading')).toHaveTextContent( + 'My test label 3' + ); + expect(await within(customFields[3]).findByRole('heading')).toHaveTextContent( + 'My test label 4' + ); + }); + + it('pass the permissions to custom fields correctly', async () => { + appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); + + appMockRender.render( + + ); + + expect( + screen.queryByTestId('case-text-custom-field-edit-button-test_key_1') + ).not.toBeInTheDocument(); + }); - it('removes extra custom fields', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByRole('switch')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: false, - }); + it('removes extra custom fields', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByRole('switch')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: false, }); }); + }); - it('updates an existing toggle field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click((await screen.findAllByRole('switch'))[0]); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: false, - }); + it('updates an existing toggle field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click((await screen.findAllByRole('switch'))[0]); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: false, }); }); + }); - it('updates new toggle field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click((await screen.findAllByRole('switch'))[0]); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - type: CustomFieldTypes.TOGGLE, - key: 'test_key_2', - value: true, - }); + it('updates new toggle field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click((await screen.findAllByRole('switch'))[0]); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + type: CustomFieldTypes.TOGGLE, + key: 'test_key_2', + value: true, }); }); + }); - it('updates existing text field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click( - await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) - ); - - userEvent.paste( - await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), - '!!!' - ); - - userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - ...customFieldsMock[0], - value: 'My text test value 1!!!', - }); + it('updates existing text field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click( + await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) + ); + + userEvent.paste( + await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), + '!!!' + ); + + userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + ...customFieldsMock[0], + value: 'My text test value 1!!!', }); }); + }); - it('updates new text field correctly', async () => { - appMockRender.render( - - ); - - userEvent.click( - await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) - ); - - expect( - await screen.findByText('This field is populated with the default value.') - ).toBeInTheDocument(); - - userEvent.paste( - await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), - ' updated!!' - ); - - userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith({ - ...customFieldsMock[0], - value: `${customFieldsConfigurationMock[0].defaultValue} updated!!`, - }); + it('updates new text field correctly', async () => { + appMockRender.render( + + ); + + userEvent.click( + await screen.findByTestId(`case-text-custom-field-edit-button-${customFieldsMock[0].key}`) + ); + + expect( + await screen.findByText('This field is populated with the default value.') + ).toBeInTheDocument(); + + userEvent.paste( + await screen.findByTestId('case-text-custom-field-form-field-test_key_1'), + ' updated!!' + ); + + userEvent.click(await screen.findByTestId('case-text-custom-field-submit-button-test_key_1')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith({ + ...customFieldsMock[0], + value: `${customFieldsConfigurationMock[0].defaultValue} updated!!`, }); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index 10b8ad2da9de8..2accabb73a9e2 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -19,90 +19,85 @@ jest.mock('../../common/lib/kibana'); const useKibanaMock = useKibana as jest.Mocked; -// FLAKY: https://github.com/elastic/kibana/issues/189530 -for (let i = 0; i < 50; i++) { - describe('ConnectorSelector', () => { - const handleChange = jest.fn(); - const defaultProps = { - connectors: [], - handleChange, - dataTestSubj: 'connectors', - disabled: false, - idAria: 'connectors', - isLoading: false, - }; +describe('ConnectorSelector', () => { + const handleChange = jest.fn(); + const defaultProps = { + connectors: [], + handleChange, + dataTestSubj: 'connectors', + disabled: false, + idAria: 'connectors', + isLoading: false, + }; - let appMock: AppMockRenderer; + let appMock: AppMockRenderer; - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - beforeEach(() => { - useKibanaMock().services.triggersActionsUi.actionTypeRegistry.get = jest - .fn() - .mockReturnValue({ - actionTypeTitle: 'test', - iconClass: 'logoSecurity', - }); + beforeEach(() => { + useKibanaMock().services.triggersActionsUi.actionTypeRegistry.get = jest.fn().mockReturnValue({ + actionTypeTitle: 'test', + iconClass: 'logoSecurity', }); + }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('should render', async () => { - appMock.render( - - - - ); + it('should render', async () => { + appMock.render( + + + + ); - expect(await screen.findByTestId(defaultProps.dataTestSubj)); - }); + expect(await screen.findByTestId(defaultProps.dataTestSubj)); + }); - it('should set the selected connector to none if the connector is not available', async () => { - appMock.render( - - - - ); + it('should set the selected connector to none if the connector is not available', async () => { + appMock.render( + + + + ); - expect(await screen.findByText('No connector selected')); - }); + expect(await screen.findByText('No connector selected')); + }); - it('should set the selected connector correctly', async () => { - appMock.render( - - - - ); + it('should set the selected connector correctly', async () => { + appMock.render( + + + + ); - expect(await screen.findByText(connectorsMock[0].name)); - }); + expect(await screen.findByText(connectorsMock[0].name)); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/create/template.test.tsx b/x-pack/plugins/cases/public/components/create/template.test.tsx index 53ddff8fe4183..371ef075c08f4 100644 --- a/x-pack/plugins/cases/public/components/create/template.test.tsx +++ b/x-pack/plugins/cases/public/components/create/template.test.tsx @@ -13,79 +13,76 @@ import { createAppMockRenderer } from '../../common/mock'; import { templatesConfigurationMock } from '../../containers/mock'; import { TemplateSelector } from './templates'; -// FLAKY: https://github.com/elastic/kibana/issues/178457 -for (let i = 0; i < 50; i++) { - describe('CustomFields', () => { - let appMockRender: AppMockRenderer; - const onTemplateChange = jest.fn(); +describe('CustomFields', () => { + let appMockRender: AppMockRenderer; + const onTemplateChange = jest.fn(); - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders correctly', async () => { - appMockRender.render( - - ); + it('renders correctly', async () => { + appMockRender.render( + + ); - expect(await screen.findByText('Template name')).toBeInTheDocument(); - expect(await screen.findByTestId('create-case-template-select')).toBeInTheDocument(); - }); + expect(await screen.findByText('Template name')).toBeInTheDocument(); + expect(await screen.findByTestId('create-case-template-select')).toBeInTheDocument(); + }); - it('selects a template correctly', async () => { - const selectedTemplate = templatesConfigurationMock[2]; + it('selects a template correctly', async () => { + const selectedTemplate = templatesConfigurationMock[2]; - appMockRender.render( - - ); + appMockRender.render( + + ); - userEvent.selectOptions( - await screen.findByTestId('create-case-template-select'), - selectedTemplate.key - ); + userEvent.selectOptions( + await screen.findByTestId('create-case-template-select'), + selectedTemplate.key + ); - await waitFor(() => { - expect(onTemplateChange).toHaveBeenCalledWith(selectedTemplate.caseFields); - }); + await waitFor(() => { + expect(onTemplateChange).toHaveBeenCalledWith(selectedTemplate.caseFields); }); + }); - it('shows the selected option correctly', async () => { - const selectedTemplate = templatesConfigurationMock[2]; + it('shows the selected option correctly', async () => { + const selectedTemplate = templatesConfigurationMock[2]; - appMockRender.render( - - ); + appMockRender.render( + + ); - userEvent.selectOptions( - await screen.findByTestId('create-case-template-select'), - selectedTemplate.key - ); + userEvent.selectOptions( + await screen.findByTestId('create-case-template-select'), + selectedTemplate.key + ); - expect( - (await screen.findByRole('option', { name: selectedTemplate.name })) - .selected - ).toBe(true); - }); + expect( + (await screen.findByRole('option', { name: selectedTemplate.name })) + .selected + ).toBe(true); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx index 7ac62b19bd2a8..9e40ec0e4f61b 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx @@ -15,71 +15,68 @@ import { FormTestComponent } from '../../common/test_utils'; import { CustomFieldTypes } from '../../../common/types/domain'; import { FormFields } from './form_fields'; -// FLAKY: https://github.com/elastic/kibana/issues/188450 -for (let i = 0; i < 50; i++) { - describe('FormFields ', () => { - let appMockRender: AppMockRenderer; - const onSubmit = jest.fn(); +describe('FormFields ', () => { + let appMockRender: AppMockRenderer; + const onSubmit = jest.fn(); - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders correctly', async () => { - appMockRender.render( - - - - ); + it('renders correctly', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('custom-field-label-input')).toBeInTheDocument(); - expect(await screen.findByTestId('custom-field-type-selector')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('custom-field-label-input')).toBeInTheDocument(); + expect(await screen.findByTestId('custom-field-type-selector')).toBeInTheDocument(); + }); - it('disables field type selector on edit mode', async () => { - appMockRender.render( - - - - ); + it('disables field type selector on edit mode', async () => { + appMockRender.render( + + + + ); - expect(await screen.findByTestId('custom-field-type-selector')).toHaveAttribute('disabled'); - }); + expect(await screen.findByTestId('custom-field-type-selector')).toHaveAttribute('disabled'); + }); - it('submit data correctly', async () => { - appMockRender.render( - - - - ); + it('submit data correctly', async () => { + appMockRender.render( + + + + ); - fireEvent.change(await screen.findByTestId('custom-field-type-selector'), { - target: { value: CustomFieldTypes.TOGGLE }, - }); + fireEvent.change(await screen.findByTestId('custom-field-type-selector'), { + target: { value: CustomFieldTypes.TOGGLE }, + }); - userEvent.type(await screen.findByTestId('custom-field-label-input'), 'hello'); - userEvent.click(await screen.findByText('Submit')); + userEvent.type(await screen.findByTestId('custom-field-label-input'), 'hello'); + userEvent.click(await screen.findByText('Submit')); - await waitFor(() => { - // data, isValid - expect(onSubmit).toBeCalledWith( - { - label: 'hello', - type: CustomFieldTypes.TOGGLE, - defaultValue: false, - }, - true - ); - }); + await waitFor(() => { + // data, isValid + expect(onSubmit).toBeCalledWith( + { + label: 'hello', + type: CustomFieldTypes.TOGGLE, + defaultValue: false, + }, + true + ); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index a61ed6c5d9736..9285dc9f0d73a 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -27,157 +27,150 @@ const defaultProps = { isLoadingDescription: false, }; -// Failing: See https://github.com/elastic/kibana/issues/185879 -for (let i = 0; i < 50; i++) { - describe('Description', () => { - const onUpdateField = jest.fn(); - let appMockRender: AppMockRenderer; +describe('Description', () => { + const onUpdateField = jest.fn(); + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders description correctly', async () => { - appMockRender.render(); + it('renders description correctly', async () => { + appMockRender.render(); - expect(await screen.findByTestId('description')).toBeInTheDocument(); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('description')).toBeInTheDocument(); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - it('hides and shows the description correctly when collapse button clicked', async () => { - appMockRender.render(); + it('hides and shows the description correctly when collapse button clicked', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); - await waitFor(() => { - expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument(); - }); + await waitFor(() => { + expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument(); + }); - userEvent.click(await screen.findByTestId('description-collapse-icon')); + userEvent.click(await screen.findByTestId('description-collapse-icon')); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - }); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - it('shows textarea on edit click', async () => { - appMockRender.render(); + it('shows textarea on edit click', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument(); + }); - it('edits the description correctly when saved', async () => { - const editedDescription = 'New updated description'; - appMockRender.render(); + it('edits the description correctly when saved', async () => { + const editedDescription = 'New updated description'; + appMockRender.render(); - userEvent.click(await screen.findByTestId('description-edit-icon')); + userEvent.click(await screen.findByTestId('description-edit-icon')); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + userEvent.click(await screen.findByTestId('editable-save-markdown')); - await waitFor(() => { - expect(onUpdateField).toHaveBeenCalledWith({ - key: 'description', - value: editedDescription, - }); + await waitFor(() => { + expect(onUpdateField).toHaveBeenCalledWith({ + key: 'description', + value: editedDescription, }); }); + }); - it('keeps the old description correctly when canceled', async () => { - const editedDescription = 'New updated description'; - appMockRender.render(); - - userEvent.click(await screen.findByTestId('description-edit-icon')); + it('keeps the old description correctly when canceled', async () => { + const editedDescription = 'New updated description'; + appMockRender.render(); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); + userEvent.click(await screen.findByTestId('description-edit-icon')); - expect(await screen.findByText(editedDescription)).toBeInTheDocument(); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription); - userEvent.click(await screen.findByTestId('editable-cancel-markdown')); + expect(await screen.findByText(editedDescription)).toBeInTheDocument(); - await waitFor(() => { - expect(onUpdateField).not.toHaveBeenCalled(); - }); + userEvent.click(await screen.findByTestId('editable-cancel-markdown')); - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + await waitFor(() => { + expect(onUpdateField).not.toHaveBeenCalled(); }); - it('shows an error when description is too long', async () => { - const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1); + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + }); - appMockRender.render(); + it('shows an error when description is too long', async () => { + const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1); - userEvent.click(await screen.findByTestId('description-edit-icon')); + appMockRender.render(); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription); + userEvent.click(await screen.findByTestId('description-edit-icon')); - expect( - await screen.findByText( - 'The length of the description is too long. The maximum length is 30000 characters.' - ) - ).toBeInTheDocument(); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription); - expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled'); - }); + expect( + await screen.findByText( + 'The length of the description is too long. The maximum length is 30000 characters.' + ) + ).toBeInTheDocument(); + + expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled'); + }); + + it('should hide the edit button when the user does not have update permissions', async () => { + appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() }); + appMockRender.render(); + + expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); + expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument(); + }); + + it('should display description when case is loading', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('description')).toBeInTheDocument(); + }); - it('should hide the edit button when the user does not have update permissions', async () => { - appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() }); - appMockRender.render(); + describe('draft message', () => { + const draftStorageKey = `cases.securitySolution.basic-case-id.description.markdownEditor`; - expect(await screen.findByText('Security banana Issue')).toBeInTheDocument(); - expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument(); + beforeEach(() => { + sessionStorage.setItem(draftStorageKey, 'value set in storage'); }); - it('should display description when case is loading', async () => { + it('should not show unsaved draft message when loading', async () => { appMockRender.render( ); - expect(await screen.findByTestId('description')).toBeInTheDocument(); + expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); }); - describe('draft message', () => { - const draftStorageKey = `cases.securitySolution.basic-case-id.description.markdownEditor`; + it('should not show unsaved draft message when description and storage value are same', async () => { + const props = { + ...defaultProps, + caseData: { ...defaultProps.caseData, description: 'value set in storage' }, + }; - beforeEach(() => { - sessionStorage.setItem(draftStorageKey, 'value set in storage'); - }); + appMockRender.render(); - it('should not show unsaved draft message when loading', async () => { - appMockRender.render( - - ); - - expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); - }); - - it('should not show unsaved draft message when description and storage value are same', async () => { - const props = { - ...defaultProps, - caseData: { ...defaultProps.caseData, description: 'value set in storage' }, - }; - - appMockRender.render(); - - expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('description-unsaved-draft')).not.toBeInTheDocument(); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index d1f920a982e96..b21b35b3dbaec 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -16,36 +16,33 @@ import { createAppMockRenderer } from '../../common/mock'; import { basicFileMock } from '../../containers/mock'; import { FileAttachmentEvent } from './file_attachment_event'; -// FLAKY: https://github.com/elastic/kibana/issues/174661 -for (let i = 0; i < 50; i++) { - describe('FileAttachmentEvent', () => { - let appMockRender: AppMockRenderer; +describe('FileAttachmentEvent', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('renders clickable name', async () => { - appMockRender.render( - - ); + it('renders clickable name', async () => { + appMockRender.render( + + ); - const nameLink = await screen.findByTestId('cases-files-name-link'); + const nameLink = await screen.findByTestId('cases-files-name-link'); - expect(nameLink).toBeInTheDocument(); + expect(nameLink).toBeInTheDocument(); - userEvent.click(nameLink); + userEvent.click(nameLink); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx index 806e930998d40..990b13935608d 100644 --- a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx @@ -16,56 +16,51 @@ import { createAppMockRenderer, mockedTestProvidersOwner } from '../../common/mo import { basicFileMock } from '../../containers/mock'; import { FilePreview } from './file_preview'; -// FLAKY: https://github.com/elastic/kibana/issues/182364 -for (let i = 0; i < 50; i++) { - describe('FilePreview', () => { - let appMockRender: AppMockRenderer; +describe('FilePreview', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - it('FilePreview rendered correctly', async () => { - appMockRender.render(); + it('FilePreview rendered correctly', async () => { + appMockRender.render(); - await waitFor(() => - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - id: basicFileMock.id, - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - }) - ); + await waitFor(() => + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + id: basicFileMock.id, + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + }) + ); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + }); - it('pressing escape calls closePreview', async () => { - const closePreview = jest.fn(); + it('pressing escape calls closePreview', async () => { + const closePreview = jest.fn(); - appMockRender.render( - - ); + appMockRender.render(); - await waitFor(() => - expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ - id: basicFileMock.id, - fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), - }) - ); + await waitFor(() => + expect(appMockRender.getFilesClient().getDownloadHref).toHaveBeenCalledWith({ + id: basicFileMock.id, + fileKind: constructFileKindIdByOwner(mockedTestProvidersOwner[0]), + }) + ); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - userEvent.keyboard('{esc}'); + userEvent.keyboard('{esc}'); - await waitFor(() => expect(closePreview).toHaveBeenCalled()); - }); + await waitFor(() => expect(closePreview).toHaveBeenCalled()); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index b2ff448473771..f1c5a697602e9 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -17,189 +17,186 @@ import { basicCase, basicFileMock } from '../../containers/mock'; import { getFileType } from './file_type'; import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; -// FLAKY: https://github.com/elastic/kibana/issues/175841 -for (let i = 0; i < 50; i++) { - describe('getFileType', () => { - const fileType = getFileType(); - - it('invalid props return blank FileAttachmentViewObject', () => { - expect(fileType).toStrictEqual({ - id: FILE_ATTACHMENT_TYPE, - icon: 'document', - displayName: 'Files', - getAttachmentViewObject: expect.any(Function), - getAttachmentRemovalObject: expect.any(Function), - }); +describe('getFileType', () => { + const fileType = getFileType(); + + it('invalid props return blank FileAttachmentViewObject', () => { + expect(fileType).toStrictEqual({ + id: FILE_ATTACHMENT_TYPE, + icon: 'document', + displayName: 'Files', + getAttachmentViewObject: expect.any(Function), + getAttachmentRemovalObject: expect.any(Function), }); + }); - describe('getFileAttachmentViewObject', () => { - let appMockRender: AppMockRenderer; + describe('getFileAttachmentViewObject', () => { + let appMockRender: AppMockRenderer; - const attachmentViewProps: ExternalReferenceAttachmentViewProps = { - externalReferenceId: basicFileMock.id, - // @ts-expect-error: files is a proper JSON - externalReferenceMetadata: { files: [basicFileMock] }, - caseData: { title: basicCase.title, id: basicCase.id }, - }; + const attachmentViewProps: ExternalReferenceAttachmentViewProps = { + externalReferenceId: basicFileMock.id, + // @ts-expect-error: files is a proper JSON + externalReferenceMetadata: { files: [basicFileMock] }, + caseData: { title: basicCase.title, id: basicCase.id }, + }; - beforeEach(() => { - jest.clearAllMocks(); - }); - - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); - }); + beforeEach(() => { + jest.clearAllMocks(); + }); - it('event renders a clickable name if the file is an image', async () => { - appMockRender = createAppMockRenderer(); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - // @ts-expect-error: event is defined - appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); - expect(await screen.findByText('my-super-cool-screenshot.png')).toBeInTheDocument(); - expect(screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); - }); + it('event renders a clickable name if the file is an image', async () => { + appMockRender = createAppMockRenderer(); - it('clicking the name rendered in event opens the file preview', async () => { - appMockRender = createAppMockRenderer(); + // @ts-expect-error: event is defined + appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); - // @ts-expect-error: event is a React element - appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); + expect(await screen.findByText('my-super-cool-screenshot.png')).toBeInTheDocument(); + expect(screen.queryByTestId('cases-files-image-preview')).not.toBeInTheDocument(); + }); - userEvent.click(await screen.findByText('my-super-cool-screenshot.png')); - expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); - }); + it('clicking the name rendered in event opens the file preview', async () => { + appMockRender = createAppMockRenderer(); - it('getActions renders a download button', async () => { - appMockRender = createAppMockRenderer(); + // @ts-expect-error: event is a React element + appMockRender.render(fileType.getAttachmentViewObject({ ...attachmentViewProps }).event); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + userEvent.click(await screen.findByText('my-super-cool-screenshot.png')); + expect(await screen.findByTestId('cases-files-image-preview')).toBeInTheDocument(); + }); - expect(attachmentViewObject).not.toBeUndefined(); + it('getActions renders a download button', async () => { + appMockRender = createAppMockRenderer(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(actions.length).toBe(2); - expect(actions[0]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[0].render()); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument(); + expect(actions.length).toBe(2); + expect(actions[0]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), }); - it('getActions renders a delete button', async () => { - appMockRender = createAppMockRenderer(); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[0].render()); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + expect(await screen.findByTestId('cases-files-download-button')).toBeInTheDocument(); + }); - expect(attachmentViewObject).not.toBeUndefined(); + it('getActions renders a delete button', async () => { + appMockRender = createAppMockRenderer(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(actions.length).toBe(2); - expect(actions[1]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[1].render()); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); + expect(actions.length).toBe(2); + expect(actions[1]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), }); - it('clicking the delete button in actions opens deletion modal', async () => { - appMockRender = createAppMockRenderer(); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[1].render()); - const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); + expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); + }); - expect(attachmentViewObject).not.toBeUndefined(); + it('clicking the delete button in actions opens deletion modal', async () => { + appMockRender = createAppMockRenderer(); - // @ts-expect-error: object is defined - const actions = attachmentViewObject.getActions(); + const attachmentViewObject = fileType.getAttachmentViewObject({ ...attachmentViewProps }); - expect(actions.length).toBe(2); - expect(actions[1]).toStrictEqual({ - type: AttachmentActionType.CUSTOM, - isPrimary: false, - render: expect.any(Function), - }); + expect(attachmentViewObject).not.toBeUndefined(); - // @ts-expect-error: render exists on CustomAttachmentAction - appMockRender.render(actions[1].render()); + // @ts-expect-error: object is defined + const actions = attachmentViewObject.getActions(); - const deleteButton = await screen.findByTestId('cases-files-delete-button'); + expect(actions.length).toBe(2); + expect(actions[1]).toStrictEqual({ + type: AttachmentActionType.CUSTOM, + isPrimary: false, + render: expect.any(Function), + }); - expect(deleteButton).toBeInTheDocument(); + // @ts-expect-error: render exists on CustomAttachmentAction + appMockRender.render(actions[1].render()); - userEvent.click(deleteButton); + const deleteButton = await screen.findByTestId('cases-files-delete-button'); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + expect(deleteButton).toBeInTheDocument(); - it('empty externalReferenceMetadata returns blank FileAttachmentViewObject', () => { - expect( - fileType.getAttachmentViewObject({ - ...attachmentViewProps, - externalReferenceMetadata: {}, - }) - ).toEqual({ - event: 'added an unknown file', - hideDefaultActions: true, - timelineAvatar: 'document', - getActions: expect.any(Function), - }); - }); + userEvent.click(deleteButton); - it('timelineAvatar is image if file is an image', () => { - expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( - expect.objectContaining({ - timelineAvatar: 'image', - }) - ); - }); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + }); - it('timelineAvatar is document if file is not an image', () => { - expect( - fileType.getAttachmentViewObject({ - ...attachmentViewProps, - externalReferenceMetadata: { - files: [{ ...basicFileMock, mimeType: 'text/csv' } as JsonValue], - }, - }) - ).toEqual( - expect.objectContaining({ - timelineAvatar: 'document', - }) - ); + it('empty externalReferenceMetadata returns blank FileAttachmentViewObject', () => { + expect( + fileType.getAttachmentViewObject({ + ...attachmentViewProps, + externalReferenceMetadata: {}, + }) + ).toEqual({ + event: 'added an unknown file', + hideDefaultActions: true, + timelineAvatar: 'document', + getActions: expect.any(Function), }); + }); - it('default actions should be hidden', () => { - expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( - expect.objectContaining({ - hideDefaultActions: true, - }) - ); - }); + it('timelineAvatar is image if file is an image', () => { + expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( + expect.objectContaining({ + timelineAvatar: 'image', + }) + ); }); - describe('getFileAttachmentRemovalObject', () => { - it('event renders the right message', async () => { - // @ts-expect-error: object is defined - expect(fileType.getAttachmentRemovalObject().event).toBe('removed file'); - }); + it('timelineAvatar is document if file is not an image', () => { + expect( + fileType.getAttachmentViewObject({ + ...attachmentViewProps, + externalReferenceMetadata: { + files: [{ ...basicFileMock, mimeType: 'text/csv' } as JsonValue], + }, + }) + ).toEqual( + expect.objectContaining({ + timelineAvatar: 'document', + }) + ); + }); + + it('default actions should be hidden', () => { + expect(fileType.getAttachmentViewObject(attachmentViewProps)).toEqual( + expect.objectContaining({ + hideDefaultActions: true, + }) + ); + }); + }); + + describe('getFileAttachmentRemovalObject', () => { + it('event renders the right message', async () => { + // @ts-expect-error: object is defined + expect(fileType.getAttachmentRemovalObject().event).toBe('removed file'); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx index cfee7af9064b4..f1b1d12ba2571 100644 --- a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx +++ b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx @@ -15,47 +15,129 @@ import { createAppMockRenderer } from '../../common/mock'; import { FilterPopover } from '.'; -// FLAKY: https://github.com/elastic/kibana/issues/176679 -for (let i = 0; i < 50; i++) { - describe('FilterPopover ', () => { - let appMockRender: AppMockRenderer; - const onSelectedOptionsChanged = jest.fn(); - const tags: string[] = ['coke', 'pepsi']; - - beforeEach(() => { - appMockRender = createAppMockRenderer(); - jest.clearAllMocks(); - }); +describe('FilterPopover ', () => { + let appMockRender: AppMockRenderer; + const onSelectedOptionsChanged = jest.fn(); + const tags: string[] = ['coke', 'pepsi']; + + beforeEach(() => { + appMockRender = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); + + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + + it('renders button label correctly', async () => { + appMockRender.render( + + ); + + expect(await screen.findByTestId('options-filter-popover-button-Tags')).toBeInTheDocument(); + }); + + it('renders empty label correctly', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + expect(await screen.findByText('No options available')).toBeInTheDocument(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + it('renders string type options correctly', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + expect(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)).toBeInTheDocument(); + expect(await screen.findByTestId(`options-filter-popover-item-${tags[1]}`)).toBeInTheDocument(); + }); + + it('should call onSelectionChange with selected option', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); + + await waitForEuiPopoverOpen(); + + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); + + await waitFor(() => { + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([tags[0]]); }); + }); - it('renders button label correctly', async () => { - appMockRender.render( - - ); + it('should call onSelectionChange with empty array when option is deselected', async () => { + appMockRender.render( + + ); + + userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - expect(await screen.findByTestId('options-filter-popover-button-Tags')).toBeInTheDocument(); + await waitForEuiPopoverOpen(); + + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); + + await waitFor(() => { + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([]); }); + }); - it('renders empty label correctly', async () => { + describe('maximum limit', () => { + const newTags = ['coke', 'pepsi', 'sprite', 'juice', 'water']; + const maxLength = 3; + const maxLengthLabel = `You have selected maximum number of ${maxLength} tags to filter`; + + it('should show message when maximum options are selected', async () => { appMockRender.render( ); @@ -63,16 +145,24 @@ for (let i = 0; i < 50; i++) { await waitForEuiPopoverOpen(); - expect(await screen.findByText('No options available')).toBeInTheDocument(); + expect(await screen.findByTestId('maximum-length-warning')).toHaveTextContent(maxLengthLabel); + + expect(await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`)).toHaveProperty( + 'disabled' + ); + expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( + 'disabled' + ); }); - it('renders string type options correctly', async () => { + it('should not show message when maximum length label is missing', async () => { appMockRender.render( ); @@ -80,21 +170,23 @@ for (let i = 0; i < 50; i++) { await waitForEuiPopoverOpen(); - expect( - await screen.findByTestId(`options-filter-popover-item-${tags[0]}`) - ).toBeInTheDocument(); - expect( - await screen.findByTestId(`options-filter-popover-item-${tags[1]}`) - ).toBeInTheDocument(); + expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); + expect(await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`)).toHaveProperty( + 'disabled' + ); + expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( + 'disabled' + ); }); - it('should call onSelectionChange with selected option', async () => { + it('should not show message and disable options when maximum length property is missing', async () => { appMockRender.render( ); @@ -102,20 +194,20 @@ for (let i = 0; i < 50; i++) { await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); - - await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([tags[0]]); - }); + expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); + expect(await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`)).toHaveProperty( + 'disabled', + false + ); }); - it('should call onSelectionChange with empty array when option is deselected', async () => { + it('should allow to select more options when maximum length property is missing', async () => { appMockRender.render( ); @@ -123,115 +215,11 @@ for (let i = 0; i < 50; i++) { await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${tags[0]}`)); + userEvent.click(await screen.findByTestId(`options-filter-popover-item-${newTags[1]}`)); await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([]); - }); - }); - - describe('maximum limit', () => { - const newTags = ['coke', 'pepsi', 'sprite', 'juice', 'water']; - const maxLength = 3; - const maxLengthLabel = `You have selected maximum number of ${maxLength} tags to filter`; - - it('should show message when maximum options are selected', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - expect(await screen.findByTestId('maximum-length-warning')).toHaveTextContent( - maxLengthLabel - ); - - expect( - await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`) - ).toHaveProperty('disabled'); - expect( - await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) - ).toHaveProperty('disabled'); - }); - - it('should not show message when maximum length label is missing', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); - expect( - await screen.findByTestId(`options-filter-popover-item-${newTags[3]}`) - ).toHaveProperty('disabled'); - expect( - await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) - ).toHaveProperty('disabled'); - }); - - it('should not show message and disable options when maximum length property is missing', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - expect(screen.queryByTestId('maximum-length-warning')).not.toBeInTheDocument(); - expect( - await screen.findByTestId(`options-filter-popover-item-${newTags[4]}`) - ).toHaveProperty('disabled', false); - }); - - it('should allow to select more options when maximum length property is missing', async () => { - appMockRender.render( - - ); - - userEvent.click(await screen.findByTestId('options-filter-popover-button-Tags')); - - await waitForEuiPopoverOpen(); - - userEvent.click(await screen.findByTestId(`options-filter-popover-item-${newTags[1]}`)); - - await waitFor(() => { - expect(onSelectedOptionsChanged).toHaveBeenCalledWith([ - newTags[0], - newTags[2], - newTags[1], - ]); - }); + expect(onSelectedOptionsChanged).toHaveBeenCalledWith([newTags[0], newTags[2], newTags[1]]); }); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx index 41a83c3d113d5..143121db411e1 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx @@ -61,179 +61,176 @@ const defaultProps = { editorRef, }; -// FLAKY: https://github.com/elastic/kibana/issues/171177 -for (let i = 0; i < 50; i++) { - describe('EditableMarkdown', () => { - let appMockRender: AppMockRenderer; +describe('EditableMarkdown', () => { + let appMockRender: AppMockRenderer; - beforeEach(() => { - jest.clearAllMocks(); - appMockRender = createAppMockRenderer(); - }); + beforeEach(() => { + jest.clearAllMocks(); + appMockRender = createAppMockRenderer(); + }); - afterEach(() => { - sessionStorage.removeItem(draftStorageKey); - }); + afterEach(() => { + sessionStorage.removeItem(draftStorageKey); + }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRender.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + afterEach(async () => { + await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + }); + + it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { + appMockRender.render(); + + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, }); - it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { - appMockRender.render(); + userEvent.click(await screen.findByTestId('editable-save-markdown')); - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, - }); + await waitFor(() => { + expect(onSaveContent).toHaveBeenCalledWith(newValue); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + }); + }); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + it('Does not call onSaveContent if no change from current text', async () => { + appMockRender.render(); - await waitFor(() => { - expect(onSaveContent).toHaveBeenCalledWith(newValue); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); - }); + userEvent.click(await screen.findByTestId('editable-save-markdown')); + + await waitFor(() => { + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); }); + expect(onSaveContent).not.toHaveBeenCalled(); + }); - it('Does not call onSaveContent if no change from current text', async () => { - appMockRender.render(); + it('Cancel button click calls only onChangeEditable', async () => { + appMockRender.render(); - userEvent.click(await screen.findByTestId('editable-save-markdown')); + userEvent.click(await screen.findByTestId('editable-cancel-markdown')); - await waitFor(() => { - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); - }); + await waitFor(() => { expect(onSaveContent).not.toHaveBeenCalled(); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); }); + }); - it('Cancel button click calls only onChangeEditable', async () => { + describe('errors', () => { + it('Shows error message and save button disabled if current text is empty', async () => { appMockRender.render(); - userEvent.click(await screen.findByTestId('editable-cancel-markdown')); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ''); - await waitFor(() => { - expect(onSaveContent).not.toHaveBeenCalled(); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); - }); + expect(await screen.findByText('Required field')).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); }); - describe('errors', () => { - it('Shows error message and save button disabled if current text is empty', async () => { - appMockRender.render(); + it('Shows error message and save button disabled if current text is of empty characters', async () => { + appMockRender.render(); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ''); + userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); + userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ' '); - expect(await screen.findByText('Required field')).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); - }); + expect(await screen.findByText('Required field')).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + }); - it('Shows error message and save button disabled if current text is of empty characters', async () => { - appMockRender.render(); + it('Shows error message and save button disabled if current text is too long', async () => { + const longComment = 'b'.repeat(maxLength + 1); - userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea')); - userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), ' '); + appMockRender.render(); - expect(await screen.findByText('Required field')).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); - }); + const markdown = await screen.findByTestId('euiMarkdownEditorTextArea'); - it('Shows error message and save button disabled if current text is too long', async () => { - const longComment = 'b'.repeat(maxLength + 1); + userEvent.paste(markdown, longComment); - appMockRender.render(); + expect( + await screen.findByText( + `The length of the textarea is too long. The maximum length is ${maxLength} characters.` + ) + ).toBeInTheDocument(); + expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); + }); + }); - const markdown = await screen.findByTestId('euiMarkdownEditorTextArea'); + describe('draft comment ', () => { + beforeAll(() => { + jest.useFakeTimers(); + }); - userEvent.paste(markdown, longComment); + afterEach(() => { + jest.clearAllTimers(); + }); - expect( - await screen.findByText( - `The length of the textarea is too long. The maximum length is ${maxLength} characters.` - ) - ).toBeInTheDocument(); - expect(await screen.findByTestId('editable-save-markdown')).toHaveProperty('disabled'); - }); + afterAll(() => { + jest.useRealTimers(); + sessionStorage.removeItem(draftStorageKey); }); - describe('draft comment ', () => { - beforeAll(() => { - jest.useFakeTimers(); - }); + beforeEach(() => { + jest.clearAllMocks(); + }); - afterEach(() => { - jest.clearAllTimers(); - }); + it('Save button click clears session storage', async () => { + appMockRender.render(); - afterAll(() => { - jest.useRealTimers(); - sessionStorage.removeItem(draftStorageKey); + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, }); - beforeEach(() => { - jest.clearAllMocks(); + act(() => { + jest.advanceTimersByTime(1000); }); - it('Save button click clears session storage', async () => { - appMockRender.render(); - - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, - }); - - act(() => { - jest.advanceTimersByTime(1000); - }); + expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); - expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); - - fireEvent.click(await screen.findByTestId(`editable-save-markdown`)); + fireEvent.click(await screen.findByTestId(`editable-save-markdown`)); - await waitFor(() => { - expect(onSaveContent).toHaveBeenCalledWith(newValue); - expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); - expect(sessionStorage.getItem(draftStorageKey)).toBe(null); - }); + await waitFor(() => { + expect(onSaveContent).toHaveBeenCalledWith(newValue); + expect(onChangeEditable).toHaveBeenCalledWith(defaultProps.id); + expect(sessionStorage.getItem(draftStorageKey)).toBe(null); }); + }); - it('Cancel button click clears session storage', async () => { - appMockRender.render(); + it('Cancel button click clears session storage', async () => { + appMockRender.render(); - expect(sessionStorage.getItem(draftStorageKey)).toBe(''); + expect(sessionStorage.getItem(draftStorageKey)).toBe(''); - fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { - target: { value: newValue }, - }); + fireEvent.change(await screen.findByTestId('euiMarkdownEditorTextArea'), { + target: { value: newValue }, + }); - act(() => { - jest.advanceTimersByTime(1000); - }); + act(() => { + jest.advanceTimersByTime(1000); + }); - await waitFor(() => { - expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); - }); + await waitFor(() => { + expect(sessionStorage.getItem(draftStorageKey)).toBe(newValue); + }); - fireEvent.click(await screen.findByTestId('editable-cancel-markdown')); + fireEvent.click(await screen.findByTestId('editable-cancel-markdown')); - await waitFor(() => { - expect(sessionStorage.getItem(draftStorageKey)).toBe(null); - }); + await waitFor(() => { + expect(sessionStorage.getItem(draftStorageKey)).toBe(null); }); + }); - describe('existing storage key', () => { - beforeEach(() => { - sessionStorage.setItem(draftStorageKey, 'value set in storage'); - }); + describe('existing storage key', () => { + beforeEach(() => { + sessionStorage.setItem(draftStorageKey, 'value set in storage'); + }); - it('should have session storage value same as draft comment', async () => { - appMockRender.render(); + it('should have session storage value same as draft comment', async () => { + appMockRender.render(); - expect(await screen.findByText('value set in storage')).toBeInTheDocument(); - }); + expect(await screen.findByText('value set in storage')).toBeInTheDocument(); }); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx index 0eac04a056adc..63ce2b17155fd 100644 --- a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx @@ -13,140 +13,137 @@ import { createAppMockRenderer } from '../../common/mock'; import { FormTestComponent } from '../../common/test_utils'; import { TemplateFields } from './template_fields'; -// FLAKY: https://github.com/elastic/kibana/issues/187854 -for (let i = 0; i < 50; i++) { - describe('Template fields', () => { - let appMockRenderer: AppMockRenderer; - const onSubmit = jest.fn(); - const formDefaultValue = { templateTags: [] }; - const defaultProps = { - isLoading: false, - configurationTemplateTags: [], - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRenderer = createAppMockRenderer(); - }); - - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); - - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); +describe('Template fields', () => { + let appMockRenderer: AppMockRenderer; + const onSubmit = jest.fn(); + const formDefaultValue = { templateTags: [] }; + const defaultProps = { + isLoading: false, + configurationTemplateTags: [], + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRenderer = createAppMockRenderer(); + }); - it('renders template fields correctly', async () => { - appMockRenderer.render( - - - - ); + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - expect(await screen.findByTestId('template-name-input')).toBeInTheDocument(); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - expect(await screen.findByTestId('template-description-input')).toBeInTheDocument(); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - it('renders template fields with existing value', async () => { - appMockRenderer.render( - - - - ); + it('renders template fields correctly', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-name-input')).toHaveValue('Sample template'); + expect(await screen.findByTestId('template-name-input')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-description-input')).toBeInTheDocument(); + }); - const templateTags = await screen.findByTestId('template-tags'); + it('renders template fields with existing value', async () => { + appMockRenderer.render( + + + + ); + + expect(await screen.findByTestId('template-name-input')).toHaveValue('Sample template'); + + const templateTags = await screen.findByTestId('template-tags'); + + expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( + 'template-1' + ); + expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( + 'template-2' + ); + + expect(await screen.findByTestId('template-description-input')).toHaveTextContent( + 'This is a template description' + ); + }); - expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( - 'template-1' - ); - expect(await within(templateTags).findByTestId('comboBoxInput')).toHaveTextContent( - 'template-2' - ); + it('calls onSubmit with template fields', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-description-input')).toHaveTextContent( - 'This is a template description' - ); - }); + userEvent.paste(await screen.findByTestId('template-name-input'), 'Template 1'); - it('calls onSubmit with template fields', async () => { - appMockRenderer.render( - - - - ); + const templateTags = await screen.findByTestId('template-tags'); - userEvent.paste(await screen.findByTestId('template-name-input'), 'Template 1'); + userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); + userEvent.keyboard('{enter}'); - const templateTags = await screen.findByTestId('template-tags'); + userEvent.paste( + await screen.findByTestId('template-description-input'), + 'this is a first template' + ); - userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); - userEvent.keyboard('{enter}'); + userEvent.click(screen.getByText('Submit')); - userEvent.paste( - await screen.findByTestId('template-description-input'), - 'this is a first template' + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + name: 'Template 1', + templateDescription: 'this is a first template', + templateTags: ['first'], + }, + true ); - - userEvent.click(screen.getByText('Submit')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - name: 'Template 1', - templateDescription: 'this is a first template', - templateTags: ['first'], - }, - true - ); - }); }); + }); - it('calls onSubmit with updated template fields', async () => { - appMockRenderer.render( - - - + it('calls onSubmit with updated template fields', async () => { + appMockRenderer.render( + + + + ); + + userEvent.paste(await screen.findByTestId('template-name-input'), '!!'); + + const templateTags = await screen.findByTestId('template-tags'); + + userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); + userEvent.keyboard('{enter}'); + + userEvent.paste(await screen.findByTestId('template-description-input'), '..'); + + userEvent.click(screen.getByText('Submit')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + name: 'Sample template!!', + templateDescription: 'This is a template description..', + templateTags: ['template-1', 'template-2', 'first'], + }, + true ); - - userEvent.paste(await screen.findByTestId('template-name-input'), '!!'); - - const templateTags = await screen.findByTestId('template-tags'); - - userEvent.paste(await within(templateTags).findByRole('combobox'), 'first'); - userEvent.keyboard('{enter}'); - - userEvent.paste(await screen.findByTestId('template-description-input'), '..'); - - userEvent.click(screen.getByText('Submit')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - name: 'Sample template!!', - templateDescription: 'This is a template description..', - templateTags: ['template-1', 'template-2', 'first'], - }, - true - ); - }); }); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx index 562670f917977..64c5f7f10d3cc 100644 --- a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx @@ -15,125 +15,122 @@ import { FormTestComponent } from '../../common/test_utils'; import { TemplateTags } from './template_tags'; import { showEuiComboBoxOptions } from '@elastic/eui/lib/test/rtl'; -// FLAKY: https://github.com/elastic/kibana/issues/189293 -for (let i = 0; i < 50; i++) { - describe('TemplateTags', () => { - let appMockRenderer: AppMockRenderer; - const onSubmit = jest.fn(); - const formDefaultValue = { templateTags: [] }; - - beforeEach(() => { - jest.clearAllMocks(); - appMockRenderer = createAppMockRenderer(); - }); +describe('TemplateTags', () => { + let appMockRenderer: AppMockRenderer; + const onSubmit = jest.fn(); + const formDefaultValue = { templateTags: [] }; + + beforeEach(() => { + jest.clearAllMocks(); + appMockRenderer = createAppMockRenderer(); + }); - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMockRenderer.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + }); - it('renders template tags', async () => { - appMockRenderer.render( - - - - ); + it('renders template tags', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + }); - it('renders loading state', async () => { - appMockRenderer.render( - - - - ); + it('renders loading state', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByRole('progressbar')).toBeInTheDocument(); - expect(await screen.findByLabelText('Loading')).toBeInTheDocument(); - }); + expect(await screen.findByRole('progressbar')).toBeInTheDocument(); + expect(await screen.findByLabelText('Loading')).toBeInTheDocument(); + }); - it('shows template tags options', async () => { - appMockRenderer.render( - - - - ); + it('shows template tags options', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - await showEuiComboBoxOptions(); + await showEuiComboBoxOptions(); - expect(await screen.findByText('foo')).toBeInTheDocument(); - }); + expect(await screen.findByText('foo')).toBeInTheDocument(); + }); - it('shows template tags with current values', async () => { - appMockRenderer.render( - - - - ); + it('shows template tags with current values', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - expect(await screen.findByText('foo')).toBeInTheDocument(); + expect(await screen.findByText('foo')).toBeInTheDocument(); - expect(await screen.findByText('bar')).toBeInTheDocument(); - }); + expect(await screen.findByText('bar')).toBeInTheDocument(); + }); - it('adds template tag ', async () => { - appMockRenderer.render( - - - + it('adds template tag ', async () => { + appMockRenderer.render( + + + + ); + + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + + const comboBoxEle = await screen.findByRole('combobox'); + userEvent.paste(comboBoxEle, 'test'); + userEvent.keyboard('{enter}'); + userEvent.paste(comboBoxEle, 'template'); + userEvent.keyboard('{enter}'); + + userEvent.click(screen.getByText('Submit')); + + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + templateTags: ['test', 'template'], + }, + true ); - - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - - const comboBoxEle = await screen.findByRole('combobox'); - userEvent.paste(comboBoxEle, 'test'); - userEvent.keyboard('{enter}'); - userEvent.paste(comboBoxEle, 'template'); - userEvent.keyboard('{enter}'); - - userEvent.click(screen.getByText('Submit')); - - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - templateTags: ['test', 'template'], - }, - true - ); - }); }); + }); - it('adds new template tag to existing tags', async () => { - appMockRenderer.render( - - - - ); + it('adds new template tag to existing tags', async () => { + appMockRenderer.render( + + + + ); - expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); + expect(await screen.findByTestId('template-tags')).toBeInTheDocument(); - const comboBoxEle = await screen.findByRole('combobox'); - userEvent.paste(comboBoxEle, 'test'); - userEvent.keyboard('{enter}'); + const comboBoxEle = await screen.findByRole('combobox'); + userEvent.paste(comboBoxEle, 'test'); + userEvent.keyboard('{enter}'); - userEvent.click(screen.getByText('Submit')); + userEvent.click(screen.getByText('Submit')); - await waitFor(() => { - expect(onSubmit).toBeCalledWith( - { - templateTags: ['foo', 'bar', 'test'], - }, - true - ); - }); + await waitFor(() => { + expect(onSubmit).toBeCalledWith( + { + templateTags: ['foo', 'bar', 'test'], + }, + true + ); }); }); -} +}); 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 fb3e4626178f2..8679c302be8cf 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 @@ -17,94 +17,91 @@ import { } from '../../../common/mock'; import { AlertPropertyActions } from './alert_property_actions'; -// FLAKY: https://github.com/elastic/kibana/issues/174667 -for (let i = 0; i < 50; i++) { - describe('AlertPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - totalAlerts: 1, - onDelete: jest.fn(), - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); +describe('AlertPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + totalAlerts: 1, + onDelete: jest.fn(), + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect( - (await screen.findByTestId('property-actions-user-action-group')).children.length - ).toBe(1); + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 1 + ); - expect( - await screen.findByTestId('property-actions-user-action-minusInCircle') - ).toBeInTheDocument(); - }); + expect( + await screen.findByTestId('property-actions-user-action-minusInCircle') + ).toBeInTheDocument(); + }); - it('renders the modal info correctly for multiple alert', async () => { - appMock.render(); + it('renders the modal info correctly for multiple alert', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); - expect(await screen.findByText('Remove')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts'); + expect(await screen.findByText('Remove')).toBeInTheDocument(); + }); - it('remove alerts correctly', async () => { - appMock.render(); + it('remove alerts correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); + userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(await screen.findByText('Remove')); + userEvent.click(await screen.findByText('Remove')); - await waitFor(() => { - expect(props.onDelete).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); }); + }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index 52f12ae2a4421..3f3f20fece15a 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -18,130 +18,125 @@ import { import { RegisteredAttachmentsPropertyActions } from './registered_attachments_property_actions'; import { AttachmentActionType } from '../../../client/attachment_framework/types'; -// Failing: See https://github.com/elastic/kibana/issues/174384 -for (let i = 0; i < 50; i++) { - describe('RegisteredAttachmentsPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - registeredAttachmentActions: [], - onDelete: jest.fn(), - hideDefaultActions: false, - }; - - beforeEach(() => { - jest.clearAllMocks(); - appMock = createAppMockRenderer(); - }); +describe('RegisteredAttachmentsPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + registeredAttachmentActions: [], + onDelete: jest.fn(), + hideDefaultActions: false, + }; + + beforeEach(() => { + jest.clearAllMocks(); + appMock = createAppMockRenderer(); + }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + it('renders the correct number of actions', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument(); + }); - it('renders the modal info correctly', async () => { - appMock.render(); + it('renders the modal info correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( - 'Delete attachment' - ); + expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent( + 'Delete attachment' + ); - expect(await screen.findByText('Delete')).toBeInTheDocument(); - }); + expect(await screen.findByText('Delete')).toBeInTheDocument(); + }); - it('remove attachments correctly', async () => { - appMock.render(); + it('remove attachments correctly', async () => { + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); + expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - userEvent.click(await screen.findByText('Delete')); + userEvent.click(await screen.findByText('Delete')); - await waitFor(() => { - expect(props.onDelete).toHaveBeenCalled(); - }); + await waitFor(() => { + expect(props.onDelete).toHaveBeenCalled(); }); + }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does not show the property actions when hideDefaultActions is enabled', async () => { - appMock.render(); + it('does not show the property actions when hideDefaultActions is enabled', async () => { + appMock.render(); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + }); - it('renders correctly registered attachments', async () => { - const onClick = jest.fn(); - const action = [ - { - type: AttachmentActionType.BUTTON as const, - label: 'My button', - iconType: 'download', - onClick, - }, - ]; - - appMock.render( - - ); - - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); - - expect( - (await screen.findByTestId('property-actions-user-action-group')).children.length - ).toBe(2); - - expect( - await screen.findByTestId('property-actions-user-action-download') - ).toBeInTheDocument(); - }); + it('renders correctly registered attachments', async () => { + const onClick = jest.fn(); + const action = [ + { + type: AttachmentActionType.BUTTON as const, + label: 'My button', + iconType: 'download', + onClick, + }, + ]; + + appMock.render( + + ); + + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); + + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 2 + ); + + expect(await screen.findByTestId('property-actions-user-action-download')).toBeInTheDocument(); }); -} +}); diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index 54a88f2dab576..20ddc99608e93 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -17,109 +17,106 @@ import { import { UserCommentPropertyActions } from './user_comment_property_actions'; import { waitFor } from '@testing-library/react'; -// FLAKY: https://github.com/elastic/kibana/issues/175310 -for (let i = 0; i < 50; i++) { - describe('UserCommentPropertyActions', () => { - let appMock: AppMockRenderer; - - const props = { - isLoading: false, - onEdit: jest.fn(), - onQuote: jest.fn(), - onDelete: jest.fn(), - }; - - beforeEach(() => { - appMock = createAppMockRenderer(); - jest.clearAllMocks(); - }); - - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); +describe('UserCommentPropertyActions', () => { + let appMock: AppMockRenderer; + + const props = { + isLoading: false, + onEdit: jest.fn(), + onQuote: jest.fn(), + onDelete: jest.fn(), + }; + + beforeEach(() => { + appMock = createAppMockRenderer(); + jest.clearAllMocks(); + }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); - }); + afterEach(() => { + appMock.queryClient.getQueryCache().clear(); + }); - it('renders the correct number of actions', async () => { - appMock.render(); + afterEach(async () => { + await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('renders the correct number of actions', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect( - (await screen.findByTestId('property-actions-user-action-group')).children.length - ).toBe(3); - expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - it('edits the comment correctly', async () => { - appMock.render(); + expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe( + 3 + ); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('edits the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); + expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument(); - expect(props.onEdit).toHaveBeenCalled(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-pencil')); - it('quotes the comment correctly', async () => { - appMock.render(); + expect(props.onEdit).toHaveBeenCalled(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('quotes the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); + expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument(); - expect(props.onQuote).toHaveBeenCalled(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-quote')); - it('deletes the comment correctly', async () => { - appMock.render(); + expect(props.onQuote).toHaveBeenCalled(); + }); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); + it('deletes the comment correctly', async () => { + appMock.render(); - userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); - await waitForEuiPopoverOpen(); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); + userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses')); + await waitForEuiPopoverOpen(); - userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); + expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument(); - await waitFor(() => { - expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); - }); + userEvent.click(await screen.findByTestId('property-actions-user-action-trash')); - userEvent.click(await screen.findByText('Delete')); - expect(props.onDelete).toHaveBeenCalled(); + await waitFor(() => { + expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument(); }); - it('does not show the property actions without delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); - appMock.render(); + userEvent.click(await screen.findByText('Delete')); + expect(props.onDelete).toHaveBeenCalled(); + }); - expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); - }); + it('does not show the property actions without delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: noCasesPermissions() }); + appMock.render(); + + expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument(); + }); - it('does show the property actions with only delete permissions', async () => { - appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); - appMock.render(); + it('does show the property actions with only delete permissions', async () => { + appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() }); + appMock.render(); - expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); - }); + expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument(); }); -} +}); From 904fb1165e6eb718d356d7fc1fd05a3b63764789 Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Thu, 29 Aug 2024 10:17:51 +0100 Subject: [PATCH 5/6] util for clear query cache --- .../cases/public/common/mock/test_providers.tsx | 10 +++++++++- .../components/all_cases/columns_popover.test.tsx | 6 +----- .../public/components/all_cases/use_actions.test.tsx | 6 +----- .../components/case_form_fields/severity.test.tsx | 6 +----- .../case_form_fields/sync_alerts_toggle.test.tsx | 6 +----- .../case_view/components/case_view_files.test.tsx | 6 +----- .../case_view/components/custom_fields.test.tsx | 6 +----- .../public/components/connector_selector/form.test.tsx | 6 +----- .../cases/public/components/create/template.test.tsx | 6 +----- .../components/custom_fields/form_fields.test.tsx | 6 +----- .../cases/public/components/description/index.test.tsx | 6 +----- .../components/files/file_attachment_event.test.tsx | 6 +----- .../public/components/files/file_preview.test.tsx | 6 +----- .../cases/public/components/files/file_type.test.tsx | 6 +----- .../public/components/filter_popover/index.test.tsx | 6 +----- .../editable_markdown_renderer.test.tsx | 6 +----- .../components/templates/template_fields.test.tsx | 6 +----- .../public/components/templates/template_tags.test.tsx | 6 +----- .../property_actions/alert_property_actions.test.tsx | 6 +----- .../registered_attachments_property_actions.test.tsx | 6 +----- .../user_comment_property_actions.test.tsx | 6 +----- 21 files changed, 29 insertions(+), 101 deletions(-) diff --git a/x-pack/plugins/cases/public/common/mock/test_providers.tsx b/x-pack/plugins/cases/public/common/mock/test_providers.tsx index 820ae554c3aa7..aef1024cc8afc 100644 --- a/x-pack/plugins/cases/public/common/mock/test_providers.tsx +++ b/x-pack/plugins/cases/public/common/mock/test_providers.tsx @@ -9,7 +9,7 @@ import React, { useMemo } from 'react'; import { MemoryRouter } from 'react-router-dom'; -import { render as reactRender } from '@testing-library/react'; +import { render as reactRender, waitFor } from '@testing-library/react'; import type { RenderOptions, RenderResult } from '@testing-library/react'; import type { ILicense } from '@kbn/licensing-plugin/public'; import type { ScopedFilesClient } from '@kbn/files-plugin/public'; @@ -124,6 +124,7 @@ export interface AppMockRenderer { queryClient: QueryClient; AppWrapper: React.FC<{ children: React.ReactNode }>; getFilesClient: () => ScopedFilesClient; + clearQueryCache: () => Promise; } export const testQueryClient = new QueryClient({ @@ -202,6 +203,12 @@ export const createAppMockRenderer = ({ }); }; + const clearQueryCache = async () => { + queryClient.getQueryCache().clear(); + + await waitFor(() => expect(queryClient.isFetching()).toBe(0)); + }; + return { coreStart: services, queryClient, @@ -210,5 +217,6 @@ export const createAppMockRenderer = ({ externalReferenceAttachmentTypeRegistry, persistableStateAttachmentTypeRegistry, getFilesClient, + clearQueryCache, }; }; 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 9d538001857c1..109ad955f629f 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 @@ -22,12 +22,8 @@ describe('ColumnsPopover', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + await appMockRenderer.clearQueryCache(); }); const selectedColumns = [ diff --git a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx index e896d5541cefd..9256f4aad82fe 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_actions.test.tsx @@ -36,12 +36,8 @@ describe('useActions', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders column actions', async () => { diff --git a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx index a996dd2aed021..9502c6b709220 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/severity.test.tsx @@ -23,12 +23,8 @@ describe('Severity form field', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders', async () => { diff --git a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx index a7cbff3457d0f..024ebd790cff2 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/sync_alerts_toggle.test.tsx @@ -30,12 +30,8 @@ describe('SyncAlertsToggle', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('it renders', async () => { diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx index 5030dadfd9cb8..e6469b8af7560 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_files.test.tsx @@ -39,12 +39,8 @@ describe('Case View Page files tab', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('should render the utility bar for the files table', async () => { diff --git a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx index 2361282b68054..47928a289a891 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/custom_fields.test.tsx @@ -25,12 +25,8 @@ describe('Case View Page files tab', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('should render the custom fields correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index 2accabb73a9e2..de56f593305e2 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -44,12 +44,8 @@ describe('ConnectorSelector', () => { }); }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + await appMock.clearQueryCache(); }); it('should render', async () => { diff --git a/x-pack/plugins/cases/public/components/create/template.test.tsx b/x-pack/plugins/cases/public/components/create/template.test.tsx index 371ef075c08f4..8048a038064c1 100644 --- a/x-pack/plugins/cases/public/components/create/template.test.tsx +++ b/x-pack/plugins/cases/public/components/create/template.test.tsx @@ -22,12 +22,8 @@ describe('CustomFields', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx index 9e40ec0e4f61b..f48181ab06171 100644 --- a/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/custom_fields/form_fields.test.tsx @@ -24,12 +24,8 @@ describe('FormFields ', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/description/index.test.tsx b/x-pack/plugins/cases/public/components/description/index.test.tsx index 9285dc9f0d73a..d5f3b26684080 100644 --- a/x-pack/plugins/cases/public/components/description/index.test.tsx +++ b/x-pack/plugins/cases/public/components/description/index.test.tsx @@ -36,12 +36,8 @@ describe('Description', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders description correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index b21b35b3dbaec..2ef16ec7a1ca7 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -24,12 +24,8 @@ describe('FileAttachmentEvent', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders clickable name', async () => { diff --git a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx index 990b13935608d..3312d9e497817 100644 --- a/x-pack/plugins/cases/public/components/files/file_preview.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_preview.test.tsx @@ -24,12 +24,8 @@ describe('FilePreview', () => { appMockRender = createAppMockRenderer(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('FilePreview rendered correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index f1c5a697602e9..f4e03aea12796 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -44,12 +44,8 @@ describe('getFileType', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('event renders a clickable name if the file is an image', async () => { diff --git a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx index f1b1d12ba2571..072a6661203fa 100644 --- a/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx +++ b/x-pack/plugins/cases/public/components/filter_popover/index.test.tsx @@ -25,12 +25,8 @@ describe('FilterPopover ', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('renders button label correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx index 143121db411e1..0a2259d42b01a 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/editable_markdown_renderer.test.tsx @@ -73,12 +73,8 @@ describe('EditableMarkdown', () => { sessionStorage.removeItem(draftStorageKey); }); - afterEach(() => { - appMockRender.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRender.queryClient.isFetching()).toBe(0)); + await appMockRender.clearQueryCache(); }); it('Save button click calls onSaveContent and onChangeEditable when text area value changed', async () => { diff --git a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx index 63ce2b17155fd..f5dda51104653 100644 --- a/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_fields.test.tsx @@ -27,12 +27,8 @@ describe('Template fields', () => { appMockRenderer = createAppMockRenderer(); }); - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + await appMockRenderer.clearQueryCache(); }); it('renders template fields correctly', async () => { diff --git a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx index 64c5f7f10d3cc..6b084a3317e3f 100644 --- a/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx +++ b/x-pack/plugins/cases/public/components/templates/template_tags.test.tsx @@ -25,12 +25,8 @@ describe('TemplateTags', () => { appMockRenderer = createAppMockRenderer(); }); - afterEach(() => { - appMockRenderer.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMockRenderer.queryClient.isFetching()).toBe(0)); + await appMockRenderer.clearQueryCache(); }); it('renders template tags', async () => { 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 8679c302be8cf..43601412c0bfe 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 @@ -31,12 +31,8 @@ describe('AlertPropertyActions', () => { appMock = createAppMockRenderer(); }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + await appMock.clearQueryCache(); }); it('renders the correct number of actions', async () => { diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx index 3f3f20fece15a..92c6c2cb5e3d3 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx @@ -33,12 +33,8 @@ describe('RegisteredAttachmentsPropertyActions', () => { appMock = createAppMockRenderer(); }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + await appMock.clearQueryCache(); }); it('renders the correct number of actions', async () => { diff --git a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx index 20ddc99608e93..bf090a94ad062 100644 --- a/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/property_actions/user_comment_property_actions.test.tsx @@ -32,12 +32,8 @@ describe('UserCommentPropertyActions', () => { jest.clearAllMocks(); }); - afterEach(() => { - appMock.queryClient.getQueryCache().clear(); - }); - afterEach(async () => { - await waitFor(() => expect(appMock.queryClient.isFetching()).toBe(0)); + await appMock.clearQueryCache(); }); it('renders the correct number of actions', async () => { From 02937cf30d93017ce1163ad167c9c95fdd12260e Mon Sep 17 00:00:00 2001 From: Janki Salvi Date: Thu, 29 Aug 2024 10:26:08 +0100 Subject: [PATCH 6/6] fix lint --- .../cases/public/components/connector_selector/form.test.tsx | 2 +- .../public/components/files/file_attachment_event.test.tsx | 2 +- x-pack/plugins/cases/public/components/files/file_type.test.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx index de56f593305e2..c87dd5bb1d10b 100644 --- a/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx +++ b/x-pack/plugins/cases/public/components/connector_selector/form.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { screen, waitFor } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import { ConnectorSelector } from './form'; import { useKibana } from '../../common/lib/kibana'; import type { AppMockRenderer } from '../../common/mock'; diff --git a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx index 2ef16ec7a1ca7..af1a09f169216 100644 --- a/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_attachment_event.test.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { screen, waitFor } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../common/mock'; diff --git a/x-pack/plugins/cases/public/components/files/file_type.test.tsx b/x-pack/plugins/cases/public/components/files/file_type.test.tsx index f4e03aea12796..ae1d3e2339e97 100644 --- a/x-pack/plugins/cases/public/components/files/file_type.test.tsx +++ b/x-pack/plugins/cases/public/components/files/file_type.test.tsx @@ -6,7 +6,7 @@ */ import type { JsonValue } from '@kbn/utility-types'; import userEvent from '@testing-library/user-event'; -import { screen, waitFor } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import type { ExternalReferenceAttachmentViewProps } from '../../client/attachment_framework/types'; import type { AppMockRenderer } from '../../common/mock';