Skip to content

Commit

Permalink
[ResponseOps][Cases] Fix flaky title tests (elastic#190048)
Browse files Browse the repository at this point in the history
Fixes elastic#187364

## Summary

Updated the tests to stop using enzyme.
  • Loading branch information
adcoelho committed Aug 8, 2024
1 parent 671a343 commit 853f32c
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@

import type { FC, PropsWithChildren } from 'react';
import React from 'react';
import { mount } from 'enzyme';
import { act } from '@testing-library/react';
import { screen } from '@testing-library/react';

import type { FormHook } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib';
import type { CaseFormFieldsSchemaProps } from './schema';

import { useForm, Form } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib';
import userEvent from '@testing-library/user-event';

import { Title } from './title';
import { schema } from '../create/schema';
import type { CaseFormFieldsSchemaProps } from './schema';
import { createAppMockRenderer, type AppMockRenderer } from '../../common/mock';

// FLAKY: https://github.com/elastic/kibana/issues/187364
describe.skip('Title', () => {
describe('Title', () => {
let globalForm: FormHook;
let appMockRender: AppMockRenderer;

const MockHookWrapperComponent: FC<PropsWithChildren<unknown>> = ({ children }) => {
const { form } = useForm<CaseFormFieldsSchemaProps>({
Expand All @@ -35,42 +38,37 @@ describe.skip('Title', () => {

beforeEach(() => {
jest.resetAllMocks();
appMockRender = createAppMockRenderer();
});

it('it renders', async () => {
const wrapper = mount(
appMockRender.render(
<MockHookWrapperComponent>
<Title isLoading={false} />
</MockHookWrapperComponent>
);

expect(wrapper.find(`[data-test-subj="caseTitle"]`).exists()).toBeTruthy();
expect(await screen.findByTestId('caseTitle')).toBeInTheDocument();
});

it('it disables the input when loading', async () => {
const wrapper = mount(
appMockRender.render(
<MockHookWrapperComponent>
<Title isLoading={true} />
</MockHookWrapperComponent>
);

expect(wrapper.find(`[data-test-subj="caseTitle"] input`).prop('disabled')).toBeTruthy();
expect(await screen.findByTestId('input')).toBeDisabled();
});

it('it changes the title', async () => {
const wrapper = mount(
appMockRender.render(
<MockHookWrapperComponent>
<Title isLoading={false} />
</MockHookWrapperComponent>
);

await act(async () => {
wrapper
.find(`[data-test-subj="caseTitle"] input`)
.first()
.simulate('change', { target: { value: 'My new title' } });
});
userEvent.paste(await screen.findByTestId('input'), ' is updated');

expect(globalForm.getFormData()).toEqual({ title: 'My new title' });
expect(globalForm.getFormData()).toEqual({ title: 'My title is updated' });
});
});

0 comments on commit 853f32c

Please sign in to comment.