Skip to content

Commit

Permalink
[Cases] Fix alert property actions flaky test (elastic#174759)
Browse files Browse the repository at this point in the history
## Summary

Fixes: elastic#174671,
elastic#174670,
elastic#174669,
elastic#174668,
elastic#174667

Successful builds:
https://buildkite.com/elastic/kibana-pull-request/builds?branch=cnasikas%3Afix_alert_property_actions_flaky

### 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)

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and CoenWarmer committed Feb 15, 2024
1 parent 97d07d7 commit 30be582
Showing 1 changed file with 39 additions and 48 deletions.
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,89 @@ 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();
userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle'));

userEvent.click(result.getByTestId('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();
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();

await waitFor(() => {
expect(result.queryByTestId('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();
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();
});
});

0 comments on commit 30be582

Please sign in to comment.