[Cases] Fix description component flaky tests (#164063)

## Summary

Fixes 
#164049 
 #164048
#164045 
#164044
#164050
#164047
#164046

Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2895

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Janki Salvi 2023-08-16 16:40:33 +02:00 committed by GitHub
parent 0fedc8b78e
commit f9bc627735
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 68 deletions

View file

@ -27,13 +27,7 @@ const defaultProps = {
isLoadingDescription: false,
};
// FLAKY: https://github.com/elastic/kibana/issues/164049
// FLAKY: https://github.com/elastic/kibana/issues/164048
// FLAKY: https://github.com/elastic/kibana/issues/164047
// FLAKY: https://github.com/elastic/kibana/issues/164046
// FLAKY: https://github.com/elastic/kibana/issues/164045
// FLAKY: https://github.com/elastic/kibana/issues/164044
describe.skip('Description', () => {
describe('Description', () => {
const onUpdateField = jest.fn();
let appMockRender: AppMockRenderer;
@ -97,27 +91,6 @@ describe.skip('Description', () => {
});
});
it('trims the description correctly when saved', async () => {
const descriptionWithSpaces = 'New updated description ';
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.type(screen.getByTestId('euiMarkdownEditorTextArea'), descriptionWithSpaces);
userEvent.click(screen.getByTestId('editable-save-markdown'));
await waitFor(() => {
expect(onUpdateField).toHaveBeenCalledWith({
key: 'description',
value: descriptionWithSpaces.trim(),
});
});
});
it('keeps the old description correctly when canceled', async () => {
const editedDescription = 'New updated description';
const res = appMockRender.render(
@ -137,38 +110,6 @@ describe.skip('Description', () => {
});
});
it('shows an error when description is empty', async () => {
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.type(screen.getByTestId('euiMarkdownEditorTextArea'), '');
await waitFor(() => {
expect(screen.getByText('A description is required.')).toBeInTheDocument();
expect(screen.getByTestId('editable-save-markdown')).toHaveAttribute('disabled');
});
});
it('shows an error when description is a sting of empty characters', async () => {
const res = appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} />
);
userEvent.click(res.getByTestId('description-edit-icon'));
userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.type(screen.getByTestId('euiMarkdownEditorTextArea'), ' ');
await waitFor(() => {
expect(screen.getByText('A description is required.')).toBeInTheDocument();
expect(screen.getByTestId('editable-save-markdown')).toHaveAttribute('disabled');
});
});
it('shows an error when description is too long', async () => {
const longDescription = Array(MAX_DESCRIPTION_LENGTH / 2 + 1)
.fill('a')
@ -204,20 +145,13 @@ describe.skip('Description', () => {
expect(screen.queryByTestId('description-edit-icon')).not.toBeInTheDocument();
});
// FLAKY: https://github.com/elastic/kibana/issues/164050
describe.skip('draft message', () => {
describe('draft message', () => {
const draftStorageKey = `cases.testAppId.basic-case-id.description.markdownEditor`;
beforeEach(() => {
sessionStorage.setItem(draftStorageKey, 'value set in storage');
});
it('should show unsaved draft message correctly', async () => {
appMockRender.render(<Description {...defaultProps} onUpdateField={onUpdateField} />);
expect(screen.getByTestId('description-unsaved-draft')).toBeInTheDocument();
});
it('should not show unsaved draft message when loading', async () => {
appMockRender.render(
<Description {...defaultProps} onUpdateField={onUpdateField} isLoadingDescription={true} />

View file

@ -87,6 +87,36 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await testSubjects.click('editable-title-cancel-btn');
});
it('shows error when description is empty strings, trims the description value on submit', async () => {
await testSubjects.click('description-edit-icon');
await header.waitUntilLoadingHasFinished();
const editCommentTextArea = await find.byCssSelector(
'[data-test-subj*="editable-markdown-form"] textarea.euiMarkdownEditorTextArea'
);
await header.waitUntilLoadingHasFinished();
await editCommentTextArea.focus();
await editCommentTextArea.clearValue();
await editCommentTextArea.type(' ');
const error = await find.byCssSelector('.euiFormErrorText');
expect(await error.getVisibleText()).equal('A description is required.');
await editCommentTextArea.type('Description with space ');
await testSubjects.click('editable-save-markdown');
await header.waitUntilLoadingHasFinished();
const desc = await find.byCssSelector(
'[data-test-subj="description"] [data-test-subj="scrollable-markdown"]'
);
expect(await desc.getVisibleText()).equal('Description with space');
});
it('adds a comment to a case', async () => {
const commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'