Skip to content

Commit

Permalink
[ResponseOps][Cases] Fix category flaky test. (elastic#189473)
Browse files Browse the repository at this point in the history
fixes elastic#177792

## Summary

Updated the tests to use `await screen.find` instead of `get`.
  • Loading branch information
adcoelho authored Jul 31, 2024
1 parent 7f42e2c commit 20912a7
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { categories } from '../../containers/mock';
import { MAX_CATEGORY_LENGTH } from '../../../common/constants';
import { FormTestComponent } from '../../common/test_utils';

// FLAKY: https://github.com/elastic/kibana/issues/177792
describe.skip('Category', () => {
describe('Category', () => {
let appMockRender: AppMockRenderer;
const onSubmit = jest.fn();

Expand All @@ -26,14 +25,14 @@ describe.skip('Category', () => {
appMockRender = createAppMockRenderer();
});

it('renders the category field correctly', () => {
it('renders the category field correctly', async () => {
appMockRender.render(
<FormTestComponent onSubmit={onSubmit}>
<CategoryFormField isLoading={false} availableCategories={categories} />
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();
});

it('can submit without setting a category', async () => {
Expand All @@ -43,8 +42,8 @@ describe.skip('Category', () => {
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
userEvent.click(screen.getByText('Submit'));
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -59,8 +58,8 @@ describe.skip('Category', () => {
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
userEvent.click(screen.getByText('Submit'));
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -75,8 +74,8 @@ describe.skip('Category', () => {
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
userEvent.click(screen.getByText('Submit'));
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -91,9 +90,9 @@ describe.skip('Category', () => {
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();

userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -112,9 +111,9 @@ describe.skip('Category', () => {
</FormTestComponent>
);

expect(screen.getByTestId('categories-list')).toBeInTheDocument();
expect(await screen.findByTestId('categories-list')).toBeInTheDocument();

userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -136,7 +135,7 @@ describe.skip('Category', () => {
);

userEvent.type(screen.getByRole('combobox'), `${categories[1]}{enter}`);
userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -152,7 +151,7 @@ describe.skip('Category', () => {
);

userEvent.type(screen.getByRole('combobox'), 'my new category{enter}');
userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -168,7 +167,7 @@ describe.skip('Category', () => {
);

userEvent.type(screen.getByRole('combobox'), ' {enter}');
userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
Expand All @@ -185,29 +184,29 @@ describe.skip('Category', () => {
);

userEvent.type(screen.getByRole('combobox'), ' {enter}');
userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
expect(onSubmit).toBeCalledWith({}, false);
});

userEvent.click(screen.getByTestId('comboBoxClearButton'));
userEvent.click(screen.getByText('Submit'));
userEvent.click(await screen.findByTestId('comboBoxClearButton'));
userEvent.click(await screen.findByTestId('form-test-component-submit-button'));

await waitFor(() => {
// data, isValid
expect(onSubmit).toBeCalledWith({}, true);
});
});

it('disables the component correctly when it is loading', () => {
it('disables the component correctly when it is loading', async () => {
appMockRender.render(
<FormTestComponent onSubmit={onSubmit}>
<CategoryFormField isLoading={true} availableCategories={categories} />
</FormTestComponent>
);

expect(screen.getByRole('combobox')).toBeDisabled();
expect(await screen.findByRole('combobox')).toBeDisabled();
});
});

0 comments on commit 20912a7

Please sign in to comment.