diff --git a/e2e-tests/cypress/tests/integration/channels/messaging/edit_message_spec.js b/e2e-tests/cypress/tests/integration/channels/messaging/edit_message_spec.js index 0bf2363650..1aad5036be 100644 --- a/e2e-tests/cypress/tests/integration/channels/messaging/edit_message_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/messaging/edit_message_spec.js @@ -145,4 +145,42 @@ describe('Edit Message', () => { cy.get(postText).should('have.text', `${secondMessage} Another new message Edited`); }); }); + + it('MM-T5416 should discard any changes made after cancelling the edit and opening the edit textbox again should display the original message', () => { + const message = 'World!'; + cy.postMessage(message); + + // * Verify message is sent and not pending + cy.getLastPostId().then((postId) => { + const postText = `#postMessageText_${postId}`; + cy.get(postText).should('have.text', message); + + // # Open edit textbox + cy.uiGetPostTextBox().type('{uparrow}'); + + // * Edit Post Input should appear, and edit the post + cy.get('#edit_textbox').should('be.visible'); + + // * Press the escape key to cancel + cy.get('#edit_textbox').should('have.text', message).type(' Another new message{esc}'); + cy.get('#edit_textbox').should('not.exist'); + + // * Check that the message wasn't edited + cy.get(postText).should('have.text', message); + }); + + cy.getLastPostId().then((postId) => { + const postText = `#postMessageText_${postId}`; + cy.get(postText).should('have.text', message); + + // # Open edit textbox again + cy.uiGetPostTextBox().type('{uparrow}'); + + // * Edit Post Input should appear, and edit the post + cy.get('#edit_textbox').should('be.visible'); + + // * Opening the edit textbox again after previously cancelling the edit should contain the original message. + cy.get('#edit_textbox').should('have.text', message); + }); + }); }); diff --git a/webapp/channels/src/components/edit_post/edit_post.tsx b/webapp/channels/src/components/edit_post/edit_post.tsx index 9a467ebbbf..3711dca85f 100644 --- a/webapp/channels/src/components/edit_post/edit_post.tsx +++ b/webapp/channels/src/components/edit_post/edit_post.tsx @@ -220,7 +220,13 @@ const EditPost = ({editingPost, actions, canEditPost, config, channelId, draft, actions.unsetEditingPost(); }; - const handleAutomatedRefocusAndExit = () => handleRefocusAndExit(editingPost.refocusId || null); + const handleAutomatedRefocusAndExit = () => { + draftRef.current = { + ...draftRef.current, + message: '', + }; + handleRefocusAndExit(editingPost.refocusId || null); + }; const handleEdit = async () => { if (!editingPost.post || isSaveDisabled()) {