Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Unskip flyout and custom fields flaky tests #177590

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move them here?

Copy link
Member Author

@cnasikas cnasikas Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specific reason, probably a random copy-paste from another test. Do you want me to change the order?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, I was just wondering if you had found some little performance hack that said moving these to the beforeEach block was more efficient 😄

You can leave as is 👍

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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to eliminate the Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. warning.


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