Skip to content

Commit

Permalink
[Cases] Fix description flaky tests (#174903)
Browse files Browse the repository at this point in the history
## Summary

Fixes: #174323,
#174322,
#174321,
#164049,
#164048,
#164045

### 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 16, 2024
1 parent fcf59b6 commit 6aa5ae8
Showing 1 changed file with 29 additions and 48 deletions.
77 changes: 29 additions & 48 deletions x-pack/plugins/cases/public/components/description/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { basicCase } from '../../containers/mock';

import { Description } from '.';
import type { AppMockRenderer } from '../../common/mock';
import { createAppMockRenderer, noUpdateCasesPermissions, TestProviders } from '../../common/mock';
import { createAppMockRenderer, noUpdateCasesPermissions } from '../../common/mock';
import { MAX_DESCRIPTION_LENGTH } from '../../../common/constants';

jest.mock('../../common/lib/kibana');
Expand All @@ -27,13 +27,7 @@ const defaultProps = {
isLoadingDescription: false,
};

// FLAKY: https://github.com/elastic/kibana/issues/174321
// FLAKY: https://github.com/elastic/kibana/issues/174322
// FLAKY: https://github.com/elastic/kibana/issues/174323
// FLAKY: https://github.com/elastic/kibana/issues/164045
// FLAKY: https://github.com/elastic/kibana/issues/164048
// FLAKY: https://github.com/elastic/kibana/issues/164049
describe.skip('Description', () => {
describe('Description', () => {
const onUpdateField = jest.fn();
let appMockRender: AppMockRenderer;

Expand All @@ -45,48 +39,42 @@ describe.skip('Description', () => {
it('renders description correctly', async () => {
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

expect(screen.getByTestId('description')).toBeInTheDocument();
expect(screen.getByText('Security banana Issue')).toBeInTheDocument();
expect(await screen.findByTestId('description')).toBeInTheDocument();
expect(await screen.findByText('Security banana Issue')).toBeInTheDocument();
});

it('hides and shows the description correctly when collapse button clicked', async () => {
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

userEvent.click(res.getByTestId('description-collapse-icon'));
userEvent.click(await screen.findByTestId('description-collapse-icon'));

await waitFor(() => {
expect(screen.queryByText('Security banana Issue')).not.toBeInTheDocument();
});

userEvent.click(res.getByTestId('description-collapse-icon'));
userEvent.click(await screen.findByTestId('description-collapse-icon'));

expect(await screen.findByText('Security banana Issue')).toBeInTheDocument();
});

it('shows textarea on edit click', async () => {
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.click(await screen.findByTestId('description-edit-icon'));

expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument();
});

it('edits the description correctly when saved', async () => {
const editedDescription = 'New updated description';
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.click(await screen.findByTestId('description-edit-icon'));

userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), editedDescription);
userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription);

userEvent.click(screen.getByTestId('editable-save-markdown'));
userEvent.click(await screen.findByTestId('editable-save-markdown'));

await waitFor(() => {
expect(onUpdateField).toHaveBeenCalledWith({
Expand All @@ -98,37 +86,33 @@ describe.skip('Description', () => {

it('keeps the old description correctly when canceled', async () => {
const editedDescription = 'New updated description';
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.click(await screen.findByTestId('description-edit-icon'));

userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), editedDescription);
userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), editedDescription);

expect(screen.getByText(editedDescription)).toBeInTheDocument();
expect(await screen.findByText(editedDescription)).toBeInTheDocument();

userEvent.click(screen.getByTestId('editable-cancel-markdown'));
userEvent.click(await screen.findByTestId('editable-cancel-markdown'));

await waitFor(() => {
expect(onUpdateField).not.toHaveBeenCalled();
});

expect(screen.getByText('Security banana Issue')).toBeInTheDocument();
expect(await screen.findByText('Security banana Issue')).toBeInTheDocument();
});

it('shows an error when description is too long', async () => {
const longDescription = 'a'.repeat(MAX_DESCRIPTION_LENGTH + 1);

const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.click(await screen.findByTestId('description-edit-icon'));

userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), longDescription);
userEvent.clear(await screen.findByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), longDescription);

expect(
await screen.findByText(
Expand All @@ -139,14 +123,11 @@ describe.skip('Description', () => {
expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled');
});

it('should hide the edit button when the user does not have update permissions', () => {
appMockRender.render(
<TestProviders permissions={noUpdateCasesPermissions()}>
<Description {...defaultProps} onUpdateField={onUpdateField} />
</TestProviders>
);
it('should hide the edit button when the user does not have update permissions', async () => {
appMockRender = createAppMockRenderer({ permissions: noUpdateCasesPermissions() });
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);

expect(screen.getByText('Security banana Issue')).toBeInTheDocument();
expect(await screen.findByText('Security banana Issue')).toBeInTheDocument();
expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument();
});

Expand Down

0 comments on commit 6aa5ae8

Please sign in to comment.