diff --git a/e2e-tests/cypress/tests/integration/channels/keyboard_shortcuts/dot_menu_spec.js b/e2e-tests/cypress/tests/integration/channels/keyboard_shortcuts/dot_menu_spec.js index 0d51562edea..9b5650386c9 100644 --- a/e2e-tests/cypress/tests/integration/channels/keyboard_shortcuts/dot_menu_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/keyboard_shortcuts/dot_menu_spec.js @@ -69,7 +69,7 @@ describe('Keyboard Shortcuts', () => { // # add test to the message cy.get('#edit_textbox').type(postEditMessage); - cy.get('#edit_textbox').type('{enter}'); + cy.get('#create_post').findByText('Save').should('be.visible').click(); // * Verify edited message cy.uiWaitUntilMessagePostedIncludes(postMessage + postEditMessage); diff --git a/e2e-tests/cypress/tests/integration/channels/messaging/center_channel_rhs_overlap_spec.js b/e2e-tests/cypress/tests/integration/channels/messaging/center_channel_rhs_overlap_spec.js index 20900d3cb5b..f46ccce32b3 100644 --- a/e2e-tests/cypress/tests/integration/channels/messaging/center_channel_rhs_overlap_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/messaging/center_channel_rhs_overlap_spec.js @@ -12,7 +12,7 @@ import * as TIMEOUTS from '../../../fixtures/timeouts'; import * as MESSAGES from '../../../fixtures/messages'; -import {isMac} from '../../../utils'; +import {isMac, getRandomId} from '../../../utils'; describe('Messaging', () => { let testTeam; @@ -248,20 +248,14 @@ describe('Messaging', () => { cy.get(`#postMessageText_${postId}`).should('contain', message1); }); - // # [18] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(message2).type('{enter}').wait(TIMEOUTS.HALF_SEC); - }); - - // * Check that the edited message has been posted cy.getLastPostId().then((postId) => { - cy.get(`#postMessageText_${postId}`).should('contain', message2); + const message = `message ${getRandomId()}`; + + // # [18] Edit previous post + cy.editLastPostWithNewMessage(message); + + // * Check that the edited message has been posted + cy.get(`#postMessageText_${postId}`).should('contain', message); }); // # [19] Post message with quotes @@ -273,19 +267,11 @@ describe('Messaging', () => { cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly1); }); - // # [20] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(messageWithCodeblock1).type('{enter}').wait(TIMEOUTS.HALF_SEC); - }); - - // * Check that the edited message has been posted cy.getLastPostId().then((postId) => { + // # [20] Edit previous post + cy.editLastPostWithNewMessage(messageWithCodeblock1); + + // * Check that the edited message has been posted cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly1); }); @@ -387,19 +373,11 @@ describe('Messaging', () => { cy.get(`#postMessageText_${postId}`).should('contain', message1); }); - // # [30] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(message2).type('{enter}').wait(TIMEOUTS.HALF_SEC); - }); - - // * Check that the edited message has been posted cy.getLastPostId().then((postId) => { + // # [30] Edit previous post + cy.editLastPostWithNewMessage(message2); + + // * Check that the edited message has been posted cy.get(`#postMessageText_${postId}`).should('contain', message2); }); @@ -412,19 +390,11 @@ describe('Messaging', () => { cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly1); }); - // # [32] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(messageWithCodeblock1).type('{enter}').wait(TIMEOUTS.HALF_SEC); - }); - - // * Check that the edited message has been posted cy.getLastPostId().then((postId) => { + // # [32] Edit previous post + cy.editLastPostWithNewMessage(messageWithCodeblock1); + + // * Check that the edited message has been posted cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly1); }); @@ -432,25 +402,11 @@ describe('Messaging', () => { cy.uiGetPostTextBox().clear().type(messageWithCodeblockIncomplete2).wait(TIMEOUTS.HALF_SEC); cy.uiGetPostTextBox().type('{enter}').wait(TIMEOUTS.HALF_SEC); - // * Check that the message has been posted cy.getLastPostId().then((postId) => { - cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly2); - }); + // # [34] Edit previous post + cy.editLastPostWithNewMessage(messageWithCodeblockIncomplete2); - // # [34] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(messageWithCodeblockIncomplete2).wait(TIMEOUTS.HALF_SEC); - cy.get('#edit_textbox').type('{enter}'); - }); - - // * Check that the edited message has been posted - cy.getLastPostId().then((postId) => { + // * Check that the edited message has been posted cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly2); }); @@ -463,21 +419,11 @@ describe('Messaging', () => { cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly3); }); - // # [36] Edit previous post - cy.getLastPostId().then(() => { - cy.uiGetPostTextBox().type('{uparrow}'); - - // * Edit Post Input should appear - cy.get('#edit_textbox').should('be.visible'); - - // * Update the post message and type ENTER - cy.get('#edit_textbox').invoke('val', '').type(`${messageWithCodeblockIncomplete3}{leftArrow}{leftArrow}{leftArrow}`).wait(TIMEOUTS.HALF_SEC); - cy.get('#edit_textbox').type('{enter}'); - }); - - // * Check that the message has been posted - // Bug? - when clocking CTRL+ENTER from edit box, the code block does not appear in center cy.getLastPostId().then((postId) => { + // # [36] Edit previous post + cy.editLastPostWithNewMessage(`${messageWithCodeblockIncomplete3}{leftArrow}{leftArrow}{leftArrow}`); + + // * Check that the edited message has been posted cy.get(`#postMessageText_${postId}`).should('contain', messageWithCodeblockTextOnly3); }); }); diff --git a/e2e-tests/cypress/tests/support/ui/post.ts b/e2e-tests/cypress/tests/support/ui/post.ts index 5186a800748..50d5547dd49 100644 --- a/e2e-tests/cypress/tests/support/ui/post.ts +++ b/e2e-tests/cypress/tests/support/ui/post.ts @@ -63,6 +63,18 @@ function getPost(postId: string): ChainableT { } Cypress.Commands.add('getPost', getPost); +function editLastPostWithNewMessage(message: string) { + cy.uiGetPostTextBox().type('{uparrow}'); + + // * Edit Post Input should appear + cy.get('#edit_textbox').should('be.visible'); + + // # Update the post message and click Save + cy.get('#edit_textbox').clear().type(message) + cy.get('#create_post').findByText('Save').should('be.visible').click(); +} +Cypress.Commands.add('editLastPostWithNewMessage', editLastPostWithNewMessage); + export function verifySavedPost(postId, message) { // * Check that the center save icon has been updated correctly cy.get(`#post_${postId}`).trigger('mouseover', {force: true}); @@ -182,6 +194,16 @@ declare global { namespace Cypress { interface Chainable { + /** + * Edit last post with a new message + * + * @param {string} - message + * + * @example + * cy.editLastPostWithNewMessage('new message'); + */ + editLastPostWithNewMessage: typeof editLastPostWithNewMessage; + /** * Get post profile image of a given post ID or the last post if post ID is not given *