Skip to content

Commit

Permalink
[Cases] Fix flakiness in the description tests (elastic#170433)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Nov 3, 2023
1 parent c2f6fc4 commit 9c26527
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions x-pack/plugins/cases/public/components/description/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ describe('Description', () => {

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

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

it('shows textarea on edit click', async () => {
Expand All @@ -68,9 +66,7 @@ describe('Description', () => {

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

await waitFor(() => {
expect(screen.getByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument();
});
expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toBeInTheDocument();
});

it('edits the description correctly when saved', async () => {
Expand All @@ -82,12 +78,15 @@ describe('Description', () => {
userEvent.click(res.getByTestId('description-edit-icon'));

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

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

await waitFor(() => {
expect(onUpdateField).toHaveBeenCalledWith({ key: 'description', value: editedDescription });
expect(onUpdateField).toHaveBeenCalledWith({
key: 'description',
value: editedDescription,
});
});
});

Expand All @@ -100,20 +99,21 @@ describe('Description', () => {
userEvent.click(res.getByTestId('description-edit-icon'));

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

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

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

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

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

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

const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
Expand All @@ -124,14 +124,13 @@ describe('Description', () => {
userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.paste(screen.getByTestId('euiMarkdownEditorTextArea'), longDescription);

await waitFor(() => {
expect(
screen.getByText(
'The length of the description is too long. The maximum length is 30000 characters.'
)
).toBeInTheDocument();
expect(screen.getByTestId('editable-save-markdown')).toHaveAttribute('disabled');
});
expect(
await screen.findByText(
'The length of the description is too long. The maximum length is 30000 characters.'
)
).toBeInTheDocument();

expect(await screen.findByTestId('editable-save-markdown')).toHaveAttribute('disabled');
});

it('should hide the edit button when the user does not have update permissions', () => {
Expand Down

0 comments on commit 9c26527

Please sign in to comment.