From 36027ac1c45f2b9b65168c0f35fff77b68d720ac Mon Sep 17 00:00:00 2001 From: Caleb Roseland Date: Wed, 7 Jun 2023 12:54:29 -0500 Subject: [PATCH] MM-52995: Fix opening DM/GM thread from thread footer (#23579) --- .../open_thread_dm_spec.js | 70 +++++++++++++++++++ .../src/components/post/post_component.tsx | 4 +- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js diff --git a/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js new file mode 100644 index 0000000000..87c89f6112 --- /dev/null +++ b/e2e-tests/cypress/tests/integration/channels/collapsed_reply_threads/open_thread_dm_spec.js @@ -0,0 +1,70 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +// *************************************************************** +// - [#] indicates a test step (e.g. # Go to a page) +// - [*] indicates an assertion (e.g. * Check the title) +// - Use element ID when selecting an element. Create one if none. +// *************************************************************** + +// Stage: @prod +// Group: @channels @collapsed_reply_threads + +describe('Collapsed Reply Threads', () => { + let testTeam; + let testUser; + let otherUser; + + before(() => { + cy.apiUpdateConfig({ + ServiceSettings: { + ThreadAutoFollow: true, + CollapsedThreads: 'default_off', + EnableTutorial: false, + }, + }); + + // # Create new channel and other user, and add other user to channel + cy.apiInitSetup({loginAfter: true, promoteNewUserAsAdmin: true}).then(({team, user}) => { + testTeam = team; + testUser = user; + + cy.apiSaveCRTPreference(testUser.id, 'on'); + cy.apiCreateUser({prefix: 'other'}).then(({user: user1}) => { + otherUser = user1; + + cy.apiAddUserToTeam(testTeam.id, otherUser.id); + }); + }); + }); + + beforeEach(() => { + // # Visit the channel + cy.visit(`/${testTeam.name}/messages/@${otherUser.username}`); + }); + + it('should open thread when thread footer reply button is clicked in a DM/GM channel', () => { + // # Post a message + const msg = 'Root post'; + cy.postMessage(msg); + + cy.getLastPostId().then((rootId) => { + // # Thread with replies + cy.clickPostCommentIcon(rootId); + cy.uiGetReplyTextBox().type('reply{enter}'); + cy.uiGetReplyTextBox().type('reply2{enter}'); + cy.uiCloseRHS(); + + // * Check that the RHS is closed + cy.get('#rhsContainer').should('not.exist'); + + // # Get thread footer of last post and find reply button + cy.uiGetPostThreadFooter(rootId).find('button.ReplyButton').click(); + + // * Thread should be visible in RHS + cy.get(`#rhsPost_${rootId}`).within(() => { + cy.get(`#rhsPostMessageText_${rootId}`).should('be.visible').and('have.text', msg); + }); + }); + }); +}); diff --git a/webapp/channels/src/components/post/post_component.tsx b/webapp/channels/src/components/post/post_component.tsx index 6a63f95bb9..514cd96c85 100644 --- a/webapp/channels/src/components/post/post_component.tsx +++ b/webapp/channels/src/components/post/post_component.tsx @@ -390,12 +390,12 @@ const PostComponent = (props: Props): JSX.Element => { }, [post, props.actions, props.actions.selectPostFromRightHandSideSearch]); const handleThreadClick = useCallback((e: React.MouseEvent) => { - if (props.currentTeam.id === props.team?.id) { + if (props.currentTeam.id === teamId) { handleCommentClick(e); } else { handleJumpClick(e); } - }, [handleCommentClick, handleJumpClick]); + }, [handleCommentClick, handleJumpClick, props.currentTeam.id, teamId]); const postClass = classNames('post__body', {'post--edited': PostUtils.isEdited(post), 'search-item-snippet': isSearchResultItem});