add e2e for persist draft check with existing comment (#163811)

## Summary

fixes https://github.com/elastic/kibana/issues/156741

Scenario | Old Test | Functional test where it is covered
-- | -- | --
'checks draft comment persist behaviour with another markdown user
action update' | 'it should persist the draft of new comment while
existing old comment is updated' | 'should persist the draft of new
comment while old comment is updated'

<br class="Apple-interchange-newline">

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


### Checklist

features that require explanation or tutorials
- [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 <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Janki Salvi 2023-08-15 16:24:06 +02:00 committed by GitHub
parent c2c1e076a4
commit 1774c0c942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 50 deletions

View file

@ -75,8 +75,7 @@ const useFindCaseUserActionsMock = useFindCaseUserActions as jest.Mock;
const useUpdateCommentMock = useUpdateComment as jest.Mock;
const patchComment = jest.fn();
// FLAKY: https://github.com/elastic/kibana/issues/156741
describe.skip(`UserActions`, () => {
describe(`UserActions`, () => {
const sampleData = {
content: 'what a great comment update',
};
@ -270,52 +269,4 @@ describe.skip(`UserActions`, () => {
expect(screen.queryByTestId('add-comment')).not.toBeInTheDocument();
});
});
it('it should persist the draft of new comment while existing old comment is updated', async () => {
const editedComment = 'it is an edited comment';
const newComment = 'another cool comment';
const ourActions = [getUserAction('comment', UserActionActions.create)];
useFindCaseUserActionsMock.mockReturnValue({
...defaultUseFindCaseUserActions,
data: { userActions: ourActions },
});
appMockRender.render(<UserActions {...defaultProps} />);
userEvent.clear(screen.getByTestId('euiMarkdownEditorTextArea'));
userEvent.type(screen.getByTestId('euiMarkdownEditorTextArea'), newComment);
userEvent.click(
within(
screen.getAllByTestId(`comment-create-action-${defaultProps.data.comments[0].id}`)[1]
).getByTestId('property-actions-user-action-ellipses')
);
await waitForEuiPopoverOpen();
userEvent.click(screen.getByTestId('property-actions-user-action-pencil'));
fireEvent.change(screen.getAllByTestId('euiMarkdownEditorTextArea')[0], {
target: { value: editedComment },
});
userEvent.click(
within(
screen.getAllByTestId(`comment-create-action-${defaultProps.data.comments[0].id}`)[1]
).getByTestId('editable-save-markdown')
);
await waitFor(() => {
expect(
within(
screen.getAllByTestId(`comment-create-action-${defaultProps.data.comments[0].id}`)[1]
).queryByTestId('editable-markdown-form')
).not.toBeInTheDocument();
});
await waitFor(() => {
expect(screen.getAllByTestId('add-comment')[1].textContent).toContain(newComment);
});
});
});

View file

@ -467,6 +467,56 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await testSubjects.existOrFail('description-unsaved-draft');
});
it('should persist the draft of new comment while old comment is updated', async () => {
await cases.singleCase.addComment('my first comment');
let commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'
);
await commentArea.focus();
await commentArea.clearValue();
await commentArea.type('Test comment from automation');
await testSubjects.click('property-actions-user-action-ellipses');
await header.waitUntilLoadingHasFinished();
await testSubjects.click('property-actions-user-action-pencil');
await header.waitUntilLoadingHasFinished();
const editCommentTextArea = await find.byCssSelector(
'[data-test-subj*="editable-markdown-form"] textarea.euiMarkdownEditorTextArea'
);
await header.waitUntilLoadingHasFinished();
await editCommentTextArea.focus();
await editCommentTextArea.type('Edited comment');
await testSubjects.click('editable-save-markdown');
await header.waitUntilLoadingHasFinished();
/**
* We need to wait for some time to
* give the localStorage a change to persist
* the comment. Otherwise, the test navigates to
* fast to the cases table and the comment is not
* persisted
*/
await setTimeoutAsync(2000);
await header.waitUntilLoadingHasFinished();
await browser.refresh();
await header.waitUntilLoadingHasFinished();
commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'
);
expect(await commentArea.getVisibleText()).to.be('Test comment from automation');
});
/**
* There is this bug https://github.com/elastic/kibana/issues/157280
* where this test randomly reproduces thus making the test flaky.