[Cases] Fix property actions flaky tests (#176709)

## Summary

Fixes #175314
Fixes #175313
Fixes #175312
Fixes #175311
Fixes #175310
Fixes #174667
Fixes #174384


### Checklist

- [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
This commit is contained in:
Janki Salvi 2024-02-13 12:52:03 +01:00 committed by GitHub
parent 67611d6c94
commit 873ae31687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 77 deletions

View file

@ -17,8 +17,7 @@ import {
} from '../../../common/mock';
import { AlertPropertyActions } from './alert_property_actions';
// FLAKY: https://github.com/elastic/kibana/issues/174667
describe.skip('AlertPropertyActions', () => {
describe('AlertPropertyActions', () => {
let appMock: AppMockRenderer;
const props = {
@ -49,22 +48,6 @@ describe.skip('AlertPropertyActions', () => {
).toBeInTheDocument();
});
it('renders the modal info correctly for one alert', async () => {
appMock.render(<AlertPropertyActions {...props} />);
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();
userEvent.click(await screen.findByTestId('property-actions-user-action-minusInCircle'));
expect(await screen.findByTestId('property-actions-confirm-modal')).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 () => {
appMock.render(<AlertPropertyActions {...props} totalAlerts={2} />);
@ -93,7 +76,7 @@ describe.skip('AlertPropertyActions', () => {
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
userEvent.click(screen.getByText('Remove'));
userEvent.click(await screen.findByText('Remove'));
await waitFor(() => {
expect(props.onDelete).toHaveBeenCalled();

View file

@ -6,7 +6,7 @@
*/
import React from 'react';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
import { waitForEuiPopoverOpen, screen } from '@elastic/eui/lib/test/rtl';
import userEvent from '@testing-library/user-event';
import type { AppMockRenderer } from '../../../common/mock';
import { createAppMockRenderer } from '../../../common/mock';
@ -35,30 +35,30 @@ describe('UserActionPropertyActions', () => {
});
it('renders the loading spinner correctly when loading', async () => {
const result = appMock.render(<UserActionPropertyActions {...props} isLoading={true} />);
appMock.render(<UserActionPropertyActions {...props} isLoading={true} />);
expect(result.getByTestId('user-action-title-loading')).toBeInTheDocument();
expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
expect(await screen.findByTestId('user-action-title-loading')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
});
it('renders the property actions', async () => {
const result = appMock.render(<UserActionPropertyActions {...props} isLoading={false} />);
appMock.render(<UserActionPropertyActions {...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-pencil')).toBeInTheDocument();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
1
);
expect(await screen.findByTestId('property-actions-user-action-pencil')).toBeInTheDocument();
});
it('does not render if properties are empty', async () => {
const result = appMock.render(
<UserActionPropertyActions {...props} isLoading={false} propertyActions={[]} />
);
appMock.render(<UserActionPropertyActions isLoading={false} propertyActions={[]} />);
expect(result.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
expect(result.queryByTestId('user-action-title-loading')).not.toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
expect(screen.queryByTestId('user-action-title-loading')).not.toBeInTheDocument();
});
});

View file

@ -18,8 +18,7 @@ import {
import { RegisteredAttachmentsPropertyActions } from './registered_attachments_property_actions';
import { AttachmentActionType } from '../../../client/attachment_framework/types';
// FLAKY: https://github.com/elastic/kibana/issues/174384
describe.skip('RegisteredAttachmentsPropertyActions', () => {
describe('RegisteredAttachmentsPropertyActions', () => {
let appMock: AppMockRenderer;
const props = {
@ -41,13 +40,7 @@ describe.skip('RegisteredAttachmentsPropertyActions', () => {
userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
1
);
expect(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action-group')).toBeInTheDocument();
});
it('renders the modal info correctly', async () => {

View file

@ -6,7 +6,7 @@
*/
import React from 'react';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
import { waitForEuiPopoverOpen, screen } from '@elastic/eui/lib/test/rtl';
import userEvent from '@testing-library/user-event';
import type { AppMockRenderer } from '../../../common/mock';
import {
@ -17,12 +17,7 @@ import {
import { UserCommentPropertyActions } from './user_comment_property_actions';
import { waitFor } from '@testing-library/react';
// FLAKY: https://github.com/elastic/kibana/issues/175310
// FLAKY: https://github.com/elastic/kibana/issues/175311
// FLAKY: https://github.com/elastic/kibana/issues/175312
// FLAKY: https://github.com/elastic/kibana/issues/175313
// FLAKY: https://github.com/elastic/kibana/issues/175314
describe.skip('UserCommentPropertyActions', () => {
describe('UserCommentPropertyActions', () => {
let appMock: AppMockRenderer;
const props = {
@ -38,80 +33,82 @@ describe.skip('UserCommentPropertyActions', () => {
});
it('renders the correct number of actions', async () => {
const result = appMock.render(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...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(3);
expect(result.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument();
expect(result.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument();
expect(result.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
3
);
expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument();
});
it('edits the comment correctly', async () => {
const result = appMock.render(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...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-pencil')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action-pencil')).toBeInTheDocument();
userEvent.click(result.getByTestId('property-actions-user-action-pencil'));
userEvent.click(await screen.findByTestId('property-actions-user-action-pencil'));
expect(props.onEdit).toHaveBeenCalled();
});
it('quotes the comment correctly', async () => {
const result = appMock.render(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...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-quote')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action-quote')).toBeInTheDocument();
userEvent.click(result.getByTestId('property-actions-user-action-quote'));
userEvent.click(await screen.findByTestId('property-actions-user-action-quote'));
expect(props.onQuote).toHaveBeenCalled();
});
it('deletes the comment correctly', async () => {
const result = appMock.render(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...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-trash')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-user-action-trash')).toBeInTheDocument();
userEvent.click(result.getByTestId('property-actions-user-action-trash'));
userEvent.click(await screen.findByTestId('property-actions-user-action-trash'));
await waitFor(() => {
expect(result.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(screen.queryByTestId('property-actions-confirm-modal')).toBeInTheDocument();
});
userEvent.click(result.getByText('Delete'));
userEvent.click(await screen.findByText('Delete'));
expect(props.onDelete).toHaveBeenCalled();
});
it('does not show the property actions without delete permissions', async () => {
appMock = createAppMockRenderer({ permissions: noCasesPermissions() });
const result = appMock.render(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...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(<UserCommentPropertyActions {...props} />);
appMock.render(<UserCommentPropertyActions {...props} />);
expect(result.getByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
});
});