Skip to content

Commit

Permalink
[Cases] Fix flaky "add comment" tests. (#170400)
Browse files Browse the repository at this point in the history
Fixes #168505
Fixes #168506
Fixes #168507
Fixes #168508
Fixes #168509
(I hope)

## Summary

Covered most of the logic in e2e tests.

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

## 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

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
adcoelho and kibanamachine authored Nov 6, 2023
1 parent 95d729b commit 96a4d5b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
43 changes: 8 additions & 35 deletions x-pack/plugins/cases/public/components/add_comment/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,42 +131,15 @@ describe('AddComment ', () => {

appMockRender.render(<AddComment {...addCommentProps} ref={ref} />);

userEvent.type(screen.getByTestId('euiMarkdownEditorTextArea'), sampleData.comment);
userEvent.paste(await screen.findByTestId('euiMarkdownEditorTextArea'), sampleData.comment);

await act(async () => {
ref.current!.addQuote(sampleQuote);
});

await waitFor(() => {
expect(screen.getByTestId('euiMarkdownEditorTextArea').textContent).toContain(
`${sampleData.comment}\n\n> what a cool quote \n> with new lines \n\n`
);
});
});

it('should call onFocus when adding a quote', async () => {
const ref = React.createRef<AddCommentRefObject>();

appMockRender.render(<AddComment {...addCommentProps} ref={ref} />);

ref.current!.editor!.textarea!.focus = jest.fn();

await act(async () => {
ref.current!.addQuote('a comment');
});

await waitFor(() => {
expect(ref.current!.editor!.textarea!.focus).toHaveBeenCalled();
});
});

it('should NOT call onFocus on mount', async () => {
const ref = React.createRef<AddCommentRefObject>();

appMockRender.render(<AddComment {...addCommentProps} ref={ref} />);

ref.current!.editor!.textarea!.focus = jest.fn();
expect(ref.current!.editor!.textarea!.focus).not.toHaveBeenCalled();
expect((await screen.findByTestId('euiMarkdownEditorTextArea')).textContent).toContain(
`${sampleData.comment}\n\n> what a cool quote \n> with new lines \n\n`
);
});

it('it should insert a timeline', async () => {
Expand All @@ -185,13 +158,13 @@ describe('AddComment ', () => {
</CasesTimelineIntegrationProvider>
);

act(() => {
await act(async () => {
attachTimeline('[title](url)');
});

await waitFor(() => {
expect(screen.getByTestId('euiMarkdownEditorTextArea')).toHaveTextContent('[title](url)');
});
expect(await screen.findByTestId('euiMarkdownEditorTextArea')).toHaveTextContent(
'[title](url)'
);
});

describe('errors', () => {
Expand Down
24 changes: 24 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 @@ -33,6 +33,12 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
const kibanaServer = getService('kibanaServer');
const browser = getService('browser');

const hasFocus = async (testSubject: string) => {
const targetElement = await testSubjects.find(testSubject);
const activeElement = await find.activeElement();
return (await targetElement._webElement.getId()) === (await activeElement._webElement.getId());
};

describe('View case', () => {
describe('page', () => {
createOneCaseBeforeDeleteAllAfter(getPageObject, getService);
Expand Down Expand Up @@ -122,6 +128,11 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
expect(await desc.getVisibleText()).equal('Description with space');
});

it('comment area does not have focus on page load', async () => {
browser.refresh();
expect(await hasFocus('euiMarkdownEditorTextArea')).to.be(false);
});

it('adds a comment to a case', async () => {
const commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'
Expand All @@ -135,9 +146,22 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
const newComment = await find.byCssSelector(
'[data-test-subj*="comment-create-action"] [data-test-subj="scrollable-markdown"]'
);

expect(await newComment.getVisibleText()).equal('Test comment from automation');
});

it('quotes a comment on a case', async () => {
const commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'
);

await testSubjects.click('property-actions-user-action-ellipses');
await testSubjects.click('property-actions-user-action-quote');

expect(await commentArea.getVisibleText()).equal('> Test comment from automation ');
expect(await hasFocus('euiMarkdownEditorTextArea')).to.be(true);
});

it('adds a category to a case', async () => {
const category = uuidv4();
await testSubjects.click('category-edit-button');
Expand Down

0 comments on commit 96a4d5b

Please sign in to comment.