Skip to content

Commit

Permalink
[Cases] Fix description component flaky tests (#164063)
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi and kibanamachine authored Aug 16, 2023
1 parent 0fedc8b commit f9bc627
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 68 deletions.
70 changes: 2 additions & 68 deletions x-pack/plugins/cases/public/components/description/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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')
Expand Down Expand Up @@ -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} />
Expand Down
30 changes: 30 additions & 0 deletions x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f9bc627

Please sign in to comment.