Files
upstream-mattermost/e2e-tests/playwright/specs/functional/channels/notifications/system_console.spec.ts
upstream-mirror 240db4e2a7
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:29:55 +05:00

327 lines
16 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {AdminConfig} from '@mattermost/types/config';
import type {DeepPartial} from '@mattermost/types/utilities';
import type {TextInputSetting} from '@mattermost/playwright-lib';
import {expect, test} from '@mattermost/playwright-lib';
/**
* Patch the Notifications page required fields to known valid values so tests
* that load the page always start with a saveable form state, regardless of
* what other parallel tests may have left in the server config.
*/
async function resetNotificationsConfig(adminClient: {
patchConfig: (config: DeepPartial<AdminConfig>) => Promise<unknown>;
}) {
await adminClient.patchConfig({
EmailSettings: {
FeedbackName: 'Mattermost Notification',
FeedbackEmail: 'notification@mattertest.com',
},
SupportSettings: {
SupportEmail: 'support@mattertest.com',
},
});
}
/** Wait until API reflects required notification fields (guards against concurrent initSetup). */
async function waitForNotificationsServerPreconditions(adminClient: {getConfig: () => Promise<unknown>}) {
await expect
.poll(
async () => {
const c = (await adminClient.getConfig()) as AdminConfig;
const support = c.SupportSettings?.SupportEmail?.trim();
const feedbackEmail = c.EmailSettings?.FeedbackEmail?.trim();
const feedbackName = c.EmailSettings?.FeedbackName?.trim();
return Boolean(support && feedbackEmail && feedbackName);
},
{timeout: 90_000, intervals: [300, 800, 1500, 3000]},
)
.toBe(true);
}
/**
* Populate the required notification text fields so the form is valid before saving. This does not
* assert that Save becomes enabled: the admin console only enables it once the form is dirty, and
* these values may already be what the server holds (e.g. a reused server where this spec ran before).
* Assert on Save at the call sites that actually changed something.
*/
async function fillRequiredNotificationFields(notifications: {
notificationDisplayName: TextInputSetting;
notificationFromAddress: TextInputSetting;
supportEmailAddress: TextInputSetting;
notificationReplyToAddress: TextInputSetting;
}) {
await notifications.notificationDisplayName.container.scrollIntoViewIfNeeded();
await notifications.notificationDisplayName.fill('Mattermost Notification');
await notifications.notificationFromAddress.container.scrollIntoViewIfNeeded();
await notifications.notificationFromAddress.fill('notification@mattertest.com');
await notifications.supportEmailAddress.container.scrollIntoViewIfNeeded();
await notifications.supportEmailAddress.fill('support@mattertest.com');
await notifications.notificationReplyToAddress.container.scrollIntoViewIfNeeded();
await notifications.notificationReplyToAddress.fill('notification@mattertest.com');
}
test.describe('System Console Notifications', () => {
test.describe.configure({mode: 'serial'});
/**
* @objective Verify that the Push Notification Contents setting is properly displayed and can be changed to all available options
*/
test('Push Notification Contents setting displays correctly and saves all options', async ({pw}) => {
// Multiple reload/save/retry rounds — default 60 s CI timeout is too tight when shards contend on config.
test.setTimeout(240000);
const {adminUser, adminClient} = await pw.getAdminClient();
if (!adminUser || !adminClient) {
throw new Error('Failed to get admin user');
}
// Ensure required Notifications fields are populated so the Save button
// starts enabled — prevents state pollution from concurrent initSetup() calls
// that reset FeedbackName and SupportEmail to '' via updateConfig(defaultConfig).
await resetNotificationsConfig(adminClient);
await waitForNotificationsServerPreconditions(adminClient);
// # Update to default config with required notification fields populated
await adminClient.patchConfig({
EmailSettings: {
FeedbackName: 'Mattermost Notification',
FeedbackEmail: 'notification@mattertest.com',
PushNotificationContents: 'full',
},
SupportSettings: {
SupportEmail: 'support@mattertest.com',
},
});
await waitForNotificationsServerPreconditions(adminClient);
// # Log in as admin
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit Notifications admin console page (direct URL — sidebar link can be off-screen in CI)
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
await systemConsolePage.gotoNotificationsSettings();
// # Wait for Notifications section to load
const notifications = systemConsolePage.notifications;
await notifications.toBeVisible();
// Re-apply guard: a concurrent initSetup() may have cleared SupportEmail (a required
// field) between the initial resetNotificationsConfig call and the page rendering here,
// leaving the Save button disabled. Re-apply the config and reload so the form
// renders with all required fields populated.
await resetNotificationsConfig(adminClient);
await waitForNotificationsServerPreconditions(adminClient);
await systemConsolePage.page.reload();
await systemConsolePage.gotoNotificationsSettings();
await notifications.toBeVisible();
await fillRequiredNotificationFields(notifications);
// * Verify that setting is visible and matches text content
await notifications.pushNotificationContents.container.scrollIntoViewIfNeeded();
await notifications.pushNotificationContents.toBeVisible();
// * Verify that the help text is visible and matches text content
const helpText = notifications.pushNotificationContents.helpText;
await expect(helpText).toBeVisible();
const contents = [
'Generic description with only sender name',
' - Includes only the name of the person who sent the message in push notifications, with no information about channel name or message contents. ',
'Generic description with sender and channel names',
' - Includes the name of the person who sent the message and the channel it was sent in, but not the message contents. ',
'Full message content sent in the notification payload',
" - Includes the message contents in the push notification payload that is relayed through Apple's Push Notification Service (APNS) or Google's Firebase Cloud Messaging (FCM). It is ",
'highly recommended',
' this option only be used with an "https" protocol to encrypt the connection and protect confidential information sent in messages.',
'Full message content fetched from the server on receipt',
' - The notification payload relayed through APNS or FCM contains no message content, instead it contains a unique message ID used to fetch message content from the server when a push notification is received by a device. If the server cannot be reached, a generic notification will be displayed.',
];
await expect(helpText).toHaveText(contents.join(''));
const strongElements = helpText.locator('strong');
await expect(strongElements.nth(0)).toHaveText(contents[0]);
await expect(strongElements.nth(1)).toHaveText(contents[2]);
await expect(strongElements.nth(2)).toHaveText(contents[4]);
await expect(strongElements.nth(3)).toHaveText(contents[6]);
await expect(strongElements.nth(4)).toHaveText(contents[8]);
// * Verify that the option/dropdown is visible and has default value
const dropdown = notifications.pushNotificationContents.dropdown;
await expect(dropdown).toBeVisible();
await expect(dropdown).toHaveValue('full');
const options = [
{label: 'Generic description with only sender name', value: 'generic_no_channel'},
{label: 'Generic description with sender and channel names', value: 'generic'},
{label: 'Full message content sent in the notification payload', value: 'full'},
{label: 'Full message content fetched from the server on receipt', value: 'id_loaded'},
];
// # Select each value and save
// * Verify that the config is correctly saved in the server
for (const option of options) {
let saved = false;
for (let attempt = 0; attempt < 8 && !saved; attempt++) {
await resetNotificationsConfig(adminClient);
await waitForNotificationsServerPreconditions(adminClient);
await systemConsolePage.page.reload();
await systemConsolePage.gotoNotificationsSettings();
await notifications.toBeVisible();
await notifications.pushNotificationContents.container.scrollIntoViewIfNeeded();
await notifications.pushNotificationContents.toBeVisible();
const loopDropdown = notifications.pushNotificationContents.dropdown;
await expect(loopDropdown).toBeVisible();
await loopDropdown.selectOption({label: option.label});
await expect(loopDropdown).toHaveValue(option.value);
await fillRequiredNotificationFields(notifications);
// The dropdown change above dirties the form, so Save must become enabled here.
await expect(notifications.saveButton).not.toBeDisabled({timeout: 25000});
await notifications.save();
const {adminClient: pollClient} = await pw.getAdminClient();
try {
await expect
.poll(
async () => {
const config = await pollClient.getConfig();
return config.EmailSettings?.PushNotificationContents;
},
{timeout: 45000, intervals: [500, 1000, 2000, 3000]},
)
.toBe(option.value);
saved = true;
} catch {
// Concurrent full-config resets can drop the save — reload and retry.
}
}
if (!saved) {
throw new Error(`Failed to save PushNotificationContents=${option.value} after retries`);
}
}
});
/**
* @objective Verify that the Support Email setting can be changed and saved
*/
test('MM-T1210 Can change Support Email setting', async ({pw}) => {
const {adminUser, adminClient} = await pw.getAdminClient();
if (!adminUser || !adminClient) {
throw new Error('Failed to get admin user');
}
// Ensure required Notifications fields are populated so the Save button
// starts enabled — prevents state pollution from other parallel tests.
await resetNotificationsConfig(adminClient);
await waitForNotificationsServerPreconditions(adminClient);
// # Log in as admin
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit Notifications admin console page (direct URL — sidebar link can be off-screen in CI)
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
await systemConsolePage.gotoNotificationsSettings();
// # Wait for Notifications section to load
const notifications = systemConsolePage.notifications;
await notifications.toBeVisible();
// # Scroll Support Email section into view and verify that it's visible
await notifications.supportEmailAddress.container.scrollIntoViewIfNeeded();
await notifications.supportEmailAddress.toBeVisible();
// * Verify that the help text is visible and matches text content
await expect(notifications.supportEmailAddress.helpText).toBeVisible();
await expect(notifications.supportEmailAddress.helpText).toHaveText(
'Email address displayed on support emails.',
);
// # Clear and type new email
const newEmail = 'changed_for_test_support@example.com';
await notifications.supportEmailAddress.clear();
await notifications.supportEmailAddress.fill(newEmail);
// * Verify that set value is visible and matches text
await expect(notifications.supportEmailAddress.input).toHaveValue(newEmail);
// # Wait for Save button to be enabled (React processes fill() events asynchronously)
await expect(notifications.saveButton).not.toBeDisabled();
// # Save setting
await notifications.save();
// * Verify that the config is correctly saved in the server
await expect
.poll(async () => {
const config = await adminClient.getConfig();
return config.SupportSettings?.SupportEmail;
})
.toBe(newEmail);
});
/**
* @objective Verify that the save button is disabled when mandatory fields are empty
*/
test('MM-41671 cannot save the notifications page if mandatory fields are missing', async ({pw}) => {
const {adminUser, adminClient} = await pw.getAdminClient();
if (!adminUser || !adminClient) {
throw new Error('Failed to get admin user');
}
// Ensure all required fields are populated before the test starts so that
// clearing one field at a time reliably disables the save button, and
// restoring it reliably re-enables it (no other empty field blocking save).
await resetNotificationsConfig(adminClient);
await waitForNotificationsServerPreconditions(adminClient);
// # Log in as admin
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit Notifications admin console page (direct URL — sidebar link can be off-screen in CI)
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
await systemConsolePage.gotoNotificationsSettings();
// # Wait for Notifications section to load
const notifications = systemConsolePage.notifications;
await notifications.toBeVisible();
const tests = [
{name: 'Support Email Address', field: notifications.supportEmailAddress},
{name: 'Notification Display Name', field: notifications.notificationDisplayName},
{name: 'Notification From Address', field: notifications.notificationFromAddress},
];
for (const testCase of tests) {
// # Clear the field
await testCase.field.toBeVisible();
await testCase.field.clear();
// Scope error check to this field's container to avoid strict-mode failure
// when other fields on the page also have validation errors simultaneously.
const fieldError = testCase.field.container.locator('.has-error');
// * Error message is shown and save button is disabled
await expect(fieldError).toHaveText(`"${testCase.name}" is required`);
await expect(notifications.saveButton).toBeDisabled();
// # Restore the field with a valid value so format-validation errors from
// this field don't interfere with the next iteration.
await testCase.field.fill('test@example.com');
// * Ensure error for this field is gone and save button is enabled
await expect(fieldError).toHaveCount(0);
await expect(notifications.saveButton).not.toBeDisabled();
}
});
});