E2E/Cypress: Fix for flaky tests on edit post (dot_menu_spec.js and center_channel_rhs_overlap_spec.js) (#33816)

* fix for message edits

* Update e2e-tests/cypress/tests/support/ui/post.ts

Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>

---------

Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>
This commit is contained in:
sabril 2025-09-02 10:20:18 +08:00 committed by GitHub
parent 8a007f4a7f
commit cd4dc759b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 82 deletions

View file

@ -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);

View file

@ -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);
});
});

View file

@ -63,6 +63,18 @@ function getPost(postId: string): ChainableT<JQuery> {
}
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
*