Skip to content

Commit

Permalink
fix property actions flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Feb 12, 2024
1 parent f07df41 commit 6813468
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,100 +17,85 @@ import {
} from '../../../common/mock';
import { AlertPropertyActions } from './alert_property_actions';

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

const props = {
isLoading: false,
totalAlerts: 1,
onDelete: jest.fn(),
};

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

it('renders the correct number of actions', 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();

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 () => {
appMock.render(<AlertPropertyActions {...props} />);
for (let i = 0; i < 500; i++) {
describe('AlertPropertyActions', () => {
let appMock: AppMockRenderer;

const props = {
isLoading: false,
totalAlerts: 1,
onDelete: jest.fn(),
};

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

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
it('renders the correct number of actions', async () => {
appMock.render(<AlertPropertyActions {...props} />);

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

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

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(
(await screen.findByTestId('property-actions-user-action-group')).children.length
).toBe(1);

expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent('Remove alert');
expect(await screen.findByText('Remove')).toBeInTheDocument();
});
expect(
await screen.findByTestId('property-actions-user-action-minusInCircle')
).toBeInTheDocument();
});

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

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
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-ellipses'));
await waitForEuiPopoverOpen();

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

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

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

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

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
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-ellipses'));
await waitForEuiPopoverOpen();

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

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
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();
await waitFor(() => {
expect(props.onDelete).toHaveBeenCalled();
});
});
});

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

expect(screen.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() });
appMock.render(<AlertPropertyActions {...props} />);
it('does show the property actions with only delete permissions', async () => {
appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() });
appMock.render(<AlertPropertyActions {...props} />);

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,124 +18,127 @@ 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', () => {
let appMock: AppMockRenderer;

const props = {
isLoading: false,
registeredAttachmentActions: [],
onDelete: jest.fn(),
hideDefaultActions: false,
};

beforeEach(() => {
jest.clearAllMocks();
appMock = createAppMockRenderer();
});
for (let i = 0; i < 500; i++) {
describe('RegisteredAttachmentsPropertyActions', () => {
let appMock: AppMockRenderer;

const props = {
isLoading: false,
registeredAttachmentActions: [],
onDelete: jest.fn(),
hideDefaultActions: false,
};

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

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

expect(await screen.findByTestId('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(await screen.findByTestId('property-actions-user-action-ellipses'));

await waitForEuiPopoverOpen();
await waitForEuiPopoverOpen();

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

it('renders the modal info correctly', async () => {
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);
it('renders the modal info correctly', async () => {
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
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-ellipses'));
await waitForEuiPopoverOpen();

expect(await screen.findByTestId('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(await screen.findByTestId('property-actions-user-action-trash'));

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent(
'Delete attachment'
);
expect(await screen.findByTestId('confirmModalTitleText')).toHaveTextContent(
'Delete attachment'
);

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

it('remove attachments correctly', async () => {
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);
it('remove attachments correctly', async () => {
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);

expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
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-ellipses'));
await waitForEuiPopoverOpen();

expect(await screen.findByTestId('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(await screen.findByTestId('property-actions-user-action-trash'));

expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();
expect(await screen.findByTestId('property-actions-confirm-modal')).toBeInTheDocument();

userEvent.click(await screen.findByText('Delete'));
userEvent.click(await screen.findByText('Delete'));

await waitFor(() => {
expect(props.onDelete).toHaveBeenCalled();
await waitFor(() => {
expect(props.onDelete).toHaveBeenCalled();
});
});
});

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

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

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

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

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

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

it('renders correctly registered attachments', async () => {
const onClick = jest.fn();
const action = [
{
type: AttachmentActionType.BUTTON as const,
label: 'My button',
iconType: 'download',
onClick,
},
];
expect(screen.queryByTestId('property-actions-user-action')).not.toBeInTheDocument();
});

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

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

userEvent.click(await screen.findByTestId('property-actions-user-action-ellipses'));
await waitForEuiPopoverOpen();
it('does show the property actions with only delete permissions', async () => {
appMock = createAppMockRenderer({ permissions: onlyDeleteCasesPermission() });
appMock.render(<RegisteredAttachmentsPropertyActions {...props} />);

expect((await screen.findByTestId('property-actions-user-action-group')).children.length).toBe(
2
);
expect(await screen.findByTestId('property-actions-user-action')).toBeInTheDocument();
});

expect(await screen.findByTestId('property-actions-user-action-download')).toBeInTheDocument();
it('renders correctly registered attachments', async () => {
const onClick = jest.fn();
const action = [
{
type: AttachmentActionType.BUTTON as const,
label: 'My button',
iconType: 'download',
onClick,
},
];

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

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

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

expect(
(await screen.findByTestId('property-actions-user-action-group')).children.length
).toBe(2);

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

0 comments on commit 6813468

Please sign in to comment.