From 60e1257d311cebf83dee5bc42d6f3ca749733b9b Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 31 Jul 2024 09:49:03 +0200 Subject: [PATCH] [ResponseOps][Cases] Fix custom fields flaky test. (#189475) fixes #188133 ## Summary I simplified the failing test a bit to make it less likely to timeout. 1. We checked for the test **and** the `id` to make sure the component was rendered, it was redundant. 2. We looked for all custom fields(4) and I reduced the check to just 2(which have different types). 3. Updated another test that looked for a label to look for an `id`(for consistency). --- .../case_form_fields/custom_fields.test.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/cases/public/components/case_form_fields/custom_fields.test.tsx b/x-pack/plugins/cases/public/components/case_form_fields/custom_fields.test.tsx index 9a869ad0c89b9e..614420d5ebc5ae 100644 --- a/x-pack/plugins/cases/public/components/case_form_fields/custom_fields.test.tsx +++ b/x-pack/plugins/cases/public/components/case_form_fields/custom_fields.test.tsx @@ -14,10 +14,8 @@ import { createAppMockRenderer } from '../../common/mock'; import { FormTestComponent } from '../../common/test_utils'; import { customFieldsConfigurationMock } from '../../containers/mock'; import { CustomFields } from './custom_fields'; -import * as i18n from './translations'; -// FLAKY: https://github.com/elastic/kibana/issues/188133 -describe.skip('CustomFields', () => { +describe('CustomFields', () => { let appMockRender: AppMockRenderer; const onSubmit = jest.fn(); @@ -40,14 +38,17 @@ describe.skip('CustomFields', () => { ); - expect(await screen.findByText(i18n.ADDITIONAL_FIELDS)).toBeInTheDocument(); expect(await screen.findByTestId('caseCustomFields')).toBeInTheDocument(); - for (const item of customFieldsConfigurationMock) { - expect( - await screen.findByTestId(`${item.key}-${item.type}-create-custom-field`) - ).toBeInTheDocument(); - } + const cf0 = customFieldsConfigurationMock[0]; + const cf1 = customFieldsConfigurationMock[1]; + + expect( + await screen.findByTestId(`${cf0.key}-${cf0.type}-create-custom-field`) + ).toBeInTheDocument(); + expect( + await screen.findByTestId(`${cf1.key}-${cf1.type}-create-custom-field`) + ).toBeInTheDocument(); }); it('should not show the custom fields if the configuration is empty', async () => { @@ -61,7 +62,7 @@ describe.skip('CustomFields', () => { ); - expect(screen.queryByText(i18n.ADDITIONAL_FIELDS)).not.toBeInTheDocument(); + expect(screen.queryByTestId('caseCustomFields')).not.toBeInTheDocument(); expect(screen.queryAllByTestId('create-custom-field', { exact: false }).length).toEqual(0); }); @@ -76,7 +77,7 @@ describe.skip('CustomFields', () => { ); - expect(screen.getAllByTestId('form-optional-field-label')).toHaveLength(2); + expect(await screen.findAllByTestId('form-optional-field-label')).toHaveLength(2); }); it('should not set default value when in edit mode', async () => {