From d34d0ebbbcca556ecf21b2ecd7252190985c2310 Mon Sep 17 00:00:00 2001
From: Awais Ansari <79941147+awais-ansari@users.noreply.github.com>
Date: Mon, 20 Feb 2023 16:07:58 +0500
Subject: [PATCH] feat: hide the comments sort feature (#441)
* feat: hide the comments sort feature
* test: temporarily comment the commnets/responses test cases
* refactor: remove comments sort commented test cases
---
.../post-comments/PostCommentsView.jsx | 3 +-
.../post-comments/PostCommentsView.test.jsx | 68 +------------------
2 files changed, 3 insertions(+), 68 deletions(-)
diff --git a/src/discussions/post-comments/PostCommentsView.jsx b/src/discussions/post-comments/PostCommentsView.jsx
index 3ba81833..07fa3b91 100644
--- a/src/discussions/post-comments/PostCommentsView.jsx
+++ b/src/discussions/post-comments/PostCommentsView.jsx
@@ -40,6 +40,7 @@ function PostCommentsView({ intl }) {
const {
courseId, learnerUsername, category, topicId, page, enableInContextSidebar,
} = useContext(DiscussionContext);
+ const enableCommentsSort = false;
useEffect(() => {
if (!thread) { submitDispatch(fetchThread(postId, courseId, true)); }
@@ -109,7 +110,7 @@ function PostCommentsView({ intl }) {
/>
)}
- {!!commentsCount && commentsStatus === RequestStatus.SUCCESSFUL && }
+ {!!commentsCount && commentsStatus === RequestStatus.SUCCESSFUL && enableCommentsSort && }
{thread.type === ThreadType.DISCUSSION && (
{
@@ -106,7 +104,7 @@ function renderComponent(postId) {
,
);
- container = wrapper.container;
+ return wrapper;
}
describe('ThreadView', () => {
@@ -698,68 +696,4 @@ describe('ThreadView', () => {
expect(screen.queryByRole('dialog', { name: /Delete/i, exact: false })).toBeInTheDocument();
});
});
-
- describe('for comments sort', () => {
- it('should show sort dropdown if there are endorse or unendorsed comments', async () => {
- renderComponent(discussionPostId);
-
- const comment = await waitFor(() => screen.findByTestId('comment-comment-1'));
- const sortWrapper = container.querySelector('.comments-sort');
- const sortDropDown = within(sortWrapper).getByRole('button', { name: /Oldest first/i });
-
- expect(comment).toBeInTheDocument();
- expect(sortDropDown).toBeInTheDocument();
- });
-
- it('should not show sort dropdown if there is no response', async () => {
- const commentId = 'comment-1';
- renderComponent(discussionPostId);
-
- await waitFor(() => screen.findByTestId('comment-comment-1'));
- axiosMock.onDelete(`${commentsApiUrl}${commentId}/`).reply(201);
- await executeThunk(removeComment(commentId, discussionPostId), store.dispatch, store.getState);
-
- expect(await waitFor(() => screen.findByText('No responses', { exact: true }))).toBeInTheDocument();
- expect(container.querySelector('.comments-sort')).not.toBeInTheDocument();
- });
-
- it('should have only two options', async () => {
- renderComponent(discussionPostId);
-
- await waitFor(() => screen.findByTestId('comment-comment-1'));
- await act(async () => { fireEvent.click(screen.getByRole('button', { name: /Oldest first/i })); });
- const dropdown = await waitFor(() => screen.findByTestId('comment-sort-dropdown-modal-popup'));
-
- expect(dropdown).toBeInTheDocument();
- expect(await within(dropdown).getAllByRole('button')).toHaveLength(2);
- });
-
- it('should be selected Oldest first and auto focus', async () => {
- renderComponent(discussionPostId);
-
- await waitFor(() => screen.findByTestId('comment-comment-1'));
- await act(async () => { fireEvent.click(screen.getByRole('button', { name: /Oldest first/i })); });
- const dropdown = await waitFor(() => screen.findByTestId('comment-sort-dropdown-modal-popup'));
-
- expect(dropdown).toBeInTheDocument();
- expect(within(dropdown).getByRole('button', { name: /Oldest first/i })).toBeInTheDocument();
- expect(within(dropdown).getByRole('button', { name: /Oldest first/i })).toHaveFocus();
- expect(within(dropdown).getByRole('button', { name: /Newest first/i })).not.toHaveFocus();
- });
-
- test('successfully handles sort state update', async () => {
- renderComponent(discussionPostId);
-
- expect(store.getState().comments.sortOrder).toBeFalsy();
-
- await waitFor(() => screen.findByTestId('comment-comment-1'));
- await act(async () => { fireEvent.click(screen.getByRole('button', { name: /Oldest first/i })); });
- const dropdown = await waitFor(() => screen.findByTestId('comment-sort-dropdown-modal-popup'));
- await act(async () => {
- fireEvent.click(within(dropdown).getByRole('button', { name: /Newest first/i }));
- });
-
- expect(store.getState().comments.sortOrder).toBeTruthy();
- });
- });
});