Skip to content

Commit

Permalink
test: added draft test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Jul 7, 2024
1 parent bc30a62 commit 7ac7115
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
24 changes: 24 additions & 0 deletions src/discussions/post-comments/PostCommentsView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
33 changes: 22 additions & 11 deletions src/setupTest.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -23,21 +26,29 @@ Object.defineProperty(window, 'matchMedia', {
const MockEditor = ({
onBlur,
onEditorChange,
}) => (
<textarea
data-testid="tinymce-editor"
onChange={(event) => {
onEditorChange(event.currentTarget.value);
}}
onBlur={event => {
onBlur(event.currentTarget.value);
}}
/>
);
value,
}) => {
const [submitting, dispatch] = useDispatchWithState();

Check failure on line 31 in src/setupTest.jsx

View workflow job for this annotation

GitHub Actions / tests

'submitting' is assigned a value but never used

return (
<textarea
data-testid="tinymce-editor"
value={value}
onChange={(event) => {
onEditorChange(`${event.currentTarget.value}`);
dispatch(setDraftContent({ responses: [{ threadId: 'thread-1', content: `${event.currentTarget.value}` }], comments: [] }));
}}
onBlur={event => {
onBlur(event.currentTarget.value);
}}
/>
);
};

MockEditor.propTypes = {
onBlur: PropTypes.func.isRequired,
onEditorChange: PropTypes.func.isRequired,
value: PropTypes.string.isRequired,
};
jest.mock('@tinymce/tinymce-react', () => {
const originalModule = jest.requireActual('@tinymce/tinymce-react');
Expand Down

0 comments on commit 7ac7115

Please sign in to comment.