Skip to content

Commit

Permalink
[Cases] Fixes registered attachments property actions flaky test (ela…
Browse files Browse the repository at this point in the history
…stic#174508)

## Summary

Fixes: elastic#174384,
elastic#174385,
elastic#174386,
elastic#174387,
elastic#174388

Successfully run 3x100 times:
https://buildkite.com/elastic/kibana-pull-request/builds?branch=cnasikas%3Afix_ua_actions_flaky_tests

### 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)
  • Loading branch information
cnasikas authored Jan 10, 2024
1 parent 39749b7 commit e3ef0a1
Showing 1 changed file with 47 additions and 45 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 @@ -18,12 +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
// FLAKY: https://github.com/elastic/kibana/issues/174385
// FLAKY: https://github.com/elastic/kibana/issues/174386
// FLAKY: https://github.com/elastic/kibana/issues/174387
// FLAKY: https://github.com/elastic/kibana/issues/174388
describe.skip('RegisteredAttachmentsPropertyActions', () => {
describe('RegisteredAttachmentsPropertyActions', () => {
let appMock: AppMockRenderer;

const props = {
Expand All @@ -34,82 +29,86 @@ describe.skip('RegisteredAttachmentsPropertyActions', () => {
};

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

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

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

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

userEvent.click(result.getByTestId('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-trash')).toBeInTheDocument();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
1
);

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

it('renders the modal info correctly', async () => {
const result = appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);
appMock.render(<RegisteredAttachmentsPropertyActions {...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(await screen.findByTestId('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(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

expect(result.getByTestId('confirmModalTitleText')).toHaveTextContent('Delete attachment');
expect(result.getByText('Delete')).toBeInTheDocument();
expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent(
'Delete attachment'
);

expect(await screen.findByText('Delete')).toBeInTheDocument();
});

it('remove attachments correctly', async () => {
const result = appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);
appMock.render(<RegisteredAttachmentsPropertyActions {...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(await screen.findByTestId('property-actions-user-action-trash')).toBeInTheDocument();

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

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

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

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

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

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

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

it('does not show the property actions when hideDefaultActions is enabled', async () => {
const result = appMock.render(
<RegisteredAttachmentsPropertyActions {...props} hideDefaultActions={true} />
);
appMock.render(<RegisteredAttachmentsPropertyActions {...props} hideDefaultActions={true} />);

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(<RegisteredAttachmentsPropertyActions {...props} />);
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);

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

it('renders correctly registered attachments', async () => {
Expand All @@ -123,16 +122,19 @@ describe.skip('RegisteredAttachmentsPropertyActions', () => {
},
];

const result = appMock.render(
appMock.render(
<RegisteredAttachmentsPropertyActions {...props} registeredAttachmentActions={action} />
);

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(2);
expect(result.queryByTestId('property-actions-user-action-download')).toBeInTheDocument();
expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
2
);

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

0 comments on commit e3ef0a1

Please sign in to comment.