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
315 lines
12 KiB
JavaScript
315 lines
12 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
// ***************************************************************
|
|
// - [#] indicates a test step (e.g. # Go to a page)
|
|
// - [*] indicates an assertion (e.g. * Check the title)
|
|
// - Use element ID when selecting an element. Create one if none.
|
|
// ***************************************************************
|
|
|
|
// Stage: @prod
|
|
// Group: @channels @notification
|
|
|
|
import {getAdminAccount} from '@/support/env';
|
|
import {spyNotificationAs} from '@/support/notification';
|
|
|
|
describe('Notifications', () => {
|
|
const admin = getAdminAccount();
|
|
let testTeam;
|
|
let testChannel;
|
|
let otherChannel;
|
|
let receiver;
|
|
let sender;
|
|
|
|
before(() => {
|
|
cy.apiInitSetup({userPrefix: 'receiver'}).then(({team, channel, user}) => {
|
|
testTeam = team;
|
|
testChannel = channel;
|
|
receiver = user;
|
|
return cy.apiCreateChannel(team.id, 'test', 'Test');
|
|
}).then(({channel}) => {
|
|
otherChannel = channel;
|
|
return cy.apiCreateUser({prefix: 'sender'});
|
|
}).then(({user}) => {
|
|
sender = user;
|
|
return cy.apiAddUserToTeam(testTeam.id, sender.id);
|
|
}).then(() => {
|
|
cy.apiAddUserToChannel(testChannel.id, sender.id);
|
|
cy.apiAddUserToChannel(otherChannel.id, sender.id);
|
|
return cy.apiAddUserToChannel(otherChannel.id, receiver.id);
|
|
}).then(() => {
|
|
cy.apiLogin(receiver);
|
|
});
|
|
});
|
|
|
|
beforeEach(() => {
|
|
// # Login as receiver and visit off-topic channel
|
|
cy.apiLogin(receiver);
|
|
markChannelRead(testChannel.id);
|
|
markChannelRead(otherChannel.id);
|
|
cy.visit(`/${testTeam.name}/channels/off-topic`);
|
|
cy.get('#channelHeaderDropdownButton').should('be.visible');
|
|
|
|
// * Verify unread mention badges are cleared
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).find('#unreadMentions').should('not.exist');
|
|
cy.get(`#sidebarItem_${testChannel.name}`).find('#unreadMentions').should('not.exist');
|
|
});
|
|
|
|
it('MM-T547 still triggers notification if username is not listed in words that trigger mentions', () => {
|
|
// # Set Notification settings
|
|
setNotificationSettings({first: false, username: true, shouts: true, custom: true}, 'off-topic');
|
|
|
|
const message = `@${receiver.username} I'm messaging you! ${Date.now()}`;
|
|
|
|
// # Use another account to post a message @-mentioning our receiver
|
|
cy.postMessageAs({sender, message, channelId: otherChannel.id}).then(({id: postId}) => {
|
|
const body = `@${sender.username}: ${message}`;
|
|
|
|
cy.get('@notifySpy').should('have.been.calledWithMatch', otherChannel.display_name, (args) => {
|
|
expect(args.body, `Notification body: "${args.body}" should match: "${body}"`).to.equal(body);
|
|
expect(args.tag, `Notification tag: "${args.tag}" should match the post id`).to.equal(postId);
|
|
expect(args.tag, `Notification tag: "${args.tag}" should not contain notification text`).not.to.equal(body);
|
|
return true;
|
|
});
|
|
|
|
cy.get('@notifySpy').should('have.been.calledWithMatch',
|
|
otherChannel.display_name, {body, tag: postId, requireInteraction: false, silent: false});
|
|
});
|
|
|
|
// * Verify unread mentions badge
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).
|
|
scrollIntoView().
|
|
find('#unreadMentions').
|
|
should('be.visible').
|
|
and('have.text', '1');
|
|
|
|
// * Go to that channel
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).click({force: true});
|
|
|
|
// # Get last post message text
|
|
cy.getLastPostId().then((postId) => {
|
|
cy.get(`#postMessageText_${postId}`).as('postMessageText');
|
|
});
|
|
|
|
// * Verify entire message
|
|
cy.get('@postMessageText').
|
|
should('be.visible').
|
|
and('have.text', message);
|
|
|
|
// * Verify highlight of username
|
|
cy.get('@postMessageText').
|
|
find(`[data-mention=${receiver.username}]`).
|
|
should('be.visible').
|
|
and('have.text', `@${receiver.username}`);
|
|
});
|
|
|
|
it('MM-T545 does not trigger notifications with "Your non case-sensitive username" unchecked', () => {
|
|
// # Set Notification settings
|
|
setNotificationSettings({first: false, username: false, shouts: true, custom: true}, 'off-topic');
|
|
|
|
const message = `Hey ${receiver.username}! I'm messaging you! ${Date.now()}`;
|
|
|
|
// # Use another account to post a message @-mentioning our receiver
|
|
cy.postMessageAs({sender, message, channelId: otherChannel.id});
|
|
|
|
// * Verify stub was not called
|
|
cy.get('@notifySpy').should('be.not.called');
|
|
|
|
// * Verify unread mentions badge does not exist
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).
|
|
scrollIntoView().
|
|
find('#unreadMentions').
|
|
should('not.exist');
|
|
|
|
// # Go to the channel where you were messaged
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).click({force: true});
|
|
|
|
// # Get last post message text
|
|
cy.getLastPostId().then((postId) => {
|
|
cy.get(`#postMessageText_${postId}`).as('postMessageText');
|
|
});
|
|
|
|
// * Verify message contents
|
|
cy.get('@postMessageText').
|
|
should('be.visible').
|
|
and('have.text', message);
|
|
|
|
// * Verify it's not highlighted
|
|
cy.get('@postMessageText').
|
|
find(`[data-mention=${receiver.username}]`).
|
|
should('not.exist');
|
|
});
|
|
|
|
it('MM-T548 does not trigger notifications with "channel-wide mentions" unchecked', () => {
|
|
// # Set Notification settings
|
|
setNotificationSettings({first: false, username: false, shouts: false, custom: true}, 'off-topic');
|
|
|
|
const channelMentions = ['@here', '@all', '@channel'];
|
|
|
|
channelMentions.forEach((mention) => {
|
|
const message = `Hey ${mention} I'm message you all! ${Date.now()}`;
|
|
|
|
// # Use another account to post a message @-mentioning our receiver
|
|
cy.postMessageAs({sender, message, channelId: otherChannel.id});
|
|
|
|
// * Verify stub was not called
|
|
cy.get('@notifySpy').should('be.not.called');
|
|
|
|
// * Verify unread mentions badge does not exist
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).
|
|
find('#unreadMentions').
|
|
should('not.exist');
|
|
|
|
// # Go to the channel where you were messaged
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).click({force: true});
|
|
|
|
// # Get last post message text
|
|
cy.getLastPostId().then((postId) => {
|
|
cy.get(`#postMessageText_${postId}`).as('postMessageText');
|
|
});
|
|
|
|
// * Verify message contents
|
|
cy.get('@postMessageText').
|
|
should('be.visible').
|
|
and('have.text', message);
|
|
|
|
// * Verify it's not highlighted
|
|
cy.get('@postMessageText').
|
|
find(`[data-mention=${receiver.username}]`).
|
|
should('not.exist');
|
|
});
|
|
});
|
|
|
|
it('MM-T184 Words that trigger mentions support Chinese', () => {
|
|
const customText = '番茄';
|
|
|
|
// # Set Notification settings
|
|
setNotificationSettings({first: false, username: false, shouts: false, custom: true, customText}, 'off-topic');
|
|
const message = '番茄 I\'m messaging you!';
|
|
const message2 = '我爱吃番茄炒饭 I\'m messaging you!';
|
|
|
|
// # Use another account to post a message @-mentioning our receiver
|
|
cy.postMessageAs({sender, message, channelId: otherChannel.id});
|
|
|
|
// # Check mention on other channel
|
|
// * Verify unread mentions badge
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).
|
|
scrollIntoView().
|
|
find('#unreadMentions').
|
|
should('be.visible').
|
|
and('have.text', '1');
|
|
|
|
// * Go to that channel
|
|
cy.get(`#sidebarItem_${otherChannel.name}`).click({force: true});
|
|
|
|
// # Get last post message text
|
|
cy.getLastPostId().then((postId) => {
|
|
cy.get(`#postMessageText_${postId}`).as('postMessageText');
|
|
});
|
|
|
|
// * Verify entire message
|
|
cy.get('@postMessageText').
|
|
should('be.visible').
|
|
and('have.text', message);
|
|
|
|
// * Verify highlight of username
|
|
cy.get('@postMessageText').
|
|
find('.mention--highlight').
|
|
should('be.visible').
|
|
and('have.text', '番茄');
|
|
|
|
// # Check mention on test channel
|
|
cy.postMessageAs({sender: admin, message: message2, channelId: testChannel.id});
|
|
|
|
// * Verify unread mentions badge
|
|
cy.get(`#sidebarItem_${testChannel.name}`).
|
|
scrollIntoView().
|
|
find('#unreadMentions').
|
|
should('be.visible').
|
|
and('have.text', '1');
|
|
|
|
// * Go to that channel
|
|
cy.get(`#sidebarItem_${testChannel.name}`).click({force: true});
|
|
|
|
// # Get last post message text
|
|
cy.getLastPostId().then((postId) => {
|
|
cy.get(`#postMessageText_${postId}`).as('postMessageText');
|
|
});
|
|
|
|
// * Verify entire message
|
|
cy.get('@postMessageText').
|
|
should('be.visible').
|
|
and('have.text', message2);
|
|
|
|
// * Verify highlight of username
|
|
cy.get('@postMessageText').
|
|
find('.mention--highlight').
|
|
should('be.visible').
|
|
and('have.text', '番茄');
|
|
});
|
|
});
|
|
|
|
function markChannelRead(channelId) {
|
|
cy.request({
|
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
url: '/api/v4/channels/members/me/view',
|
|
method: 'POST',
|
|
body: {channel_id: channelId, collapsed_threads_supported: true},
|
|
});
|
|
}
|
|
|
|
function setNotificationSettings(desiredSettings = {first: true, username: true, shouts: true, custom: true, customText: '@'}, channelName) {
|
|
// # Navigate to settings modal
|
|
cy.uiOpenSettingsModal();
|
|
|
|
// # Click on notifications tab
|
|
cy.findByRoleExtended('tab', {name: 'Notifications'}).
|
|
should('be.visible').
|
|
click();
|
|
|
|
// * Notifications header should be visible
|
|
cy.findAllByText('Notifications').should('be.visible');
|
|
|
|
// # Open up 'Words that trigger mentions' sub-section
|
|
cy.findByText('Keywords that trigger notifications').
|
|
scrollIntoView().
|
|
click();
|
|
|
|
const settings = [
|
|
{key: 'first', selector: '#notificationTriggerFirst'},
|
|
{key: 'username', selector: '#notificationTriggerUsername'},
|
|
{key: 'shouts', selector: '#notificationTriggerShouts'},
|
|
{key: 'custom', selector: '#notificationTriggerCustom'},
|
|
];
|
|
|
|
// # Set check boxes to desired state
|
|
settings.forEach((setting) => {
|
|
const checkbox = desiredSettings[setting.key] ? {state: 'check', verify: 'be.checked'} : {state: 'uncheck', verify: 'not.be.checked'};
|
|
cy.get(setting.selector)[checkbox.state]().should(checkbox.verify);
|
|
});
|
|
|
|
// # Set Custom field
|
|
if (desiredSettings.custom && desiredSettings.customText) {
|
|
cy.get('#notificationTriggerCustomText').
|
|
type(desiredSettings.customText, {force: true}).
|
|
tab();
|
|
}
|
|
|
|
// # Click “Save” and close modal
|
|
cy.uiSaveAndClose();
|
|
|
|
cy.apiGetMe().then(({user}) => {
|
|
const props = user.notify_props || {};
|
|
expect(props.first_name).to.equal(desiredSettings.first ? 'true' : 'false');
|
|
expect(props.channel).to.equal(desiredSettings.shouts ? 'true' : 'false');
|
|
});
|
|
|
|
// # Navigate to a channel we are NOT going to post to
|
|
cy.get(`#sidebarItem_${channelName}`).scrollIntoView().click({force: true});
|
|
cy.get('#loadingSpinner').should('not.exist');
|
|
cy.get('#channelHeaderDropdownButton').should('be.visible');
|
|
|
|
// # Setup notification spy
|
|
spyNotificationAs('notifySpy', 'granted');
|
|
}
|