forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_links_show_as_links_spec.js
121 lines (94 loc) · 5.01 KB
/
channel_links_show_as_links_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// 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.
// ***************************************************************
// Group: @notifications
import * as TIMEOUTS from '../../fixtures/timeouts';
import {getEmailUrl, getEmailMessageSeparator, reUrl} from '../../utils';
const baseUrl = Cypress.config('baseUrl');
const mailUrl = getEmailUrl(baseUrl);
describe('Notifications', () => {
let testTeam;
let otherUser;
let lastPostId;
const channelName = 'off-topic';
before(() => {
cy.apiEmailTest();
cy.apiInitSetup().then(({team}) => {
testTeam = team;
cy.apiCreateUser().then(({user}) => {
otherUser = user;
cy.apiAddUserToTeam(testTeam.id, otherUser.id);
cy.apiLogin(otherUser);
});
// # As otherUser, set status to offline and logout
cy.visit(`/${testTeam.name}/channels/off-topic`);
cy.findByLabelText('set status').should('be.visible').click();
cy.findByText('Offline').should('be.visible').click();
cy.apiLogout();
// # Login as sysadmin and go to the Off-Topic channel
cy.apiAdminLogin();
cy.visit(`/${testTeam.name}/channels/off-topic`);
});
});
it('MM-T506 Channel links show as links in notification emails', () => {
// # Open 'Account Settings' modal
cy.findByLabelText('main menu').should('be.visible').click();
cy.findByText('Account Settings').should('be.visible').click();
// * Check that the 'Account Settings' modal was opened
cy.get('#accountSettingsModal').should('exist').within(() => {
cy.get('#notificationsButton').should('be.visible').click();
// * Verify that 'Email Notifications' is set to 'Immediately'
cy.get('#emailDesc').should('be.visible').within(() => {
cy.findByText('Immediately').should('be.visible');
});
// # Close the modal
cy.get('#accountSettingsHeader').find('button').should('be.visible').click();
});
// # Post a message as sysadmin that contains the channel name and otherUser's username
cy.postMessage(`This is a message in ~${channelName} channel for @${otherUser.username}`);
cy.getLastPostId().then((postId) => {
lastPostId = postId;
});
// # Logout from sysadmin account and login as otherUser
cy.apiLogout();
cy.apiLogin(otherUser);
cy.task('getRecentEmail', {username: otherUser.username, mailUrl}).then((response) => {
const messageSeparator = getEmailMessageSeparator(baseUrl);
const bodyText = response.data.body.text.split('\n');
// * Verify that the email was properly received and has the correct output
verifyEmailNotification(response, testTeam, testTeam.display_name, otherUser.email, messageSeparator);
const permalink = bodyText[9].match(reUrl)[0];
// # Visit permalink (e.g. click on email link)
cy.visit(permalink);
// # Choose the 'View in Browser' option
cy.findByText('View in Browser', {timeout: TIMEOUTS.HALF_MIN}).click();
// * Verify that the post message that otherUser was notified of in the email is visible
cy.get(`#postMessageText_${lastPostId}`, {timeout: TIMEOUTS.HALF_MIN}).should('be.visible');
});
});
const verifyEmailNotification = (response, teamName, teamDisplayName, email, messageSeparator) => {
const isoDate = new Date().toISOString().substring(0, 10);
const {data, status} = response;
// * Should return success status
expect(status).to.equal(200);
// * Verify that email is addressed to the correct user
expect(data.to.length).to.equal(1);
expect(data.to[0]).to.contain(email);
// * Verify that date is current
expect(data.date).to.contain(isoDate);
// * Verify that the email subject is correct
expect(data.subject).to.contain(`[Mattermost] Notification in ${testTeam.display_name}`);
// * Verify that the email body is correct
const bodyText = data.body.text.split(messageSeparator);
expect(bodyText.length).to.equal(16);
expect(bodyText[1]).to.equal('You have a new notification.');
expect(bodyText[4]).to.equal('Channel: Off-Topic');
expect(bodyText[5]).to.contain('@sysadmin');
expect(bodyText[7]).to.equal(`This is a message in ~${channelName} ( ${baseUrl}/landing#/${testTeam.name}/channels/${channelName} ) channel for @${otherUser.username}`);
expect(bodyText[9]).to.equal(`Go To Post ( ${baseUrl}/landing#/${testTeam.name}/pl/${lastPostId} )`);
};
});