From c9cb3d5bb08d126959f7ce62a9f434ee2a895c29 Mon Sep 17 00:00:00 2001 From: Mario Vitale Date: Mon, 6 May 2024 08:37:20 +0200 Subject: [PATCH] Fix E2E test cases and setup for GHA (#26944) * Fix E2E test cases and setup for GHA * Fix more test cases, apply recommendations --- e2e-tests/.ci/.e2erc | 2 +- e2e-tests/.ci/dashboard.override.yml | 2 -- e2e-tests/.ci/server.generate.sh | 7 ------- e2e-tests/.ci/server.prepare.sh | 10 ++++++++++ e2e-tests/.ci/server.start.sh | 9 +++++++++ .../channels/channel_settings/channel_header_spec.ts | 8 +++++--- .../enterprise/metrics/license_no_license_spec.js | 2 +- .../sidebar_link_navigation_e20_spec.js | 2 +- .../settings/display/theme/code_theme_colors_spec.js | 2 +- .../signin_authentication/login_close_server_spec.js | 12 +++++++++++- .../join_closed_team_with_not_allowed_email_spec.js | 2 +- .../toast/unread_with_bottom_start_toast_spec.js | 6 +++--- e2e-tests/cypress/tests/utils/admin_console.js | 3 ++- 13 files changed, 45 insertions(+), 22 deletions(-) diff --git a/e2e-tests/.ci/.e2erc b/e2e-tests/.ci/.e2erc index e3fb105050..0ebb1b67e0 100644 --- a/e2e-tests/.ci/.e2erc +++ b/e2e-tests/.ci/.e2erc @@ -52,7 +52,7 @@ mme2e_wait_service_healthy () { SERVICE_NAME=${1?} RETRIES_LEFT=${2:-1} RETRIES_INTERVAL=${3:-10} - mme2e_wait_command_success "${DC_COMMAND} ps ${SERVICE_NAME} | grep -q '\(healthy\)'" "Waiting for ${SERVICE_NAME} container to be healthy" "$RETRIES_LEFT" "$RETRIES_INTERVAL" + mme2e_wait_command_success "${DC_COMMAND} ps ${SERVICE_NAME} | grep -qE '\(healthy\)'" "Waiting for ${SERVICE_NAME} container to be healthy" "$RETRIES_LEFT" "$RETRIES_INTERVAL" } mme2e_wait_image () { IMAGE_NAME=${1?} diff --git a/e2e-tests/.ci/dashboard.override.yml b/e2e-tests/.ci/dashboard.override.yml index 3f8471ccaa..2ae00bb084 100644 --- a/e2e-tests/.ci/dashboard.override.yml +++ b/e2e-tests/.ci/dashboard.override.yml @@ -1,6 +1,4 @@ --- -version: "3.1" - services: dashboard: image: mattermostdevelopment/mirrored-node:18.17 diff --git a/e2e-tests/.ci/server.generate.sh b/e2e-tests/.ci/server.generate.sh index fe34a9ede6..d43f2294a2 100755 --- a/e2e-tests/.ci/server.generate.sh +++ b/e2e-tests/.ci/server.generate.sh @@ -45,7 +45,6 @@ generate_docker_compose_file() { # Image hashes in this file are for amd64 systems # NB: May include paths relative to the "server/build" directory, which contains the original compose file that this yaml is overriding -version: "2.4" services: server: image: \${SERVER_IMAGE} @@ -56,16 +55,10 @@ services: MM_SERVICESETTINGS_ALLOWCORSFROM: "*" MM_SERVICESETTINGS_ENABLELOCALMODE: "true" MM_SERVICESETTINGS_ENABLESECURITYFIXALERT: "false" - MM_PLUGINSETTINGS_ENABLED: "true" - MM_PLUGINSETTINGS_ENABLEUPLOADS: "true" - MM_PLUGINSETTINGS_AUTOMATICPREPACKAGEDPLUGINS: "true" - MM_TEAMSETTINGS_ENABLEOPENSERVER: "true" MM_SQLSETTINGS_DATASOURCE: "postgres://mmuser:mostest@localhost:5432/mattermost_test?sslmode=disable&connect_timeout=10&binary_parameters=yes" MM_SQLSETTINGS_DRIVERNAME: "postgres" MM_EMAILSETTINGS_SMTPSERVER: "localhost" MM_CLUSTERSETTINGS_READONLYCONFIG: "false" - MM_SERVICESETTINGS_ENABLEONBOARDINGFLOW: "false" - MM_FEATUREFLAGS_ONBOARDINGTOURTIPS: "false" MM_SERVICEENVIRONMENT: "test" MM_FEATUREFLAGS_MOVETHREADSENABLED: "true" MM_LOGSETTINGS_ENABLEDIAGNOSTICS: "false" diff --git a/e2e-tests/.ci/server.prepare.sh b/e2e-tests/.ci/server.prepare.sh index db9c7f18af..a619db53d3 100755 --- a/e2e-tests/.ci/server.prepare.sh +++ b/e2e-tests/.ci/server.prepare.sh @@ -3,6 +3,16 @@ set -e -u -o pipefail cd "$(dirname "$0")" . .e2erc +mme2e_log "Configuring starting server parameters that may be changed at runtime" +for SETTING in \ + TeamSettings.EnableOpenServer=true \ + PluginSettings.Enable=true \ + PluginSettings.EnableUploads=true \ + PluginSettings.AutomaticPrepackagedPlugins=true + do + mme2e_log "Configuring parameter: $SETTING" + ${MME2E_DC_SERVER} exec -T -- server mmctl --local config set $(tr = ' ' <<<$SETTING) +done if [ -n "${MM_LICENSE:-}" ]; then # We prefer uploading the license here, instead of setting the env var for the server # This is to retain the flexibility of being able to remove it programmatically, if the tests require it diff --git a/e2e-tests/.ci/server.start.sh b/e2e-tests/.ci/server.start.sh index a28460354b..39059db65e 100755 --- a/e2e-tests/.ci/server.start.sh +++ b/e2e-tests/.ci/server.start.sh @@ -19,4 +19,13 @@ if ! mme2e_wait_service_healthy server 60 10; then mme2e_log "Mattermost container not healthy, retry attempts exhausted. Giving up." >&2 exit 1 fi +for MIGRATION in migration_advanced_permissions_phase_2; do + # Query explanation: if it doesn't find the migration in the table, there are 0 results and the command fails with a divide-by-zero error. Otherwise the command succeeds + MIGRATION_CHECK_COMMAND="${MME2E_DC_SERVER} exec -T -- postgres psql -U mmuser mattermost_test -c \"select 1 / (select count(*) from Systems where name = '${MIGRATION}' and value = 'true');\"" + if ! mme2e_wait_command_success "$MIGRATION_CHECK_COMMAND >/dev/null 2>&1" "Waiting for migration to be completed: ${MIGRATION}" "30" "10"; then + mme2e_log "Migration ${MIGRATION} not completed, retry attempts exhausted. Giving up." >&2 + exit 2 + fi + mme2e_log "${MIGRATION}: completed." +done mme2e_log "Mattermost container is running and healthy" diff --git a/e2e-tests/cypress/tests/integration/channels/channel_settings/channel_header_spec.ts b/e2e-tests/cypress/tests/integration/channels/channel_settings/channel_header_spec.ts index 9ddef7c5f0..d54a9f2e52 100644 --- a/e2e-tests/cypress/tests/integration/channels/channel_settings/channel_header_spec.ts +++ b/e2e-tests/cypress/tests/integration/channels/channel_settings/channel_header_spec.ts @@ -73,12 +73,14 @@ function hoverOnChannelDescriptionAndVerifyBehavior() { const channelDescriptionText = `test description ${getRandomId()}`; // # Wait a little for channel to load - cy.wait(TIMEOUTS.FIVE_SEC); + cy.wait(TIMEOUTS.ONE_SEC); // # Scan within channel header description area cy.get('#channelHeaderDescription').should('be.visible').within(() => { - // * Verify that empty header text is visible and click it - cy.findByText('Add a channel header').should('be.visible').click(); + // * Verify that empty header text is exists and click it. + // Note that it is invisible until the mouse hovers it, which is unfeasible in Cypress + // https://docs.cypress.io/api/commands/hover + cy.findByText('Add a channel header').click({force: true}); }); // # Scan inside the channel header modal diff --git a/e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_no_license_spec.js b/e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_no_license_spec.js index aff4a98901..4611e800a7 100644 --- a/e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_no_license_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_no_license_spec.js @@ -15,7 +15,7 @@ import {checkMetrics, toggleMetricsOn} from './helper'; describe('Metrics > No license', () => { before(() => { cy.shouldNotRunOnCloudEdition(); - cy.apiAdminLogin(); + cy.apiAdminLogin().wait(50); cy.apiDeleteLicense(); toggleMetricsOn(); }); diff --git a/e2e-tests/cypress/tests/integration/channels/enterprise/system_console/sidebar_link_navigation_e20_spec.js b/e2e-tests/cypress/tests/integration/channels/enterprise/system_console/sidebar_link_navigation_e20_spec.js index 9e2881df6f..05a23b252b 100644 --- a/e2e-tests/cypress/tests/integration/channels/enterprise/system_console/sidebar_link_navigation_e20_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/enterprise/system_console/sidebar_link_navigation_e20_spec.js @@ -51,7 +51,7 @@ function verifyCanNavigate(testCase) { // * Verify that it redirects to the URL and matches with the header cy.url().should('include', testCase.url); - cy.get('.admin-console__header', {timeout: TIMEOUTS.ONE_MIN}). + cy.get(`${testCase.headerSelector || '.admin-console__header'}`, {timeout: TIMEOUTS.ONE_MIN}). should('be.visible'). and(testCase.headerContains ? 'contain' : 'have.text', testCase.header); } diff --git a/e2e-tests/cypress/tests/integration/channels/settings/display/theme/code_theme_colors_spec.js b/e2e-tests/cypress/tests/integration/channels/settings/display/theme/code_theme_colors_spec.js index c1d81837ed..9a4d883e44 100644 --- a/e2e-tests/cypress/tests/integration/channels/settings/display/theme/code_theme_colors_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/settings/display/theme/code_theme_colors_spec.js @@ -35,7 +35,7 @@ describe('Settings > Display > Theme > Custom Theme Colors', () => { cy.get('#customThemes').check().should('be.checked'); // # Open Center Channel Styles section - cy.get('#centerChannelStyles').click({force: true}); + cy.get('#centerChannelStyles').click({force: true}).wait(TIMEOUTS.ONE_HUNDRED_MILLIS); // # Select custom code theme cy.get('#codeThemeSelect').scrollIntoView().should('be.visible').select(theme.name); diff --git a/e2e-tests/cypress/tests/integration/channels/signin_authentication/login_close_server_spec.js b/e2e-tests/cypress/tests/integration/channels/signin_authentication/login_close_server_spec.js index f7eb8ca0f0..db4a64eebb 100644 --- a/e2e-tests/cypress/tests/integration/channels/signin_authentication/login_close_server_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/signin_authentication/login_close_server_spec.js @@ -11,13 +11,19 @@ // Group: @channels @signin_authentication describe('Login page with close server', () => { + const oldSettings = {}; before(() => { - // Disable other auth options + // Back up config, and disable other auth options const newSettings = { Office365Settings: {Enable: false}, LdapSettings: {Enable: false}, TeamSettings: {EnableOpenServer: false}, }; + cy.apiGetConfig((config) => { + Object.entries(newSettings).forEach(([key]) => { + oldSettings[key] = config[key]; + }); + }); cy.apiUpdateConfig(newSettings); // # Create new team and users @@ -26,6 +32,10 @@ describe('Login page with close server', () => { cy.visit('/login'); }); }); + after(() => { + // Restore backed up settings + cy.apiAdminLogin().apiUpdateConfig(oldSettings); + }); it('MM-47222 Should verify access problem page can be reached', () => { cy.findByText('Don\'t have an account?').should('be.visible').click(); cy.findByText('Contact your workspace admin').should('be.visible'); diff --git a/e2e-tests/cypress/tests/integration/channels/team_settings/join_closed_team_with_not_allowed_email_spec.js b/e2e-tests/cypress/tests/integration/channels/team_settings/join_closed_team_with_not_allowed_email_spec.js index 894f7daf1e..4371ca2ffa 100644 --- a/e2e-tests/cypress/tests/integration/channels/team_settings/join_closed_team_with_not_allowed_email_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/team_settings/join_closed_team_with_not_allowed_email_spec.js @@ -114,7 +114,7 @@ describe('Team Settings', () => { // # Set 'sample.mattermost.com' as the only allowed email domain and save cy.get('#allowedDomains').click().type(emailDomain).type(' '); - cy.findByText('Save').should('be.visible').click(); + cy.findByText('Save').should('be.visible'); // # Save and verify it took effect cy.uiSave(); diff --git a/e2e-tests/cypress/tests/integration/channels/toast/unread_with_bottom_start_toast_spec.js b/e2e-tests/cypress/tests/integration/channels/toast/unread_with_bottom_start_toast_spec.js index 2c5129c9d9..47492bc2d5 100644 --- a/e2e-tests/cypress/tests/integration/channels/toast/unread_with_bottom_start_toast_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/toast/unread_with_bottom_start_toast_spec.js @@ -43,7 +43,7 @@ describe('unread_with_bottom_start_toast', () => { // # Add enough messages for (let index = 0; index < 30; index++) { - cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}); + cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}).wait(50); } cy.postMessage('hello'); @@ -78,7 +78,7 @@ describe('unread_with_bottom_start_toast', () => { // # Add enough messages for (let index = 0; index < 30; index++) { - cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}); + cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}).wait(50); } cy.postMessage('hello'); @@ -111,7 +111,7 @@ describe('unread_with_bottom_start_toast', () => { // # Add enough messages for (let index = 0; index < 30; index++) { - cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}); + cy.postMessageAs({sender: otherUser, message: `test message ${index}`, channelId: channel.id}).wait(50); } cy.wait(TIMEOUTS.ONE_SEC); diff --git a/e2e-tests/cypress/tests/utils/admin_console.js b/e2e-tests/cypress/tests/utils/admin_console.js index 34a435b134..12b5a80666 100644 --- a/e2e-tests/cypress/tests/utils/admin_console.js +++ b/e2e-tests/cypress/tests/utils/admin_console.js @@ -15,7 +15,7 @@ export const adminConsoleNavigation = [ url: 'admin_console/billing/subscription', }, { - type: ['cloud_enterprise', 'e20'], + type: ['cloud_enterprise'], header: 'Billing History', sidebar: 'Billing History', url: 'admin_console/billing/billing_history', @@ -49,6 +49,7 @@ export const adminConsoleNavigation = [ { type: ['team', 'e20', 'cloud_enterprise'], header: 'Mattermost Users', + headerSelector: '.admin-console__header #systemUsersTable-headerId', sidebar: 'Users', url: 'admin_console/user_management/users', },