Skip to content

Commit

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

Fixes elastic#175314
Fixes elastic#175313
Fixes elastic#175312
Fixes elastic#175311
Fixes elastic#175310
Fixes elastic#174667
Fixes elastic#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
  • Loading branch information
js-jankisalvi authored and fkanout committed Mar 4, 2024
1 parent 8e96b73 commit 885df52
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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} />);

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand All @@ -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();
});
});

0 comments on commit 885df52

Please sign in to comment.