@webship-js/redmine-steps 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +234 -2
- package/package.json +64 -4
- package/tests/features/issues.feature +36 -0
- package/tests/features/roles.feature +16 -0
- package/tests/features/session.feature +24 -0
- package/tests/features/versions.feature +12 -0
- package/tests/step-definitions/redmine-helpers.js +470 -0
- package/tests/step-definitions/redmine-issues.steps.js +398 -0
- package/tests/step-definitions/redmine-session.steps.js +225 -0
- package/tests/step-definitions/redmine-versions.steps.js +99 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Issue step definitions: the test content a scenario makes and removes (through the site's REST API, as the managing
|
|
4
|
+
// account), the issue list, one issue and what a person changes on it through its update form (its status through the
|
|
5
|
+
// workflow, a note, the time spent, its assignee), a new issue made through the form, and what an account may not do
|
|
6
|
+
// (a Reporter's status and assignee).
|
|
7
|
+
//
|
|
8
|
+
// What a scenario makes goes after it: the issues a Given step made and the ones a scenario created through the form
|
|
9
|
+
// are removed, with their notes and the time spent on them, as the managing account, so a run leaves the site as it
|
|
10
|
+
// found it. Name test content "Webship test …": `cmd-tools-redmine-cli.sh <site> --tidy` removes what a stopped run left.
|
|
11
|
+
|
|
12
|
+
const { Given, When, Then, After, AfterAll } = require('@cucumber/cucumber');
|
|
13
|
+
const { smartSettle, friendly } = require('webship-js/tests/step-definitions/webship');
|
|
14
|
+
const {
|
|
15
|
+
budget,
|
|
16
|
+
exactly,
|
|
17
|
+
tidy,
|
|
18
|
+
open,
|
|
19
|
+
actOrExplain,
|
|
20
|
+
assertPresence,
|
|
21
|
+
waitForValue,
|
|
22
|
+
findProject,
|
|
23
|
+
findIssues,
|
|
24
|
+
issueNamed,
|
|
25
|
+
remember,
|
|
26
|
+
removeIssue,
|
|
27
|
+
makeIssue,
|
|
28
|
+
managerContexts,
|
|
29
|
+
} = require('./redmine-helpers');
|
|
30
|
+
|
|
31
|
+
/** The project a step names, else the last one a scenario used, else the one of cucumber.js. */
|
|
32
|
+
async function projectOf(world, which) {
|
|
33
|
+
const project = await findProject(world, which || (world.redmine && world.redmine.project));
|
|
34
|
+
world.redmine = Object.assign(world.redmine || {}, { project: project.identifier });
|
|
35
|
+
return project;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The issue page on screen: its id, from the address, or a friendly error. */
|
|
39
|
+
function openIssue(world) {
|
|
40
|
+
const m = world.page.url().match(/\/issues\/(\d+)/);
|
|
41
|
+
if (!m) throw friendly({ message: `No issue is open (the page is ${world.page.url()}).`, hint: 'Open one first with When I open the issue "…".' });
|
|
42
|
+
return m[1];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** An attribute the open issue shows ("status", "assigned-to", "spent-time"), as text; '' when it shows none. */
|
|
46
|
+
async function attribute(world, name) {
|
|
47
|
+
return tidy(await world.page.locator(`.issue .${name}.attribute .value`).first().innerText({ timeout: 2000 }).catch(() => ''));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Change the open issue through its update form ("Edit", then the form's fields, then "Submit"), and wait for the
|
|
52
|
+
* site's answer. `fill` sets the fields; a refused update throws with what the site said.
|
|
53
|
+
*/
|
|
54
|
+
async function update(world, label, target, fill, hint) {
|
|
55
|
+
const id = openIssue(world);
|
|
56
|
+
await actOrExplain(label, target, async () => {
|
|
57
|
+
await world.page.locator(`a.icon-edit[href$="/issues/${id}/edit"]`).first().click({ timeout: budget(world) });
|
|
58
|
+
await world.page.locator('#update').waitFor({ state: 'visible', timeout: budget(world) });
|
|
59
|
+
await fill(world.page.locator('#issue-form'));
|
|
60
|
+
await world.page.locator('#issue-form [type="submit"][name="commit"]').first().click();
|
|
61
|
+
}, hint);
|
|
62
|
+
const answer = world.page.locator('#flash_notice, #errorExplanation').first();
|
|
63
|
+
await answer.waitFor({ state: 'visible', timeout: budget(world) }).catch(() => {});
|
|
64
|
+
const error = tidy(await world.page.locator('#errorExplanation').first().innerText({ timeout: 500 }).catch(() => ''));
|
|
65
|
+
if (error) throw friendly({ message: `The site refused to ${label} "${target}": ${error}`, hint });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Test content
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Make an issue through the site's REST API as the managing account, in the project's first tracker and default
|
|
74
|
+
* status; one of the subject left by a stopped run goes first. It goes again after the scenario.
|
|
75
|
+
*
|
|
76
|
+
* Example #1: Given there is an issue "Webship test task" in the project "webship-site"
|
|
77
|
+
* Example #2: Given there is an issue "Webship test note" in the project "Webship site"
|
|
78
|
+
* Example #3: And there is an issue "Webship test status"
|
|
79
|
+
* Example #4: Given there is an issue "Webship test time" in the project "webship-site"
|
|
80
|
+
* Example #5: Given there is an issue "Webship test assignee"
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
Given(/^there is an issue "([^"]*)"(?: in the project "([^"]*)")?$/, async function (subject, which) {
|
|
84
|
+
const project = await projectOf(this, which);
|
|
85
|
+
for (const old of await findIssues(this, project, subject)) await removeIssue(this, old.id);
|
|
86
|
+
await makeIssue(this, project, subject);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Make sure no issue of the subject is in the project: one there is removed with its notes and its time, as the
|
|
91
|
+
* managing account.
|
|
92
|
+
*
|
|
93
|
+
* Example #1: Given there is no issue "Webship test new" in the project "webship-site"
|
|
94
|
+
* Example #2: Given there is no issue "Webship test new" in the project "Webship site"
|
|
95
|
+
* Example #3: And there is no issue "Webship test task"
|
|
96
|
+
* Example #4: Given there is no issue "Webship test created"
|
|
97
|
+
* Example #5: Then there is no issue "Webship test new" in the project "webship-site"
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
Given(/^there is no issue "([^"]*)"(?: in the project "([^"]*)")?$/, async function (subject, which) {
|
|
101
|
+
const project = await projectOf(this, which);
|
|
102
|
+
for (const old of await findIssues(this, project, subject)) await removeIssue(this, old.id);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// The list and one issue
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Open the issue list of a project (its default query: the open issues).
|
|
111
|
+
*
|
|
112
|
+
* Example #1: When I open the issues of the project "webship-site"
|
|
113
|
+
* Example #2: When I open the issues of the project "Webship site"
|
|
114
|
+
* Example #3: And we open the issues of the project "webship-site"
|
|
115
|
+
* Example #4: Given I open the issues of the project "webship-site"
|
|
116
|
+
* Example #5: When open the issues of the project "Webship site"
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
When(/^(I |we )*open the issues of the project "([^"]*)"$/, async function (pronounCase, which) {
|
|
120
|
+
const project = await projectOf(this, which);
|
|
121
|
+
await open(this, `/projects/${project.identifier}/issues`);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Assert that the issue list on screen shows (or does not show) a row of the subject.
|
|
126
|
+
*
|
|
127
|
+
* Example #1: Then the issue list should show "Webship test task"
|
|
128
|
+
* Example #2: Then the issue list should not show "Webship test task"
|
|
129
|
+
* Example #3: And the issue list should show "The greeting script says Helo instead of Hello"
|
|
130
|
+
* Example #4: But the issue list should not show "Webship test closed"
|
|
131
|
+
* Example #5: Then the issue list should show "Webship test new"
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
Then(/^the issue list should (not )?show "([^"]*)"$/, async function (notCase, subject) {
|
|
135
|
+
await assertPresence(this.page.locator('table.issues tr.issue td.subject').filter({ hasText: exactly(subject) }), notCase, {
|
|
136
|
+
label: `the issue "${subject}" in the list`,
|
|
137
|
+
hint: notCase ? 'The list shows the open issues: a closed one leaves it.' : 'The list shows the open issues of the project the session may see; open it first with When I open the issues of the project "…".',
|
|
138
|
+
timeout: budget(this),
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Open an issue by its subject, in the project the scenario works in.
|
|
144
|
+
*
|
|
145
|
+
* Example #1: When I open the issue "Webship test task"
|
|
146
|
+
* Example #2: When I open the issue "The greeting script says Helo instead of Hello"
|
|
147
|
+
* Example #3: And we open the issue "Webship test note"
|
|
148
|
+
* Example #4: Given I open the issue "Webship test status"
|
|
149
|
+
* Example #5: When open the issue "Webship test time"
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
152
|
+
When(/^(I |we )*open the issue "([^"]*)"$/, async function (pronounCase, subject) {
|
|
153
|
+
const issue = await issueNamed(this, subject);
|
|
154
|
+
await open(this, `/issues/${issue.id}`);
|
|
155
|
+
await assertPresence(this.page.locator('.issue .subject h3').filter({ hasText: subject }), null, {
|
|
156
|
+
label: `the issue "${subject}"`,
|
|
157
|
+
hint: 'The account of the session must see the project of the issue.',
|
|
158
|
+
timeout: budget(this),
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create an issue through the form of a project (its default tracker), and wait until it is created. It goes again
|
|
164
|
+
* after the scenario.
|
|
165
|
+
*
|
|
166
|
+
* Example #1: When I create an issue "Webship test new" in the project "webship-site"
|
|
167
|
+
* Example #2: When I create an issue "Webship test new" in the project "Webship site"
|
|
168
|
+
* Example #3: And we create an issue "Webship test created"
|
|
169
|
+
* Example #4: When I create an issue "Webship test new"
|
|
170
|
+
* Example #5: Then I create an issue "Webship test created" in the project "webship-site"
|
|
171
|
+
*
|
|
172
|
+
*/
|
|
173
|
+
When(/^(I |we )*create an issue "([^"]*)"(?: in the project "([^"]*)")?$/, async function (pronounCase, subject, which) {
|
|
174
|
+
const project = await projectOf(this, which);
|
|
175
|
+
await open(this, `/projects/${project.identifier}/issues/new`);
|
|
176
|
+
await actOrExplain('create the issue', subject, async () => {
|
|
177
|
+
await this.page.locator('#issue_subject').waitFor({ state: 'visible', timeout: budget(this) });
|
|
178
|
+
await this.page.locator('#issue_subject').fill(subject);
|
|
179
|
+
await this.page.locator('#issue-form [type="submit"][name="commit"]').first().click();
|
|
180
|
+
await this.page.waitForURL(/\/issues\/\d+(?:$|[?#])/, { timeout: budget(this) });
|
|
181
|
+
}, 'The form of a new issue (its subject, and Create) shows to an account that may add issues in the project.');
|
|
182
|
+
remember(this, openIssue(this));
|
|
183
|
+
await smartSettle(this.page, 1000);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// What a person changes on the open issue
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Move the open issue to a status through its update form (the statuses the workflow of the account's role allows).
|
|
192
|
+
*
|
|
193
|
+
* Example #1: When I set the status of the issue to "In Progress"
|
|
194
|
+
* Example #2: When I set the status of the issue to "Closed"
|
|
195
|
+
* Example #3: And we set the status of the issue to "Resolved"
|
|
196
|
+
* Example #4: When I set the status of the issue to "Feedback"
|
|
197
|
+
* Example #5: Then I set the status of the issue to "New"
|
|
198
|
+
*
|
|
199
|
+
*/
|
|
200
|
+
When(/^(I |we )*set the status of the issue to "([^"]*)"$/, async function (pronounCase, status) {
|
|
201
|
+
await update(this, 'set the status to', status, async (form) => {
|
|
202
|
+
await form.locator('#issue_status_id').selectOption({ label: status }, { timeout: budget(this) });
|
|
203
|
+
}, 'The status list of the update form offers the statuses the workflow allows the account\'s role from the issue\'s status.');
|
|
204
|
+
const result = await waitForValue(() => attribute(this, 'status'), (shown) => exactly(status).test(shown), budget(this));
|
|
205
|
+
if (!result.ok) throw friendly({ message: `The status did not become "${status}": it shows "${result.value}".`, hint: 'The site may have refused the move.' });
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Assert the status the open issue shows.
|
|
210
|
+
*
|
|
211
|
+
* Example #1: Then the status of the issue should be "In Progress"
|
|
212
|
+
* Example #2: Then the status of the issue should be "New"
|
|
213
|
+
* Example #3: And the status of the issue should be "Closed"
|
|
214
|
+
* Example #4: But the status of the issue should be "Feedback"
|
|
215
|
+
* Example #5: Then the status of the issue should be "Resolved"
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
Then(/^the status of the issue should be "([^"]*)"$/, async function (status) {
|
|
219
|
+
openIssue(this);
|
|
220
|
+
const result = await waitForValue(() => attribute(this, 'status'), (shown) => exactly(status).test(shown), budget(this));
|
|
221
|
+
if (!result.ok) throw friendly({ message: `Expected the status "${status}", but the issue shows "${result.value}".`, hint: 'The status is among the attributes at the top of the issue.' });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Add a note to the open issue through its update form, and wait until its history lists it.
|
|
226
|
+
*
|
|
227
|
+
* Example #1: When I add the note "Checked on the test site" to the issue
|
|
228
|
+
* Example #2: When I add the note "Webship test note" to the issue
|
|
229
|
+
* Example #3: And we add the note "Ready for a review" to the issue
|
|
230
|
+
* Example #4: When I add the note "Done" to the issue
|
|
231
|
+
* Example #5: Then I add the note "Webship test reply" to the issue
|
|
232
|
+
*
|
|
233
|
+
*/
|
|
234
|
+
When(/^(I |we )*add the note "([^"]*)" to the issue$/, async function (pronounCase, text) {
|
|
235
|
+
await update(this, 'add the note', text, async (form) => {
|
|
236
|
+
await form.locator('#issue_notes').fill(text);
|
|
237
|
+
}, 'The update form has a notes box for an account that may add notes to the issue.');
|
|
238
|
+
await assertPresence(this.page.locator('#history .journal.has-notes .wiki').filter({ hasText: text }), null, {
|
|
239
|
+
label: `the note "${text}"`,
|
|
240
|
+
hint: 'The note was sent but is not in the history: the site may have refused it.',
|
|
241
|
+
timeout: budget(this),
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Assert that the history of the open issue lists a note holding the text, written by an account when it names one
|
|
247
|
+
* (its name as the site shows it).
|
|
248
|
+
*
|
|
249
|
+
* Example #1: Then the issue should show the note "Checked on the test site"
|
|
250
|
+
* Example #2: Then the issue should show the note "Checked on the test site" by "Member Test"
|
|
251
|
+
* Example #3: And the issue should show the note "The script is in the project's repository"
|
|
252
|
+
* Example #4: Then the issue should show the note "Ready for a review" by "Owner Test"
|
|
253
|
+
* Example #5: But the issue should show the note "Done"
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
Then(/^the issue should show the note "([^"]*)"(?: by "([^"]*)")?$/, async function (text, author) {
|
|
257
|
+
openIssue(this);
|
|
258
|
+
const journal = this.page.locator('#history .journal.has-notes').filter({ has: this.page.locator('.wiki', { hasText: text }) });
|
|
259
|
+
await assertPresence(journal, null, { label: `the note "${text}"`, hint: 'The notes are in the history of the issue (open it with When I open the issue "…").', timeout: budget(this) });
|
|
260
|
+
if (!author) return;
|
|
261
|
+
const head = tidy(await journal.first().locator('h4').first().innerText({ timeout: 2000 }).catch(() => ''));
|
|
262
|
+
if (!head.toLowerCase().includes(author.toLowerCase())) throw friendly({ message: `Expected the note "${text}" to be by ${author}, but its heading says "${head}".`, hint: 'Give the name the site shows for the account ("Member Test").' });
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Log time on the open issue through its update form: the hours ("0.5", "1", "1:30"), the site's first activity, and a
|
|
267
|
+
* comment when the step gives one. The day is today.
|
|
268
|
+
*
|
|
269
|
+
* Example #1: When I log "0.5" hours on the issue
|
|
270
|
+
* Example #2: When I log "1" hours on the issue with the comment "Read the code"
|
|
271
|
+
* Example #3: And we log "2" hours on the issue
|
|
272
|
+
* Example #4: When I log "1.25" hours on the issue with the comment "Webship test time"
|
|
273
|
+
* Example #5: Then I log "0.5" hours on the issue
|
|
274
|
+
*
|
|
275
|
+
*/
|
|
276
|
+
When(/^(I |we )*log "([^"]*)" hours on the issue(?: with the comment "([^"]*)")?$/, async function (pronounCase, hours, comment) {
|
|
277
|
+
await update(this, 'log time', `${hours} hours`, async (form) => {
|
|
278
|
+
await form.locator('#time_entry_hours').fill(hours);
|
|
279
|
+
const activity = form.locator('#time_entry_activity_id');
|
|
280
|
+
if (await activity.count()) {
|
|
281
|
+
const values = await activity.locator('option').evaluateAll((os) => os.map((o) => o.value).filter(Boolean));
|
|
282
|
+
if (values.length && !(await activity.inputValue())) await activity.selectOption(values[0]);
|
|
283
|
+
}
|
|
284
|
+
if (comment) await form.locator('#time_entry_comments').fill(comment);
|
|
285
|
+
}, 'The update form has the spent time for an account that may log time in the project.');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Assert the time spent on the open issue, as it shows it ("0:30 h", "1:00 h").
|
|
290
|
+
*
|
|
291
|
+
* Example #1: Then the time spent on the issue should be "0:30 h"
|
|
292
|
+
* Example #2: Then the time spent on the issue should be "1:00 h"
|
|
293
|
+
* Example #3: And the time spent on the issue should be "2:00 h"
|
|
294
|
+
* Example #4: But the time spent on the issue should be "1:15 h"
|
|
295
|
+
* Example #5: Then the time spent on the issue should be "0:30 h"
|
|
296
|
+
*
|
|
297
|
+
*/
|
|
298
|
+
Then(/^the time spent on the issue should be "([^"]*)"$/, async function (spent) {
|
|
299
|
+
openIssue(this);
|
|
300
|
+
const result = await waitForValue(() => attribute(this, 'spent-time'), (shown) => shown.replace(/\s+/g, '') === spent.replace(/\s+/g, ''), budget(this));
|
|
301
|
+
if (!result.ok) throw friendly({ message: `Expected the time spent "${spent}", but the issue shows "${result.value || 'none'}".`, hint: 'The spent time is among the attributes of the issue once time is logged on it, as the site formats it ("0:30 h").' });
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Assign the open issue through its update form, to someone the form lists, by the name the site shows.
|
|
306
|
+
*
|
|
307
|
+
* Example #1: When I assign the issue to "Member Test"
|
|
308
|
+
* Example #2: When I assign the issue to "Owner Test"
|
|
309
|
+
* Example #3: And we assign the issue to "Member Test"
|
|
310
|
+
* Example #4: Then I assign the issue to "Owner Test"
|
|
311
|
+
* Example #5: When assign the issue to "Member Test"
|
|
312
|
+
*
|
|
313
|
+
*/
|
|
314
|
+
When(/^(I |we )*assign the issue to "([^"]*)"$/, async function (pronounCase, name) {
|
|
315
|
+
await update(this, 'assign the issue to', name, async (form) => {
|
|
316
|
+
await form.locator('#issue_assigned_to_id').selectOption({ label: name }, { timeout: budget(this) });
|
|
317
|
+
}, 'The assignee list of the update form shows to an account that may edit the issue, with the members who take issues.');
|
|
318
|
+
const result = await waitForValue(() => attribute(this, 'assigned-to'), (shown) => exactly(name).test(shown), budget(this));
|
|
319
|
+
if (!result.ok) throw friendly({ message: `The issue was not assigned to ${name}: it shows "${result.value}".`, hint: 'Only a member whose role takes issues can be assigned.' });
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Assert who the open issue is assigned to, by the name the site shows.
|
|
324
|
+
*
|
|
325
|
+
* Example #1: Then the issue should be assigned to "Member Test"
|
|
326
|
+
* Example #2: Then the issue should be assigned to "Owner Test"
|
|
327
|
+
* Example #3: And the issue should be assigned to "Member Test"
|
|
328
|
+
* Example #4: But the issue should be assigned to "Owner Test"
|
|
329
|
+
* Example #5: Then the issue should be assigned to "Member Test"
|
|
330
|
+
*
|
|
331
|
+
*/
|
|
332
|
+
Then(/^the issue should be assigned to "([^"]*)"$/, async function (name) {
|
|
333
|
+
openIssue(this);
|
|
334
|
+
const result = await waitForValue(() => attribute(this, 'assigned-to'), (shown) => exactly(name).test(shown), budget(this));
|
|
335
|
+
if (!result.ok) throw friendly({ message: `Expected the issue to be assigned to ${name}, but it shows "${result.value || 'nobody'}".`, hint: 'The assignee is the attribute "Assignee" of the issue.' });
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// ---------------------------------------------------------------------------
|
|
339
|
+
// What an account may not do
|
|
340
|
+
// ---------------------------------------------------------------------------
|
|
341
|
+
|
|
342
|
+
/** The update form of the open issue, opened; null when the issue offers none. */
|
|
343
|
+
async function updateForm(world) {
|
|
344
|
+
const id = openIssue(world);
|
|
345
|
+
const edit = world.page.locator(`a.icon-edit[href$="/issues/${id}/edit"]`).first();
|
|
346
|
+
if (!(await edit.count())) return null;
|
|
347
|
+
await edit.click();
|
|
348
|
+
await world.page.locator('#update').waitFor({ state: 'visible', timeout: budget(world) });
|
|
349
|
+
return world.page.locator('#issue-form');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Assert that the account of the session may not move the open issue: its update form has no status (or there is no
|
|
354
|
+
* update form at all).
|
|
355
|
+
*
|
|
356
|
+
* Example #1: Then I should not be able to change the status of the issue
|
|
357
|
+
* Example #2: Then we should not be able to change the status of the issue
|
|
358
|
+
* Example #3: And I should not be able to change the status of the issue
|
|
359
|
+
* Example #4: But I should not be able to change the status of the issue
|
|
360
|
+
* Example #5: Then should not be able to change the status of the issue
|
|
361
|
+
*
|
|
362
|
+
*/
|
|
363
|
+
Then(/^(I |we )*should not be able to change the status of the issue$/, async function (pronounCase) {
|
|
364
|
+
const form = await updateForm(this);
|
|
365
|
+
if (form && (await form.locator('#issue_status_id').count())) throw friendly({ message: 'Expected no status in the update form of the issue, but the form offers it.', hint: 'A Reporter may add notes but not move an issue; a Developer and a Manager may.' });
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Assert that the account of the session may not assign the open issue: its update form has no assignee (or there is
|
|
370
|
+
* no update form at all).
|
|
371
|
+
*
|
|
372
|
+
* Example #1: Then I should not be able to assign the issue
|
|
373
|
+
* Example #2: Then we should not be able to assign the issue
|
|
374
|
+
* Example #3: And I should not be able to assign the issue
|
|
375
|
+
* Example #4: But I should not be able to assign the issue
|
|
376
|
+
* Example #5: Then should not be able to assign the issue
|
|
377
|
+
*
|
|
378
|
+
*/
|
|
379
|
+
Then(/^(I |we )*should not be able to assign the issue$/, async function (pronounCase) {
|
|
380
|
+
const form = await updateForm(this);
|
|
381
|
+
if (form && (await form.locator('#issue_assigned_to_id').count())) throw friendly({ message: 'Expected no assignee in the update form of the issue, but the form offers it.', hint: 'A Reporter may add notes but not assign an issue; a Developer and a Manager may.' });
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// ---------------------------------------------------------------------------
|
|
385
|
+
// What a scenario made goes after it
|
|
386
|
+
// ---------------------------------------------------------------------------
|
|
387
|
+
|
|
388
|
+
After(async function () {
|
|
389
|
+
const made = (this.redmine && this.redmine.made) || new Set();
|
|
390
|
+
for (const id of made) {
|
|
391
|
+
try { await removeIssue(this, id); } catch (e) { console.warn(` could not remove the issue #${id} a scenario made: ${e.message}`); }
|
|
392
|
+
}
|
|
393
|
+
if (this.redmine) this.redmine.made = new Set();
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
AfterAll(async function () {
|
|
397
|
+
await managerContexts.dispose();
|
|
398
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Session and project step definitions: logging in with the users registry, the login form and its refusal, logging
|
|
4
|
+
// out, who the session is, and a project an account may open or is refused.
|
|
5
|
+
//
|
|
6
|
+
// The other step files: redmine-issues.steps.js (the issue list, one issue, its status, notes, time and assignee, a
|
|
7
|
+
// new issue) and redmine-versions.steps.js (a version and its issues, the roadmap).
|
|
8
|
+
//
|
|
9
|
+
// Steps that webship-js already covers with its generic click, fill and see vocabulary are not duplicated here.
|
|
10
|
+
// Every assertion waits on its locator (the assertion is the wait), and every failure is a friendly error with a hint
|
|
11
|
+
// instead of a raw Playwright timeout stack.
|
|
12
|
+
|
|
13
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
14
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
15
|
+
const {
|
|
16
|
+
budget,
|
|
17
|
+
exactly,
|
|
18
|
+
tidy,
|
|
19
|
+
open,
|
|
20
|
+
waitForValue,
|
|
21
|
+
resolveUser,
|
|
22
|
+
currentUser,
|
|
23
|
+
currentName,
|
|
24
|
+
dropSession,
|
|
25
|
+
submitLogin,
|
|
26
|
+
signInAs,
|
|
27
|
+
siteUrl,
|
|
28
|
+
findProject,
|
|
29
|
+
} = require('./redmine-helpers');
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Logging in (the first steps of the pack), then the rest of the session
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Log in with an account of the users registry in cucumber.js (`worldParameters.users`), by its handle, and make sure
|
|
37
|
+
* the session is that account's. An account that is already logged in is kept. The first time in a run the account goes
|
|
38
|
+
* through the login form; after that its session is put back, so switching accounts inside a scenario is quick.
|
|
39
|
+
*
|
|
40
|
+
* Example #1: Given I am a logged in user with the "member" user
|
|
41
|
+
* Example #2: Given I am a logged in user with the "owner" user
|
|
42
|
+
* Example #3: Given we are a logged in user with the "reader" user
|
|
43
|
+
* Example #4: And I am a logged in user with the "stranger" user
|
|
44
|
+
* Example #5: When I am a logged in user with the "member" user
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
Given(/^(I am|we are) a logged in user with the "([^"]*)" user$/, async function (pronounCase, handle) {
|
|
48
|
+
await signInAs(this, handle);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Log in through the form with the login and the password of an account of the users registry, without the checks of
|
|
53
|
+
* "I am a logged in user with the … user": the step to use when the scenario is about the login itself. Follow it with
|
|
54
|
+
* a step that says what should happen.
|
|
55
|
+
*
|
|
56
|
+
* Example #1: When I log in with the "member" user
|
|
57
|
+
* Example #2: When I log in with the "owner" user
|
|
58
|
+
* Example #3: When we log in with the "reader" user
|
|
59
|
+
* Example #4: And I log in with the "stranger" user
|
|
60
|
+
* Example #5: When log in with the "member" user
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
When(/^(I |we )*log in with the "([^"]*)" user$/, async function (pronounCase, handle) {
|
|
64
|
+
const user = resolveUser(this, handle);
|
|
65
|
+
await dropSession(this);
|
|
66
|
+
await submitLogin(this, user.username, user.password);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Fill in the login form with a login and a password as typed in the step, and submit it. It asserts nothing: follow
|
|
71
|
+
* it with a step that says what should happen (logged in, or the login refused). For the accounts of the registry use
|
|
72
|
+
* "I am a logged in user with the … user".
|
|
73
|
+
*
|
|
74
|
+
* Example #1: When I log in as "member" with the password "not-the-right-password"
|
|
75
|
+
* Example #2: When I log in as "nobody" with the password "whatever"
|
|
76
|
+
* Example #3: When we log in as "reader" with the password "wrong"
|
|
77
|
+
* Example #4: And I log in as "owner" with the password "wrong-password"
|
|
78
|
+
* Example #5: When I log in as "member" with the password ""
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
When(/^(I |we )*log in as "([^"]*)" with the password "([^"]*)"$/, async function (pronounCase, login, password) {
|
|
82
|
+
await dropSession(this);
|
|
83
|
+
await submitLogin(this, login, password);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Make sure nobody is logged in: the browser forgets its session. (To end a session through the screens, use
|
|
88
|
+
* "I log out".)
|
|
89
|
+
*
|
|
90
|
+
* Example #1: Given I am not logged in
|
|
91
|
+
* Example #2: Given we are not logged in
|
|
92
|
+
* Example #3: And I am not logged in
|
|
93
|
+
* Example #4: When I am not logged in
|
|
94
|
+
* Example #5: Given I am not logged in
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
Given(/^(I am|we are) not logged in$/, async function (pronounCase) {
|
|
98
|
+
await dropSession(this);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Log out through the site, the way its account menu does (its sign-out page and its button), and wait until the
|
|
103
|
+
* session is a visitor's.
|
|
104
|
+
*
|
|
105
|
+
* Example #1: When I log out
|
|
106
|
+
* Example #2: When we log out
|
|
107
|
+
* Example #3: And I log out
|
|
108
|
+
* Example #4: Then I log out
|
|
109
|
+
* Example #5: When log out
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
When(/^(I |we )*log out$/, async function (pronounCase) {
|
|
113
|
+
await open(this, '/logout');
|
|
114
|
+
const button = this.page.locator('form[action$="/logout"] [type="submit"]').first();
|
|
115
|
+
if (await button.count()) await button.click();
|
|
116
|
+
const result = await waitForValue(() => currentUser(this), (login) => login === '', budget(this));
|
|
117
|
+
if (!result.ok) {
|
|
118
|
+
throw friendly({ message: `Logging out did not end the session: it is still "${result.value}"'s.`, hint: 'The site logs out with the button of its sign-out page (/logout); a single sign-on provider may keep the session elsewhere.' });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Assert who the session is: the name the site shows for the account ("Member Test"), or its login ("member").
|
|
124
|
+
*
|
|
125
|
+
* Example #1: Then I should be logged in as "Member Test"
|
|
126
|
+
* Example #2: Then I should be logged in as "member"
|
|
127
|
+
* Example #3: Then we should be logged in as "Owner Test"
|
|
128
|
+
* Example #4: And I should be logged in as "reader"
|
|
129
|
+
* Example #5: Then should be logged in as "Stranger Test"
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
Then(/^(I |we )*should be logged in as "([^"]*)"$/, async function (pronounCase, who) {
|
|
133
|
+
const result = await waitForValue(async () => [await currentUser(this), await currentName(this)], ([login, name]) => login === who || exactly(who).test(name), budget(this));
|
|
134
|
+
if (!result.ok) {
|
|
135
|
+
const [login, name] = result.value || ['', ''];
|
|
136
|
+
throw friendly({
|
|
137
|
+
message: login ? `Expected the session to be "${who}", but it is ${name} (login "${login}").` : `Expected the session to be "${who}", but nobody is logged in.`,
|
|
138
|
+
hint: 'Log in first with Given I am a logged in user with the "…" user, or with the login form.',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Assert that nobody is logged in: the session is a visitor's.
|
|
145
|
+
*
|
|
146
|
+
* Example #1: Then I should not be logged in
|
|
147
|
+
* Example #2: Then we should not be logged in
|
|
148
|
+
* Example #3: And I should not be logged in
|
|
149
|
+
* Example #4: But I should not be logged in
|
|
150
|
+
* Example #5: Then should not be logged in
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
153
|
+
Then(/^(I |we )*should not be logged in$/, async function (pronounCase) {
|
|
154
|
+
const result = await waitForValue(() => currentUser(this), (login) => login === '', budget(this));
|
|
155
|
+
if (!result.ok) {
|
|
156
|
+
throw friendly({ message: `Expected nobody to be logged in, but the session is "${result.value}"'s.`, hint: 'A refused login keeps the visitor\'s session; a login that worked opens the account\'s.' });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Assert that the login form refused the last login with a message that holds the text (the site's error banner).
|
|
162
|
+
* Give such a scenario @js-off: the browser logs the refused request.
|
|
163
|
+
*
|
|
164
|
+
* Example #1: Then the login should be refused with "Invalid user or password"
|
|
165
|
+
* Example #2: Then the login should be refused with "Invalid user"
|
|
166
|
+
* Example #3: And the login should be refused with "password"
|
|
167
|
+
* Example #4: But the login should be refused with "Invalid user or password"
|
|
168
|
+
* Example #5: Then the login should be refused with "Invalid user"
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
Then(/^the login should be refused with "([^"]*)"$/, async function (text) {
|
|
172
|
+
const banner = this.page.locator('#flash_error, .flash.error').filter({ hasText: text }).first();
|
|
173
|
+
try {
|
|
174
|
+
await banner.waitFor({ state: 'visible', timeout: budget(this) });
|
|
175
|
+
} catch {
|
|
176
|
+
const shown = tidy(await this.page.locator('.flash').first().innerText({ timeout: 1000 }).catch(() => ''));
|
|
177
|
+
throw friendly({
|
|
178
|
+
message: `Expected the login to be refused with "${text}", but ${shown ? `the page says "${shown}"` : 'the page shows no error'} (${this.page.url()}).`,
|
|
179
|
+
hint: 'Use it right after "I log in as … with the password …". A login that worked shows no error.',
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
// Projects
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Open the overview of a project, by its identifier ("webship-site") or its name ("Webship site").
|
|
190
|
+
*
|
|
191
|
+
* Example #1: When I open the project "webship-site"
|
|
192
|
+
* Example #2: When I open the project "Webship site"
|
|
193
|
+
* Example #3: And we open the project "webship-site"
|
|
194
|
+
* Example #4: Given I open the project "webship-site"
|
|
195
|
+
* Example #5: When open the project "Webship site"
|
|
196
|
+
*
|
|
197
|
+
*/
|
|
198
|
+
When(/^(I |we )*open the project "([^"]*)"$/, async function (pronounCase, which) {
|
|
199
|
+
const project = await findProject(this, which);
|
|
200
|
+
this.redmine = Object.assign(this.redmine || {}, { project: project.identifier });
|
|
201
|
+
await open(this, `/projects/${project.identifier}`);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Assert that the session may not open a project: the site answers that it is not authorized (403), or "not found".
|
|
206
|
+
* Give such a scenario @js-off: the browser logs the refused page.
|
|
207
|
+
*
|
|
208
|
+
* Example #1: Then I should be refused the project "webship-site"
|
|
209
|
+
* Example #2: Then we should be refused the project "Webship site"
|
|
210
|
+
* Example #3: And I should be refused the project "webship-site"
|
|
211
|
+
* Example #4: But I should be refused the project "webship-site"
|
|
212
|
+
* Example #5: Then should be refused the project "Webship site"
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
Then(/^(I |we )*should be refused the project "([^"]*)"$/, async function (pronounCase, which) {
|
|
216
|
+
const project = await findProject(this, which);
|
|
217
|
+
const response = await this.page.goto(siteUrl(this, `/projects/${project.identifier}`)).catch(() => null);
|
|
218
|
+
const status = response ? response.status() : 0;
|
|
219
|
+
if (status !== 404 && status !== 403) {
|
|
220
|
+
throw friendly({
|
|
221
|
+
message: `Expected the project ${project.name} to be refused, but the site answered ${status || 'nothing'} (${this.page.url()}).`,
|
|
222
|
+
hint: 'A member of the project, a public project and an administrator may open it; log in as an account with no membership.',
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|