Skip to content

Commit

Permalink
[Cases] Unskip flyout and custom fields flaky tests (#177590)
Browse files Browse the repository at this point in the history
## Summary

PR #176863 improved the cases
context provided which we assumed caused some flakiness in our tests. I
am unskipping a couple of tests to test if the changes on that PR
stabilized the tests.

Fixes #176805
Fixes #174528
Fixes #174527
Fixes #174526
Fixes #174525
Fixes #176600
Fixes #146394


### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
cnasikas authored Feb 22, 2024
1 parent 637de1d commit 2a8d29b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { customFieldsConfigurationMock } from '../../containers/mock';
import { CustomFields } from './custom_fields';
import * as i18n from './translations';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@
*/

import React from 'react';
import { act } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { CreateCaseFlyout } from './create_case_flyout';
import type { AppMockRenderer } from '../../../common/mock';
import { createAppMockRenderer } from '../../../common/mock';
import { useGetTags } from '../../../containers/use_get_tags';
import { useGetCaseConfiguration } from '../../../containers/configure/use_get_case_configuration';
import { useGetSupportedActionConnectors } from '../../../containers/configure/use_get_supported_action_connectors';
import { useAvailableCasesOwners } from '../../app/use_available_owners';
import { connectorsMock } from '../../../containers/mock';
import { useCaseConfigureResponse } from '../../configure_cases/__mock__';
import { waitForComponentToUpdate } from '../../../common/test_utils';

jest.mock('../../../common/lib/kibana');
jest.mock('../../../containers/use_get_tags');
jest.mock('../../../containers/configure/use_get_supported_action_connectors');
jest.mock('../../../containers/configure/use_get_case_configuration');
jest.mock('../../markdown_editor/plugins/lens/use_lens_draft_comment');
jest.mock('../../app/use_available_owners');

const useGetTagsMock = useGetTags as jest.Mock;
const useGetConnectorsMock = useGetSupportedActionConnectors as jest.Mock;
const useGetCaseConfigurationMock = useGetCaseConfiguration as jest.Mock;
const useAvailableOwnersMock = useAvailableCasesOwners as jest.Mock;

const onClose = jest.fn();
const onSuccess = jest.fn();
Expand All @@ -23,49 +39,49 @@ const defaultProps = {
owner: 'securitySolution',
};

// FLAKY: https://github.com/elastic/kibana/issues/174525
// FLAKY: https://github.com/elastic/kibana/issues/174526
// FLAKY: https://github.com/elastic/kibana/issues/174527
// FLAKY: https://github.com/elastic/kibana/issues/174528
describe.skip('CreateCaseFlyout', () => {
let mockedContext: AppMockRenderer;
describe('CreateCaseFlyout', () => {
let appMockRenderer: AppMockRenderer;

beforeEach(() => {
mockedContext = createAppMockRenderer();
jest.clearAllMocks();
appMockRenderer = createAppMockRenderer();
useAvailableOwnersMock.mockReturnValue(['securitySolution', 'observability']);
useGetTagsMock.mockReturnValue({ data: ['test'] });
useGetConnectorsMock.mockReturnValue({ isLoading: false, data: connectorsMock });
useGetCaseConfigurationMock.mockImplementation(() => useCaseConfigureResponse);
});

it('renders', async () => {
const { getByTestId } = mockedContext.render(<CreateCaseFlyout {...defaultProps} />);
await act(async () => {
expect(getByTestId('create-case-flyout')).toBeTruthy();
});
appMockRenderer.render(<CreateCaseFlyout {...defaultProps} />);
await waitForComponentToUpdate();

expect(await screen.findByTestId('create-case-flyout')).toBeInTheDocument();
});

it('should call onCloseCaseModal when closing the flyout', async () => {
const { getByTestId } = mockedContext.render(<CreateCaseFlyout {...defaultProps} />);
await act(async () => {
userEvent.click(getByTestId('euiFlyoutCloseButton'));
appMockRenderer.render(<CreateCaseFlyout {...defaultProps} />);
await waitForComponentToUpdate();

userEvent.click(await screen.findByTestId('euiFlyoutCloseButton'));

await waitFor(() => {
expect(onClose).toBeCalled();
});
expect(onClose).toBeCalled();
});

it('renders headerContent when passed', async () => {
const headerContent = <p data-test-subj="testing123" />;
const { getByTestId } = mockedContext.render(
<CreateCaseFlyout {...defaultProps} headerContent={headerContent} />
);
appMockRenderer.render(<CreateCaseFlyout {...defaultProps} headerContent={headerContent} />);
await waitForComponentToUpdate();

await act(async () => {
expect(getByTestId('testing123')).toBeTruthy();
expect(getByTestId('create-case-flyout-header').children.length).toEqual(2);
});
expect(await screen.findByTestId('testing123')).toBeInTheDocument();
expect((await screen.findByTestId('create-case-flyout-header')).children.length).toEqual(2);
});

it('does not render headerContent when undefined', async () => {
const { getByTestId } = mockedContext.render(<CreateCaseFlyout {...defaultProps} />);
appMockRenderer.render(<CreateCaseFlyout {...defaultProps} />);
await waitForComponentToUpdate();

await act(async () => {
expect(getByTestId('create-case-flyout-header').children.length).toEqual(1);
});
expect((await screen.findByTestId('create-case-flyout-header')).children.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { MAX_CUSTOM_FIELDS_PER_CASE } from '../../../common/constants';
import { CustomFields } from '.';
import * as i18n from './translations';

// Flaky: https://github.com/elastic/kibana/issues/176805
describe.skip('CustomFields', () => {
describe('CustomFields', () => {
let appMockRender: AppMockRenderer;

const props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import userEvent from '@testing-library/user-event';
import { FormTestComponent } from '../../../common/test_utils';
import { Configure } from './configure';

// Failing: See https://github.com/elastic/kibana/issues/176600
describe.skip('Configure ', () => {
describe('Configure ', () => {
const onSubmit = jest.fn();

beforeEach(() => {
Expand Down

0 comments on commit 2a8d29b

Please sign in to comment.