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] Fix alert property actions flaky test #174759

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Changes from 4 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 @@ -7,7 +7,7 @@

import React from 'react';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
import { waitFor } from '@testing-library/react';
import { waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import type { AppMockRenderer } from '../../../common/mock';
import {
Expand All @@ -17,12 +17,7 @@ import {
} from '../../../common/mock';
import { AlertPropertyActions } from './alert_property_actions';

// FLAKY: https://github.com/elastic/kibana/issues/174667
// FLAKY: https://github.com/elastic/kibana/issues/174668
// FLAKY: https://github.com/elastic/kibana/issues/174669
// FLAKY: https://github.com/elastic/kibana/issues/174670
// FLAKY: https://github.com/elastic/kibana/issues/174671
describe.skip('AlertPropertyActions', () => {
describe('AlertPropertyActions', () => {
let appMock: AppMockRenderer;

const props = {
Expand All @@ -32,93 +27,101 @@ describe.skip('AlertPropertyActions', () => {
};

beforeEach(() => {
appMock = createAppMockRenderer();
jest.clearAllMocks();
appMock = createAppMockRenderer();
});

it('renders the correct number of actions', async () => {
const result = appMock.render(<AlertPropertyActions {...props} />);
appMock.render(<AlertPropertyActions {...props} />);

expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-ellipses'));
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();

expect(result.getByTestId('property-actions-user-action-group').children.length).toBe(1);
expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
1
);

expect(
await screen.findByTestId('property-actions-user-action-minusInCircle')
).toBeInTheDocument();
});

it('renders the modal info correctly for one alert', async () => {
const result = appMock.render(<AlertPropertyActions {...props} />);
appMock.render(<AlertPropertyActions {...props} />);

expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-ellipses'));
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();

expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument();
expect(
await screen.findByTestId('property-actions-user-action-minusInCircle')
).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle'));
userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle'));

await waitFor(() => {
expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

expect(result.getByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert');
expect(result.getByText('Remove')).toBeInTheDocument();
expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert');
expect(await screen.findByText('Remove')).toBeInTheDocument();
});

it('renders the modal info correctly for multiple alert', async () => {
const result = appMock.render(<AlertPropertyActions {...props} totalAlerts={2} />);
appMock.render(<AlertPropertyActions {...props} totalAlerts={2} />);

expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-ellipses'));
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();

expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument();
expect(
await screen.findByTestId('property-actions-user-action-minusInCircle')
).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle'));
userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle'));

await waitFor(() => {
expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

expect(result.getByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts');
expect(result.getByText('Remove')).toBeInTheDocument();
expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alerts');
expect(await screen.findByText('Remove')).toBeInTheDocument();
});

it('remove alerts correctly', async () => {
const result = appMock.render(<AlertPropertyActions {...props} />);
appMock.render(<AlertPropertyActions {...props} />);

expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();

userEvent.click(result.getByTestId('property-actions-user-action-ellipses'));
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();

expect(result.queryByTestId('property-actions-user-action-minusInCircle')).toBeInTheDocument();
expect(
await screen.findByTestId('property-actions-user-action-minusInCircle')
).toBeInTheDocument();

userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle'));

userEvent.click(result.getByTestId('property-actions-user-action-minusInCircle'));
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

userEvent.click(screen.getByText('Remove'));

await waitFor(() => {
expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(props.onDelete).toHaveBeenCalled();
});

userEvent.click(result.getByText('Remove'));
expect(props.onDelete).toHaveBeenCalled();
});

it('does not show the property actions without delete permissions', async () => {
appMock = createAppMockRenderer({ permissions: noCasesPermissions() });
const result = appMock.render(<AlertPropertyActions {...props} />);
appMock.render(<AlertPropertyActions {...props} />);

expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
});

it('does show the property actions with only delete permissions', async () => {
appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() });
const result = appMock.render(<AlertPropertyActions {...props} />);
appMock.render(<AlertPropertyActions {...props} />);

expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
});
});