From 7ac71153d9ba42bebf244eda686bcca2c10c67be Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Mon, 8 Jul 2024 00:44:22 +0500 Subject: [PATCH] test: added draft test case --- .../post-comments/PostCommentsView.test.jsx | 24 ++++++++++++++ src/setupTest.jsx | 33 ++++++++++++------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/discussions/post-comments/PostCommentsView.test.jsx b/src/discussions/post-comments/PostCommentsView.test.jsx index 4f15c596c..28a89d145 100644 --- a/src/discussions/post-comments/PostCommentsView.test.jsx +++ b/src/discussions/post-comments/PostCommentsView.test.jsx @@ -671,6 +671,30 @@ describe('ThreadView', () => { expect(screen.queryByTestId('reply-comment-3')).not.toBeInTheDocument(); }); + it('successfully added response in the draft.', async () => { + await waitFor(() => renderComponent(discussionPostId)); + + let addResponseBtn = screen.queryByText('Add response'); + await act(async () => { + fireEvent.click(addResponseBtn); + }); + + await waitFor(() => { + const editor = screen.queryByTestId('tinymce-editor'); + fireEvent.change(editor, { target: { value: 'Hello, world!' } }); + }); + const cancelBtn = screen.queryByText('Cancel'); + await act(async () => { + fireEvent.click(cancelBtn); + }); + addResponseBtn = screen.queryByText('Add response'); + await act(async () => { + fireEvent.click(addResponseBtn); + }); + + expect(screen.queryByText('Hello, world!')).toBeInTheDocument(); + }); + it('pressing load more button will load next page of replies', async () => { await waitFor(() => renderComponent(discussionPostId)); diff --git a/src/setupTest.jsx b/src/setupTest.jsx index 261398e07..1f49be487 100755 --- a/src/setupTest.jsx +++ b/src/setupTest.jsx @@ -1,5 +1,8 @@ import PropTypes from 'prop-types'; +import useDispatchWithState from './data/hooks'; +import { setDraftContent } from './discussions/post-comments/data/slices'; + import '@testing-library/jest-dom/extend-expect'; import 'babel-polyfill'; @@ -23,21 +26,29 @@ Object.defineProperty(window, 'matchMedia', { const MockEditor = ({ onBlur, onEditorChange, -}) => ( -