diff --git a/cypress/integration/account_settings/display/channel_display_mode_spec.js b/cypress/integration/account_settings/display/channel_display_mode_spec.js index b323e222644c..b2c76596a41c 100644 --- a/cypress/integration/account_settings/display/channel_display_mode_spec.js +++ b/cypress/integration/account_settings/display/channel_display_mode_spec.js @@ -17,7 +17,7 @@ describe('Account Settings > Display > Channel Display Mode', () => { // Post a message to a channel cy.visit('/'); - cy.postMessage('Test for channel display mode {enter}'); + cy.postMessage('Test for channel display mode'); }); beforeEach(() => { diff --git a/cypress/integration/account_settings/general/nickname.js b/cypress/integration/account_settings/general/nickname.js index 636b60ba3370..6bcadc93b3f0 100644 --- a/cypress/integration/account_settings/general/nickname.js +++ b/cypress/integration/account_settings/general/nickname.js @@ -51,8 +51,8 @@ describe('Account Settings > Sidebar > General', () => { cy.get('#accountSettingsHeader > .close').click(); cy.get('#sidebarHeaderDropdownButton').click(); - cy.get('#manageMembers').should('be.visible'); - cy.get('#manageMembers').click(); + cy.get('#viewMembers').should('be.visible'); + cy.get('#viewMembers').click(); // # Search for username and check that no nickname is present cy.get('.modal-title').should('be.visible'); @@ -82,8 +82,8 @@ describe('Account Settings > Sidebar > General', () => { cy.get('#accountSettingsHeader > .close').click(); cy.get('#sidebarHeaderDropdownButton').click(); - cy.get('#manageMembers').should('be.visible'); - cy.get('#manageMembers').click(); + cy.get('#viewMembers').should('be.visible'); + cy.get('#viewMembers').click(); // # Search for username and check that expected nickname is present cy.get('.modal-title').should('be.visible'); diff --git a/cypress/integration/at_mentions/at_mentions_spec.js b/cypress/integration/at_mentions/at_mentions_spec.js index f3f023147979..b5252a1f1110 100644 --- a/cypress/integration/at_mentions/at_mentions_spec.js +++ b/cypress/integration/at_mentions/at_mentions_spec.js @@ -230,6 +230,8 @@ describe('at-mention', () => { cy.get('@postMessageText'). find(`[data-mention=${receiver.username}]`). should('not.exist'); + + cy.get('#sidebarItem_saepe-5').click({force: true}); }); }); }); diff --git a/cypress/integration/channel/edit_message_spec.js b/cypress/integration/channel/edit_message_spec.js index b815a96d4025..e65d186b50b2 100644 --- a/cypress/integration/channel/edit_message_spec.js +++ b/cypress/integration/channel/edit_message_spec.js @@ -22,7 +22,7 @@ describe('Edit Message', () => { cy.visit('/'); // # Post message "Hello" - cy.get('#post_textbox').type('Hello World!').type('{enter}'); + cy.postMessage('Hello World!'); // # Hit the up arrow to open the "edit modal" cy.get('#post_textbox').type('{uparrow}'); @@ -75,7 +75,7 @@ describe('Edit Message', () => { cy.visit('/'); // # Post a message - cy.postMessage('Checking timestamp {enter}'); + cy.postMessage('Checking timestamp'); cy.getLastPostId().then((postId) => { // # Mouseover post to display the timestamp @@ -149,7 +149,7 @@ describe('Edit Message', () => { cy.visit('/'); // # Enter first message - cy.get('#post_textbox').type('Hello{enter}'); + cy.postMessage('Hello'); // * Verify first message is sent and not pending cy.getLastPostId().then((postId) => { @@ -158,7 +158,7 @@ describe('Edit Message', () => { }); // # Enter second message - cy.get('#post_textbox').type('World!{enter}'); + cy.postMessage('World!'); // * Verify second message is sent and not pending cy.getLastPostId().then((postId) => { diff --git a/cypress/integration/channel/message_deletion_spec.js b/cypress/integration/channel/message_deletion_spec.js index c2d2ca13c0bb..ae4cbfbb03a6 100644 --- a/cypress/integration/channel/message_deletion_spec.js +++ b/cypress/integration/channel/message_deletion_spec.js @@ -17,7 +17,7 @@ describe('Message deletion', () => { it('M13336 Delete both parent post and reply when deleting parent post from center', () => { // # Post message in center. - cy.postMessage('test message deletion {enter}'); + cy.postMessage('test message deletion'); cy.getLastPostId().then((parentMessageId) => { // # Mouseover the post and click post comment icon. diff --git a/cypress/integration/channel/message_draft_spec.js b/cypress/integration/channel/message_draft_spec.js index 41255c7ab225..fd745fbcfd47 100644 --- a/cypress/integration/channel/message_draft_spec.js +++ b/cypress/integration/channel/message_draft_spec.js @@ -7,19 +7,19 @@ // - Use element ID when selecting an element. Create one if none. // *************************************************************** -/*eslint max-nested-callbacks: ["error", 3]*/ +/*eslint max-nested-callbacks: ["error", 4]*/ let testTeam; describe('Message Draft', () => { before(() => { // # Login as new user - cy.loginAsNewUser(); - - // # Create new team and visit its URL - cy.apiCreateTeam('test-team', 'Test Team').then((response) => { - testTeam = response.body; - cy.visit(`/${testTeam.name}`); + cy.loginAsNewUser().then(() => { + // # Create new team and visit its URL + cy.apiCreateTeam('test-team', 'Test Team').then((response) => { + testTeam = response.body; + cy.visit(`/${testTeam.name}`); + }); }); }); diff --git a/cypress/integration/channel/message_draft_then_switch_channel_spec.js b/cypress/integration/channel/message_draft_then_switch_channel_spec.js index c76857feabf9..40275b1a9d22 100644 --- a/cypress/integration/channel/message_draft_then_switch_channel_spec.js +++ b/cypress/integration/channel/message_draft_then_switch_channel_spec.js @@ -7,7 +7,7 @@ // - Use element ID when selecting an element. Create one if none. // *************************************************************** -/*eslint max-nested-callbacks: ["error", 3]*/ +/*eslint max-nested-callbacks: ["error", 4]*/ import * as TIMEOUTS from '../../fixtures/timeouts'; @@ -16,12 +16,12 @@ let testTeam; describe('Message Draft and Switch Channels', () => { before(() => { // # Login as new user - cy.loginAsNewUser(); - - // # Create new team and visit its URL - cy.apiCreateTeam('test-team', 'Test Team').then((response) => { - testTeam = response.body; - cy.visit(`/${testTeam.name}`); + cy.loginAsNewUser().then(() => { + // # Create new team and visit its URL + cy.apiCreateTeam('test-team', 'Test Team').then((response) => { + testTeam = response.body; + cy.visit(`/${testTeam.name}`); + }); }); }); diff --git a/cypress/integration/channel/message_edit_post_with_attachment_spec.js b/cypress/integration/channel/message_edit_post_with_attachment_spec.js index feefa2e0b2c8..d2b0e830a4f1 100644 --- a/cypress/integration/channel/message_edit_post_with_attachment_spec.js +++ b/cypress/integration/channel/message_edit_post_with_attachment_spec.js @@ -34,7 +34,7 @@ describe('MM-13697 Edit Post with attachment', () => { }); // # Type 'This is sample text' and submit - cy.get('#post_textbox').type('This is sample text{enter}'); + cy.postMessage('This is sample text'); // # Get last post ID cy.getLastPostId().then((postID) => { diff --git a/cypress/integration/email/mention_email_notification_spec.js b/cypress/integration/email/mention_email_notification_spec.js index e6013f9caab4..a6e41e80b99e 100644 --- a/cypress/integration/email/mention_email_notification_spec.js +++ b/cypress/integration/email/mention_email_notification_spec.js @@ -28,7 +28,7 @@ describe('Email notification', () => { it('post a message that mentions a user', () => { cy.apiLogin('user-1'); cy.visit('/ad-1/channels/town-square'); - cy.postMessage(`${text}{enter}`); + cy.postMessage(text); // Wait for a while to ensure that email notification is sent. cy.wait(TIMEOUTS.SMALL); diff --git a/cypress/integration/login/login_spec.js b/cypress/integration/login/login_spec.js index adb728bc1361..124b48895181 100644 --- a/cypress/integration/login/login_spec.js +++ b/cypress/integration/login/login_spec.js @@ -7,9 +7,17 @@ // - Use element ID when selecting an element. Create one if none. // *************************************************************** +/* eslint max-nested-callbacks: ["error", 4] */ + +let config; + describe('Login page', () => { before(() => { - // 1. Go to login page + cy.apiGetConfig().then((response) => { + config = response.body; + }); + + // # Go to login page cy.apiLogout(); cy.visit('/login'); @@ -20,13 +28,13 @@ describe('Login page', () => { cy.get('#login_section').should('be.visible'); // * Check the title - cy.title().should('include', 'Mattermost'); + cy.title().should('include', config.TeamSettings.SiteName); }); it('should match elements, body', () => { // * Check elements in the body cy.get('#login_section').should('be.visible'); - cy.get('#site_name').should('contain', 'Mattermost'); + cy.get('#site_name').should('contain', config.TeamSettings.SiteName); cy.get('#site_description').should('contain', 'All team communication in one place, searchable and accessible anywhere'); cy.get('#loginId').should('be.visible'); cy.get('#loginId').should('have.attr', 'placeholder', 'Email or Username'); @@ -44,13 +52,13 @@ describe('Login page', () => { cy.get('#copyright').should('contain', '© 2015-'); cy.get('#copyright').should('contain', 'Mattermost, Inc.'); cy.get('#about_link').should('contain', 'About'); - cy.get('#about_link').should('have.attr', 'href', 'https://about.mattermost.com/default-about/'); + cy.get('#about_link').should('have.attr', 'href', config.SupportSettings.AboutLink); cy.get('#privacy_link').should('contain', 'Privacy'); - cy.get('#privacy_link').should('have.attr', 'href', 'https://about.mattermost.com/default-privacy-policy/'); + cy.get('#privacy_link').should('have.attr', 'href', config.SupportSettings.PrivacyPolicyLink); cy.get('#terms_link').should('contain', 'Terms'); - cy.get('#terms_link').should('have.attr', 'href', 'https://about.mattermost.com/default-terms/'); + cy.get('#terms_link').should('have.attr', 'href', config.SupportSettings.TermsOfServiceLink); cy.get('#help_link').should('contain', 'Help'); - cy.get('#help_link').should('have.attr', 'href', 'https://about.mattermost.com/default-help/'); + cy.get('#help_link').should('have.attr', 'href', config.SupportSettings.HelpLink); }); it('should login then logout by user-1', () => { diff --git a/cypress/integration/login/signup_spec.js b/cypress/integration/login/signup_spec.js index 22ddc2557c2a..22f7511e1359 100644 --- a/cypress/integration/login/signup_spec.js +++ b/cypress/integration/login/signup_spec.js @@ -7,8 +7,17 @@ // - Use element ID when selecting an element. Create one if none. // *************************************************************** +/* eslint max-nested-callbacks: ["error", 4] */ + +let config; + describe('Signup Email page', () => { before(() => { + cy.apiGetConfig().then((response) => { + config = response.body; + }); + cy.apiLogout(); + // # Go to signup email page cy.visit('/signup_email'); }); @@ -18,7 +27,7 @@ describe('Signup Email page', () => { cy.get('#signup_email_section').should('be.visible'); // * Check the title - cy.title().should('include', 'Mattermost'); + cy.title().should('include', config.TeamSettings.SiteName); }); it('should match elements, back button', () => { @@ -32,7 +41,7 @@ describe('Signup Email page', () => { it('should match elements, body', () => { // * Check elements in the body cy.get('#signup_email_section').should('be.visible'); - cy.get('#site_name').should('contain', 'Mattermost'); + cy.get('#site_name').should('contain', config.TeamSettings.SiteName); cy.get('#site_description').should('contain', 'All team communication in one place, searchable and accessible anywhere'); cy.get('#create_account').should('contain', 'Let\'s create your account'); cy.get('#signin_account').should('contain', 'Already have an account?'); @@ -56,8 +65,8 @@ describe('Signup Email page', () => { cy.get('#createAccountButton').should('contain', 'Create Account'); cy.get('#signup_agreement').should('contain', 'By proceeding to create your account and use Mattermost, you agree to our Terms of Service and Privacy Policy. If you do not agree, you cannot use Mattermost.'); - cy.get('#signup_agreement > span > [href="https://about.mattermost.com/default-terms/"]').should('be.visible'); - cy.get('#signup_agreement > span > [href="https://about.mattermost.com/default-privacy-policy/"]').should('be.visible'); + cy.get(`#signup_agreement > span > [href="${config.SupportSettings.TermsOfServiceLink}"]`).should('be.visible'); + cy.get(`#signup_agreement > span > [href="${config.SupportSettings.PrivacyPolicyLink}"]`).should('be.visible'); }); it('should match elements, footer', () => { @@ -67,12 +76,12 @@ describe('Signup Email page', () => { cy.get('#copyright').should('contain', '© 2015-'); cy.get('#copyright').should('contain', 'Mattermost, Inc.'); cy.get('#about_link').should('contain', 'About'); - cy.get('#about_link').should('have.attr', 'href', 'https://about.mattermost.com/default-about/'); + cy.get('#about_link').should('have.attr', 'href', config.SupportSettings.AboutLink); cy.get('#privacy_link').should('contain', 'Privacy'); - cy.get('#privacy_link').should('have.attr', 'href', 'https://about.mattermost.com/default-privacy-policy/'); + cy.get('#privacy_link').should('have.attr', 'href', config.SupportSettings.PrivacyPolicyLink); cy.get('#terms_link').should('contain', 'Terms'); - cy.get('#terms_link').should('have.attr', 'href', 'https://about.mattermost.com/default-terms/'); + cy.get('#terms_link').should('have.attr', 'href', config.SupportSettings.TermsOfServiceLink); cy.get('#help_link').should('contain', 'Help'); - cy.get('#help_link').should('have.attr', 'href', 'https://about.mattermost.com/default-help/'); + cy.get('#help_link').should('have.attr', 'href', config.SupportSettings.HelpLink); }); }); diff --git a/cypress/integration/post_header/post_header_spec.js b/cypress/integration/post_header/post_header_spec.js index bf2b6e1e1e32..b4110d97e1c8 100644 --- a/cypress/integration/post_header/post_header_spec.js +++ b/cypress/integration/post_header/post_header_spec.js @@ -21,7 +21,7 @@ describe('Post Header', () => { cy.visit('/ad-1/channels/town-square'); // # Post a message - cy.postMessage('test for permalink{enter}'); + cy.postMessage('test for permalink'); // * Check initial state that "the jump to recent messages" is not visible cy.get('#archive-link-home').should('not.be.visible'); @@ -62,7 +62,7 @@ describe('Post Header', () => { cy.visit('/ad-1/channels/town-square'); // # Post a message - cy.postMessage('test for flagged post{enter}'); + cy.postMessage('test for flagged post'); cy.getLastPostId().then((postId) => { // * Check that the center flag icon of a post is not visible @@ -87,7 +87,7 @@ describe('Post Header', () => { cy.visit('/ad-1/channels/town-square'); // # Post a message - cy.postMessage('test for dropdown menu{enter}'); + cy.postMessage('test for dropdown menu'); cy.getLastPostId().then((postId) => { // * Check that the center dot menu' button and dropdown are hidden @@ -115,7 +115,7 @@ describe('Post Header', () => { cy.visit('/ad-1/channels/town-square'); // # Post a message - cy.postMessage('test for reaction and emoji picker{enter}'); + cy.postMessage('test for reaction and emoji picker'); cy.getLastPostId().then((postId) => { // * Check that the center post reaction icon and emoji picker are not visible @@ -145,7 +145,7 @@ describe('Post Header', () => { cy.visit('/ad-1/channels/town-square'); // # Post a message - cy.postMessage('test for opening and closing RHS{enter}'); + cy.postMessage('test for opening and closing RHS'); // # Open RHS on hover to a post and click to its comment icon cy.clickPostCommentIcon(); diff --git a/cypress/integration/search/search_user_post.js b/cypress/integration/search/search_user_post.js index 7645a54974e5..1eeb409041b0 100644 --- a/cypress/integration/search/search_user_post.js +++ b/cypress/integration/search/search_user_post.js @@ -40,7 +40,7 @@ describe('Search in DMs', () => { createNewDMChannel(users['user-2'].email); // # Post message to user - cy.postMessage(message + '{enter}'); + cy.postMessage(message); // # Type `in:` in searchbox cy.get('#searchBox').type('in:'); diff --git a/cypress/plugins/post_message_as.js b/cypress/plugins/post_message_as.js index 44e0751c813f..ac706ee1bc9f 100644 --- a/cypress/plugins/post_message_as.js +++ b/cypress/plugins/post_message_as.js @@ -1,35 +1,40 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -require('@babel/polyfill'); -require('isomorphic-fetch'); - -const {Client4} = require('mattermost-redux/client'); const axios = require('axios'); const cypressConfig = require('../../cypress.json'); module.exports = async ({sender, message, channelId, createAt = 0}) => { - const url = `${cypressConfig.baseUrl}/api/v4/users/login`; - - const response = await axios({ - url, + const loginResponse = await axios({ + url: `${cypressConfig.baseUrl}/api/v4/users/login`, headers: {'X-Requested-With': 'XMLHttpRequest'}, method: 'post', data: {login_id: sender.username, password: sender.password}, }); - const token = response.headers.token; - - Client4.setUrl(cypressConfig.baseUrl); - Client4.setToken(token); + const setCookie = loginResponse.headers['set-cookie']; + let cookieString = ''; + setCookie.forEach((cookie) => { + const nameAndValue = cookie.split(';')[0]; + cookieString += nameAndValue + ';'; + }); - const options = { - channel_id: channelId, - message, - type: '', - create_at: createAt, - }; + const response = await axios({ + url: `${cypressConfig.baseUrl}/api/v4/posts`, + headers: { + 'Content-Type': 'application/json', + 'X-Requested-With': 'XMLHttpRequest', + Cookie: cookieString, + }, + method: 'post', + data: { + channel_id: channelId, + message, + type: '', + create_at: createAt, + }, + }); - return Client4.createPost(options); + return {status: response.status, data: response.data, error: response.error}; }; diff --git a/cypress/support/api_commands.js b/cypress/support/api_commands.js index a5f6d7eeeec7..0a71e025a9b2 100644 --- a/cypress/support/api_commands.js +++ b/cypress/support/api_commands.js @@ -337,7 +337,7 @@ Cypress.Commands.add('loginAsNewUser', (user = {}) => { /** * Unpins pinned posts of given postID directly via API * This API assume that the user is logged in and has cookie to access -* @param {Object} postId - Post ID of the pinned post to unpin +* @param {String} postId - Post ID of the pinned post to unpin */ Cypress.Commands.add('apiUnpinPosts', (postId) => { return cy.request({ @@ -373,10 +373,19 @@ Cypress.Commands.add('apiUpdateConfig', (newSettings = {}) => { cy.apiLogout(); }); +Cypress.Commands.add('apiGetConfig', () => { + cy.apiLogin('sysadmin'); + + // # Get current settings + return cy.request('/api/v4/config'); +}); + // ***************************************************************************** // Post creation // ***************************************************************************** Cypress.Commands.add('postMessageAs', (sender, message, channelId, createAt = 0) => { - cy.task('postMessageAs', {sender, message, channelId, createAt}).its('message').should('equal', message); + cy.task('postMessageAs', {sender, message, channelId, createAt}). + its('status'). + should('be.equal', 201); }); diff --git a/cypress/support/ui_commands.js b/cypress/support/ui_commands.js index c7ef83b7e78a..46d9cc77e79b 100644 --- a/cypress/support/ui_commands.js +++ b/cypress/support/ui_commands.js @@ -126,6 +126,7 @@ function isMac() { Cypress.Commands.add('postMessage', (message) => { cy.get('#post_textbox', {timeout: TIMEOUTS.LARGE}).clear().type(message).type('{enter}'); + cy.wait(TIMEOUTS.TINY); }); Cypress.Commands.add('postMessageReplyInRHS', (message) => { @@ -311,7 +312,7 @@ Cypress.Commands.add('minDisplaySettings', () => { cy.get('#collapseTitle').should('be.visible', 'contain', 'Default appearance of image previews'); cy.get('#collapseEdit').should('be.visible', 'contain', 'Edit'); - cy.get('#message_displayTitle').should('be.visible', 'contain', 'Message Display'); + cy.get('#message_displayTitle').scrollIntoView().should('be.visible', 'contain', 'Message Display'); cy.get('#message_displayEdit').should('be.visible', 'contain', 'Edit'); cy.get('#languagesTitle').scrollIntoView().should('be.visible', 'contain', 'Language');