-
Notifications
You must be signed in to change notification settings - Fork 1
/
token-e2e-test.js
332 lines (299 loc) · 12.4 KB
/
token-e2e-test.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// 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.
// ***************************************************************
import {getRandomId} from '../utils/index';
import {getAdminAccount} from '../support/env';
const sysadmin = getAdminAccount();
describe('Test AutoLink', function () {
let team1;
let team2;
let regularUser;
let channel1;
let linkName = `jira${getRandomId()}`;
before(() => {
cy.apiUpdateConfig({
PluginSettings: {
// # Enable the 'autolink' plugin and enable the admin account for it
PluginStates: {'mattermost-autolink': {Enable: true}},
Plugins: {'mattermost-autolink': {enableadmincommand: true}},
},
});
cy.apiInitSetup().then(({team, user, channel}) => {
team1 = team;
channel1 = channel;
regularUser = user;
cy.visit(`/${team1.name}/channels/town-square`);
});
cy.apiCreateTeam('test-team2', 'Test Team2').then(({team}) => {
team2 = team;
});
// # Install Plugin using API and enable admin commands
cy.apiInstallPluginFromUrl(
`https://github.com/mattermost/mattermost-plugin-autolink/releases/download/v1.2.0/mattermost-autolink-1.2.0.tar.gz`,
true,
);
});
beforeEach(() => {
cy.apiAdminLogin();
});
it('Autolink autocomple is working', function () {
//Ensure autilink slash commands are ebabeled
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type('/a');
cy.contains('autolink [command]');
cy.contains('autolink [command]').click();
});
it('Create link', function () {
// Add a link
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type('/a');
cy.contains('autolink [command]').click(); // correct locator - waiting on bug fix
cy.get('#post_textbox').type(`add ${linkName}`);
cy.get('#post_textbox').should('contain', `/autolink add ${linkName}`);
cy.get('#post_textbox');
cy.wait(250);
cy.get('#post_textbox').type('{enter}', {force: true});
cy.contains(`: ${linkName}`);
});
it('Add a template', function () {
//Add a template
cy.get('#post_textbox').clear();
cy.get('#post_textbox')
.should('be.focused')
.type(
`/autolink set ${linkName} ` +
'Template [MM-${{}jira_id{}}](https://mattermost.atlassian.net/browse/MM-${{}jira_id{}}){enter}',
);
cy.contains('Template: ');
cy.waitUntil(() => {
return cy.getLastPost().then((el) => {
return el.find('code');
});
});
cy.wait(250);
cy.getLastPost().within(() => {
cy.get('code').should(
'have.text',
'[MM-${jira_id}](https://mattermost.atlassian.net/browse/MM-${jira_id})',
);
});
});
it('Add a Pattern', function () {
// Add a patern
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type(`/autolink set ${linkName} Pattern (MM)(-)(?P<jira_id>\\d+){enter}`);
cy.contains('Pattern: ');
});
it('Pattern is applied', function () {
//Pattern is applied
cy.get('#post_textbox').clear;
cy.postMessage('MM-1234{enter}');
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://mattermost.atlassian.net/browse/MM-1234')
.and('have.text', 'MM-1234');
});
});
it('Add a Scope', function () {
// Add a scope
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type(`/autolink set ${linkName} Scope ${team1.name}{enter}`);
cy.contains('Scope: ');
cy.contains(`${team1.name}`);
});
it('Pattern applied in scope only', function () {
//pattern applied in Team
cy.get(`#${team1.name}TeamButton`).click();
cy.wait(500);
cy.get('#post_textbox').type('MM-1234');
cy.wait(1000);
cy.get('#post_textbox').type('{enter}');
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://mattermost.atlassian.net/browse/MM-1234')
.and('have.text', 'MM-1234');
});
//pattern NOT applied in Team
cy.get(`#${team2.name}TeamButton`).should('have.attr', 'href', `/${team2.name}`).click();
cy.get('#post_textbox').should('be.visible').clear(); //.should should resolve need for wait
cy.wait(500);
cy.postMessage('MM-1234');
cy.getLastPost().within(() => {
cy.get('p').should('have.text', 'MM-1234');
});
cy.get(`#${team1.name}TeamButton`).click();
cy.get('#post_textbox').should('be.focused');
});
it('Disable link ', function () {
//Confirm enabled state
cy.get(`#${team1.name}TeamButton`).click();
cy.wait(250);
cy.postMessage('MM-2222{enter}');
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://mattermost.atlassian.net/browse/MM-2222')
.and('have.text', 'MM-2222');
});
//Disable
cy.postMessage(`/autolink disable ${linkName}{enter}`);
cy.wait(1500);
cy.getLastPost().within((el) => {
console.log('look here');
console.log(el);
cy.get('del').should('have.text', linkName);
});
cy.wait(499);
cy.get('#post_textbox').clear();
cy.wait(250);
cy.get('#post_textbox').type('MM-2222{enter}');
cy.getLastPost().within(() => {
cy.get('p').should('have.text', 'MM-2222');
});
});
it('enable link ', function () {
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type(`/autolink enable ${linkName}{enter}`);
cy.contains(`: ${linkName}`);
cy.get('#post_textbox').clear();
cy.wait(250);
cy.get('#post_textbox').type('MM-2222{enter}');
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://mattermost.atlassian.net/browse/MM-2222')
.and('have.text', 'MM-2222');
});
});
it('Apply patterns on edit false by default', function () {
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type('NN-5678{enter}');
cy.wait(1000);
cy.get('#post_textbox').should('be.focused').type('{uparrow}');
cy.wait(250);
cy.get('#edit_textbox').should('be.focused').type('{home}{del}{del}MM{enter}');
cy.getLastPost().within(() => {
cy.get('p').should('have.text', 'MM-5678');
});
});
it('Apply patterns on edit true', function () {
// Update config
cy.apiUpdateConfig({
PluginSettings: {
PluginStates: {'mattermost-autolink': {Enable: true}},
Plugins: {
'mattermost-autolink': {enableadmincommand: true},
'mattermost-autolink': {enableonupdate: true},
},
},
});
cy.visit(`/${team1.name}/channels/town-square`);
//Ensure pattern is applied on edit
cy.get('#post_textbox').clear();
cy.get('#post_textbox').type('NN-5678{enter}');
cy.wait(1000);
cy.get('#post_textbox').type('{uparrow}');
cy.wait(250);
cy.get('#edit_textbox').type('{home}{del}{del}MM{enter}');
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://mattermost.atlassian.net/browse/MM-5678')
.and('have.text', 'MM-5678');
});
});
it('Non sysadmin can not use slash commands', function () {
cy.apiLogin(regularUser);
cy.visit(`/${team1.name}/channels/town-square`);
// Ensure autolink commands are non functinal
cy.postMessage('/autolink list {enter}');
cy.uiWaitUntilMessagePostedIncludes(` commands can only be executed by a system administrator or `);
cy.getLastPost().within(() => {
cy.contains(` commands can only be executed by a system administrator or `);
});
cy.postMessage('/autolink add pickles{enter}');
cy.wait(1000);
cy.uiWaitUntilMessagePostedIncludes(` commands can only be executed by a system administrator or `);
cy.getLastPost().within(() => {
cy.contains(` commands can only be executed by a system administrator or `);
});
});
it('User added as plugin admin', function () {
cy.apiUpdateConfig({
PluginSettings: {
PluginStates: {'mattermost-autolink': {Enable: true}},
Plugins: {
'mattermost-autolink': {enableadmincommand: true},
'mattermost-autolink': {enableonupdate: true},
'mattermost-autolink': {pluginadmins: regularUser.id},
},
},
});
cy.apiLogin(regularUser);
cy.visit(`/${team1.name}/channels/town-square`);
cy.get('#post_textbox').should('be.visible');
cy.wait(250);
cy.postMessage('/autolink list {enter}');
cy.postMessage('{enter}');
cy.get('#post_textbox').should('be.visible');
cy.getLastPost().within(() => {
cy.contains(`: ${linkName}`);
});
cy.postMessage(`/autolink disable ${linkName}{enter}`);
cy.wait(1500);
cy.getLastPost().within((el) => {
console.log('look here');
console.log(el);
cy.get('del').should('have.text', linkName);
});
});
it('Common links work', function () {
//ESR Link
let esrLinkName = `ESR${getRandomId()}`;
cy.postMessage(`/autolink add ${esrLinkName}`);
cy.postMessage(`/autolink set ${esrLinkName} Pattern ESR`);
cy.postMessage(
`/autolink set ${esrLinkName} Template [ESR](https://docs.mattermost.com/prcess/traing.html#rhs)`,
);
cy.postMessage(`A post with ESR link?`);
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://docs.mattermost.com/prcess/traing.html#rhs')
.and('have.text', 'ESR');
});
//GitHub Link
let gitLinkName = `GitHub${getRandomId()}`;
cy.postMessage(`/autolink add ${gitLinkName}`);
cy.postMessage(
`/autolink set ${gitLinkName} ` + 'Pattern https://github\\.com/mattermost/(?P<repo>.+)/pull/(?P<id>\\d+)',
);
cy.postMessage(
`/autolink set ${gitLinkName} ` +
'Template [pr-${{}repo{}}-${{}id{}}](https://github.com/mattermost/${{}repo{}}/pull/${{}id{}})',
);
cy.postMessage(`https://github.com/mattermost/mattermost-server/pull/14756`);
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.should('have.attr', 'href', 'https://github.com/mattermost/mattermost-server/pull/14756')
.and('have.text', 'pr-mattermost-server-14756');
});
});
it('Mutiple GitHub links', function () {
cy.postMessage(
'https://github.com/mattermost/mattermost-webapp/pull/2859 and https://github.com/mattermost/mattermost-webapp/pull/2858',
);
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.eq(0)
.should('have.attr', 'href', 'https://github.com/mattermost/mattermost-webapp/pull/2859')
.and('have.text', 'pr-mattermost-webapp-2859');
});
cy.getLastPost().within(() => {
cy.get('.theme.markdown__link')
.eq(1)
.should('have.attr', 'href', 'https://github.com/mattermost/mattermost-webapp/pull/2858')
.and('have.text', 'pr-mattermost-webapp-2858');
});
});
});