@webship-js/gitea-steps 0.0.0-stage → 2.0.0

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.
@@ -0,0 +1,488 @@
1
+ 'use strict';
2
+
3
+ // Issue step definitions: the test content a scenario makes and removes (through the forge's REST API, as the
4
+ // managing account), the issue list, one issue and what a person does on it through its page (a comment, closing and
5
+ // reopening it, the time spent on it, its assignee), what its sidebar shows (its milestone), a new issue made through
6
+ // the form, and what an account may not do (a reader's close button, assignee and time tracker).
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 comments 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-gitea-cli.sh <site> --tidy` removes what a stopped run left.
11
+ //
12
+ // Gitea 1.27 and Forgejo 17 draw the issue sidebar differently (a combo list in Gitea, the older dropdowns in Forgejo);
13
+ // each control below is looked for in both shapes. A milestone is set through the API, never the sidebar: Forgejo's own
14
+ // script logs errors after a milestone change on the page.
15
+
16
+ const { Given, When, Then, After, AfterAll } = require('@cucumber/cucumber');
17
+ const { smartSettle, friendly } = require('webship-js/tests/step-definitions/webship');
18
+ const {
19
+ budget,
20
+ escapeRegExp,
21
+ exactly,
22
+ tidy,
23
+ open,
24
+ actOrExplain,
25
+ assertPresence,
26
+ waitForValue,
27
+ findRepository,
28
+ findIssues,
29
+ issueNamed,
30
+ remember,
31
+ removeIssue,
32
+ makeIssue,
33
+ managerContexts,
34
+ } = require('./gitea-helpers');
35
+
36
+ /** The repository a step names, else the last one a scenario used, else the one of cucumber.js. */
37
+ async function repositoryOf(world, which) {
38
+ const repo = await findRepository(world, which || (world.gitea && world.gitea.repository));
39
+ world.gitea = Object.assign(world.gitea || {}, { repository: repo.path });
40
+ return repo;
41
+ }
42
+
43
+ /** The issue page on screen: its repository and number, from the address, or a friendly error. */
44
+ function openIssue(world) {
45
+ const m = world.page.url().match(/\/([^/]+\/[^/]+)\/issues\/(\d+)/);
46
+ 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 "…".' });
47
+ return { repository: m[1], number: m[2] };
48
+ }
49
+
50
+ /** What the open issue's state label says: "Open" or "Closed". */
51
+ async function stateOf(world) {
52
+ return tidy(await world.page.locator('.issue-state-label').first().innerText({ timeout: 2000 }).catch(() => ''));
53
+ }
54
+
55
+ /** The sidebar's assignee control: Gitea's combo dropdown, or Forgejo's dropdown. */
56
+ function assigneeDropdown(page) {
57
+ return page.locator('.issue-sidebar-combo[data-update-url*="/issues/assignee"] .ui.dropdown, .select-assignees-modify.dropdown').first();
58
+ }
59
+
60
+ /** The logins (and full names) the sidebar shows as the issue's assignees. */
61
+ async function assigneesShown(world) {
62
+ return world.page.evaluate(() => {
63
+ const out = [];
64
+ const combo = document.querySelector('.issue-sidebar-combo[data-update-url*="/issues/assignee"] .ui.list');
65
+ const list = combo || document.querySelector('.ui.assignees.list .selected');
66
+ if (!list) return out;
67
+ for (const item of list.querySelectorAll('a.item, .item a, .item')) {
68
+ if (item.classList.contains('empty-list') || item.closest('.tw-hidden, .no-select')) continue;
69
+ const text = item.textContent.replace(/\s+/g, ' ').trim();
70
+ if (text) out.push(text);
71
+ }
72
+ return [...new Set(out)];
73
+ });
74
+ }
75
+
76
+ /** The milestone the sidebar shows for the issue, or ''. */
77
+ async function milestoneShown(world) {
78
+ return world.page.evaluate(() => {
79
+ const combo = document.querySelector('.issue-sidebar-combo[data-update-url*="/issues/milestone"] .ui.list');
80
+ const list = combo || document.querySelector('#selected-milestone .selected, .ui.select-milestone.list .selected');
81
+ if (!list) return '';
82
+ const items = [...list.querySelectorAll('a.item, .item a, .item, a')].filter((e) => !e.classList.contains('empty-list') && !e.closest('.tw-hidden, .no-select'));
83
+ return items.length ? items[0].textContent.replace(/\s+/g, ' ').trim() : '';
84
+ });
85
+ }
86
+
87
+ /** "Total Time Spent: 30 minutes" of the sidebar (Forgejo: "Total time spent"), as "30 minutes"; '' when none. */
88
+ async function timeSpentShown(world) {
89
+ return world.page.evaluate(() => {
90
+ const side = document.querySelector('.issue-content-right') || document.body;
91
+ for (const e of side.querySelectorAll('*')) {
92
+ if (e.children.length) continue;
93
+ const m = e.textContent.replace(/\s+/g, ' ').trim().match(/^Total time spent:\s*(.+)$/i);
94
+ if (m) return m[1].trim();
95
+ }
96
+ return '';
97
+ });
98
+ }
99
+
100
+ // ---------------------------------------------------------------------------
101
+ // Test content
102
+ // ---------------------------------------------------------------------------
103
+
104
+ /**
105
+ * Make sure there is an issue of this title in a repository (made through the API as the managing account; one of the
106
+ * same title is removed first, so a scenario starts from a known issue). It goes after the scenario. With "in the
107
+ * milestone …" it is in that milestone of the repository from the start.
108
+ *
109
+ * Example #1: Given there is an issue "Webship test comment" in the repository "owner/webship-site"
110
+ * Example #2: Given there is an issue "Webship test close"
111
+ * Example #3: And there is an issue "Webship test time" in the repository "owner/webship-site"
112
+ * Example #4: Given there is an issue "Webship test sprint" in the milestone "Sprint 1"
113
+ * Example #5: Given there is an issue "Webship test assign" in the milestone "Sprint 1" of the repository "owner/webship-site"
114
+ *
115
+ */
116
+ Given(/^there is an issue "([^"]*)"(?: in the milestone "([^"]*)")?(?: (?:in|of) the repository "([^"]*)")?$/, async function (title, milestone, which) {
117
+ const repo = await repositoryOf(this, which);
118
+ for (const old of await findIssues(this, repo, title)) await removeIssue(this, repo.path, old.number);
119
+ await makeIssue(this, repo, title, { milestone });
120
+ });
121
+
122
+ /**
123
+ * Make sure there is no issue of this title in a repository (any is removed through the API, with its comments and
124
+ * time).
125
+ *
126
+ * Example #1: Given there is no issue "Webship test new" in the repository "owner/webship-site"
127
+ * Example #2: Given there is no issue "Webship test form"
128
+ * Example #3: And there is no issue "Webship test new" in the repository "owner/webship-site"
129
+ * Example #4: Given there is no issue "Webship test made by hand"
130
+ * Example #5: But there is no issue "Webship test new"
131
+ *
132
+ */
133
+ Given(/^there is no issue "([^"]*)"(?: in the repository "([^"]*)")?$/, async function (title, which) {
134
+ const repo = await repositoryOf(this, which);
135
+ for (const old of await findIssues(this, repo, title)) await removeIssue(this, repo.path, old.number);
136
+ });
137
+
138
+ // ---------------------------------------------------------------------------
139
+ // The issue list
140
+ // ---------------------------------------------------------------------------
141
+
142
+ /**
143
+ * Open the issues of a repository (its list of open issues).
144
+ *
145
+ * Example #1: When I open the issues of the repository "owner/webship-site"
146
+ * Example #2: When we open the issues of the repository "owner/webship-site"
147
+ * Example #3: And I open the issues of the repository "owner/webship-site"
148
+ * Example #4: Given I open the issues of the repository "owner/webship-site"
149
+ * Example #5: When open the issues of the repository "owner/webship-site"
150
+ *
151
+ */
152
+ When(/^(I |we )*open the issues of the repository "([^"]*)"$/, async function (pronounCase, which) {
153
+ const repo = await repositoryOf(this, which);
154
+ await open(this, `/${repo.path}/issues`);
155
+ });
156
+
157
+ /**
158
+ * Assert that the issue list on screen shows (or does not show) an issue of this title.
159
+ *
160
+ * Example #1: Then the issue list should show "The greeting script says Helo instead of Hello"
161
+ * Example #2: Then the issue list should not show "Webship test closed"
162
+ * Example #3: And the issue list should show "Webship test list"
163
+ * Example #4: But the issue list should not show "Webship test gone"
164
+ * Example #5: Then the issue list should show "The usage line spells greeting as greting"
165
+ *
166
+ */
167
+ Then(/^the issue list should( not)? show "([^"]*)"$/, async function (notCase, title) {
168
+ const link = this.page.locator('a[href*="/issues/"]').filter({ hasText: exactly(title) });
169
+ await assertPresence(link, notCase, {
170
+ label: `the issue "${title}" in the list`,
171
+ hint: notCase ? 'The list shows the open issues: a closed one leaves it.' : 'The list shows the open issues the session may see; check the title and that the issue is open.',
172
+ timeout: budget(this),
173
+ });
174
+ });
175
+
176
+ /**
177
+ * Make an issue through the form of a new issue, as the session's account (its title, and a description). It goes
178
+ * after the scenario.
179
+ *
180
+ * Example #1: When I create an issue "Webship test form" in the repository "owner/webship-site"
181
+ * Example #2: When we create an issue "Webship test form"
182
+ * Example #3: And I create an issue "Webship test made by hand" in the repository "owner/webship-site"
183
+ * Example #4: When I create an issue "Webship test new"
184
+ * Example #5: When create an issue "Webship test form"
185
+ *
186
+ */
187
+ When(/^(I |we )*create an issue "([^"]*)"(?: in the repository "([^"]*)")?$/, async function (pronounCase, title, which) {
188
+ const repo = await repositoryOf(this, which);
189
+ const page = this.page;
190
+ await open(this, `/${repo.path}/issues/new`);
191
+ await actOrExplain('create the issue', title, async () => {
192
+ const form = page.locator('form:has(#issue_title)').first();
193
+ await form.locator('#issue_title').fill(title);
194
+ await form.locator('textarea[name="content"]').first().fill('Made by a test scenario through the form; it goes after the scenario.');
195
+ await form.getByRole('button', { name: /^\s*create issue\s*$/i }).first().click();
196
+ await page.waitForURL(/\/issues\/\d+(?:[?#].*)?$/, { timeout: budget(this) });
197
+ }, 'The form of a new issue (#issue_title and its Create Issue button) is at /owner/name/issues/new for an account that may open issues.');
198
+ const made = openIssue(this);
199
+ remember(this, made.repository, made.number);
200
+ await smartSettle(page, 1000);
201
+ });
202
+
203
+ // ---------------------------------------------------------------------------
204
+ // One issue
205
+ // ---------------------------------------------------------------------------
206
+
207
+ /**
208
+ * Open an issue by its title, in the repository the scenario uses.
209
+ *
210
+ * Example #1: When I open the issue "The greeting script says Helo instead of Hello"
211
+ * Example #2: When we open the issue "Webship test comment"
212
+ * Example #3: And I open the issue "Webship test close"
213
+ * Example #4: Given I open the issue "Webship test time"
214
+ * Example #5: When open the issue "An issue opened by someone outside the project"
215
+ *
216
+ */
217
+ When(/^(I |we )*open the issue "([^"]*)"$/, async function (pronounCase, title) {
218
+ const issue = await issueNamed(this, title);
219
+ this.gitea = Object.assign(this.gitea || {}, { repository: issue.repository });
220
+ await open(this, `/${issue.repository}/issues/${issue.number}`);
221
+ });
222
+
223
+ /**
224
+ * Add a comment to the open issue through its comment box, and wait until the issue shows it.
225
+ *
226
+ * Example #1: When I add the comment "Checked on the test site" to the issue
227
+ * Example #2: When we add the comment "Seen" to the issue
228
+ * Example #3: And I add the comment "The fix is on a branch" to the issue
229
+ * Example #4: Then I add the comment "Done" to the issue
230
+ * Example #5: When add the comment "Checked" to the issue
231
+ *
232
+ */
233
+ When(/^(I |we )*add the comment "([^"]*)" to the issue$/, async function (pronounCase, text) {
234
+ openIssue(this);
235
+ const page = this.page;
236
+ await actOrExplain('add the comment', text, async () => {
237
+ const form = page.locator('#comment-form');
238
+ await form.locator('textarea[name="content"]').first().fill(text);
239
+ await form.getByRole('button', { name: /^\s*comment\s*$/i }).first().click();
240
+ }, 'The comment box (#comment-form, its text area and its Comment button) shows for an account that may comment.');
241
+ await assertPresence(page.locator('.timeline-item.comment[id^="issuecomment-"] .render-content').filter({ hasText: text }), null, {
242
+ label: `the comment "${text}"`, hint: 'The forge reloads the issue with the new comment in its timeline.', timeout: budget(this),
243
+ });
244
+ });
245
+
246
+ /**
247
+ * Assert that the open issue shows a comment that holds the text, written by that account when one is named (its
248
+ * login, or the full name of a handle of the users registry).
249
+ *
250
+ * Example #1: Then the issue should show the comment "Checked on the test site"
251
+ * Example #2: Then the issue should show the comment "Checked on the test site" by "member"
252
+ * Example #3: And the issue should show the comment "The script is in the repository" by "owner"
253
+ * Example #4: But the issue should show the comment "Seen"
254
+ * Example #5: Then the issue should show the comment "Done" by "Member Test"
255
+ *
256
+ */
257
+ Then(/^the issue should show the comment "([^"]*)"(?: by "([^"]*)")?$/, async function (text, who) {
258
+ openIssue(this);
259
+ const comment = this.page.locator('.timeline-item.comment[id^="issuecomment-"]').filter({ has: this.page.locator('.render-content').filter({ hasText: text }) });
260
+ await assertPresence(comment, null, { label: `the comment "${text}"`, hint: 'Comments are in the issue\'s timeline, under its description.', timeout: budget(this) });
261
+ if (!who) return;
262
+ const users = (this.parameters && this.parameters.users) || {};
263
+ const entry = Object.values(users).find((u) => u && (u.name === who || u.username === who));
264
+ const login = entry ? entry.username : who;
265
+ const authors = (await comment.locator('.comment-header-left a.author, .comment-header-left a.tw-font-semibold').allInnerTexts()).map(tidy);
266
+ if (!authors.includes(login)) {
267
+ throw friendly({ message: `Expected the comment "${text}" to be by "${who}" (${login}), but it is by ${authors.join(', ') || 'nobody the page names'}.`, hint: 'The forge names a comment\'s author by login; a handle of the users registry is read as its login.' });
268
+ }
269
+ });
270
+
271
+ /**
272
+ * Close or reopen the open issue with its button (Gitea's "Close Issue" and "Reopen Issue", Forgejo's "Close issue"
273
+ * and "Reopen"), and wait until its state says so.
274
+ *
275
+ * Example #1: When I close the issue
276
+ * Example #2: When I reopen the issue
277
+ * Example #3: And we close the issue
278
+ * Example #4: Then I reopen the issue
279
+ * Example #5: When close the issue
280
+ *
281
+ */
282
+ When(/^(I |we )*(close|reopen) the issue$/, async function (pronounCase, action) {
283
+ openIssue(this);
284
+ const want = action === 'close' ? 'Closed' : 'Open';
285
+ const button = this.page.locator('#status-button').filter({ hasText: action === 'close' ? /^\s*close/i : /^\s*reopen/i }).first();
286
+ await actOrExplain(`${action} the issue`, this.page.url(), () => button.click({ timeout: budget(this) }),
287
+ action === 'close' ? 'An open issue has a Close button for its author and those with write access.' : 'A closed issue has a Reopen button for its author and those with write access.');
288
+ const result = await waitForValue(() => stateOf(this), (s) => exactly(want).test(s), budget(this));
289
+ if (!result.ok) throw friendly({ message: `Expected the issue to be ${want.toLowerCase()} after "${action}", but it says "${result.value || 'nothing'}".`, hint: 'The forge reloads the issue with its new state.' });
290
+ });
291
+
292
+ /**
293
+ * Assert the state of the open issue: "open" or "closed".
294
+ *
295
+ * Example #1: Then the issue should be "open"
296
+ * Example #2: Then the issue should be "closed"
297
+ * Example #3: And the issue should be "open"
298
+ * Example #4: But the issue should be "closed"
299
+ * Example #5: Then the issue should be "Open"
300
+ *
301
+ */
302
+ Then(/^the issue should be "(open|closed|Open|Closed)"$/, async function (state) {
303
+ openIssue(this);
304
+ const result = await waitForValue(() => stateOf(this), (s) => exactly(state).test(s), budget(this));
305
+ if (!result.ok) throw friendly({ message: `Expected the issue to be ${state}, but it says "${result.value || 'nothing'}".`, hint: 'The state label is under the issue\'s title.' });
306
+ });
307
+
308
+ /**
309
+ * Log time spent on the open issue through its time tracker ("Add Time": hours and minutes), and wait until the issue
310
+ * counts it. "0.5" hours are 30 minutes.
311
+ *
312
+ * Example #1: When I log "0.5" hours on the issue
313
+ * Example #2: When we log "1" hours on the issue
314
+ * Example #3: And I log "1.25" hours on the issue
315
+ * Example #4: Then I log "0.25" hours on the issue
316
+ * Example #5: When log "2" hours on the issue
317
+ *
318
+ */
319
+ When(/^(I |we )*log "([0-9]+(?:\.[0-9]+)?)" hours on the issue$/, async function (pronounCase, amount) {
320
+ openIssue(this);
321
+ const total = Math.round(Number(amount) * 60);
322
+ const hours = Math.floor(total / 60);
323
+ const minutes = total % 60;
324
+ const page = this.page;
325
+ const before = await timeSpentShown(this);
326
+ await actOrExplain('log time on the issue', `${amount} hours`, async () => {
327
+ await page.locator('button.issue-add-time').first().click({ timeout: budget(this) });
328
+ const modal = page.locator('.ui.modal.visible:has(input[name="hours"])').first();
329
+ await modal.waitFor({ state: 'visible', timeout: budget(this) });
330
+ await modal.locator('input[name="hours"]').fill(String(hours));
331
+ await modal.locator('input[name="minutes"]').fill(String(minutes));
332
+ await modal.locator('.primary.button').first().click();
333
+ }, 'The time tracker ("Add Time") shows for those with write access when time tracking is on in the repository.');
334
+ const result = await waitForValue(() => timeSpentShown(this), (t) => t !== '' && t !== before, budget(this));
335
+ if (!result.ok) throw friendly({ message: `The time logged did not show: the issue still says "${result.value || 'no time spent'}".`, hint: 'The forge reloads the issue with "Total Time Spent" in its sidebar.' });
336
+ });
337
+
338
+ /**
339
+ * Assert the total time spent on the open issue, as its sidebar says it ("30 minutes", "1 hour 15 minutes").
340
+ *
341
+ * Example #1: Then the time spent on the issue should be "30 minutes"
342
+ * Example #2: Then the time spent on the issue should be "1 hour"
343
+ * Example #3: And the time spent on the issue should be "1 hour 15 minutes"
344
+ * Example #4: But the time spent on the issue should be "15 minutes"
345
+ * Example #5: Then the time spent on the issue should be "2 hours"
346
+ *
347
+ */
348
+ Then(/^the time spent on the issue should be "([^"]*)"$/, async function (expected) {
349
+ openIssue(this);
350
+ const result = await waitForValue(() => timeSpentShown(this), (t) => exactly(expected).test(t), budget(this));
351
+ if (!result.ok) throw friendly({ message: `Expected the time spent to be "${expected}", but the issue says "${result.value || 'no time spent'}".`, hint: 'The sidebar says "Total Time Spent: …" once time is logged.' });
352
+ });
353
+
354
+ /**
355
+ * Assign the open issue to an account through its sidebar (its login, as the list of assignees shows it), and wait
356
+ * until the sidebar shows it.
357
+ *
358
+ * Example #1: When I assign the issue to "member"
359
+ * Example #2: When we assign the issue to "owner"
360
+ * Example #3: And I assign the issue to "member"
361
+ * Example #4: Then I assign the issue to "owner"
362
+ * Example #5: When assign the issue to "member"
363
+ *
364
+ */
365
+ When(/^(I |we )*assign the issue to "([^"]*)"$/, async function (pronounCase, login) {
366
+ openIssue(this);
367
+ const page = this.page;
368
+ const dropdown = assigneeDropdown(page);
369
+ await actOrExplain('assign the issue to', login, async () => {
370
+ await dropdown.click({ timeout: budget(this) });
371
+ await dropdown.locator('.menu .item').filter({ hasText: new RegExp('^\\s*' + escapeRegExp(login) + '(\\s|\\(|$)', 'i') }).first().click({ timeout: budget(this) });
372
+ // The choice is sent when the menu closes.
373
+ await page.locator('#issue-title-display').first().click();
374
+ }, 'The Assignees control of the sidebar lists the accounts with write access; a reader sees it disabled.');
375
+ const result = await waitForValue(() => assigneesShown(this), (list) => list.some((a) => a.split(/\s/)[0] === login), budget(this));
376
+ if (!result.ok) throw friendly({ message: `The issue was not assigned to "${login}": the sidebar shows ${(result.value || []).join(', ') || 'no assignee'}.`, hint: 'Only an account with write access to the repository may be assigned.' });
377
+ });
378
+
379
+ /**
380
+ * Assert that the open issue is assigned to an account: its login ("member") or its full name ("Member Test").
381
+ *
382
+ * Example #1: Then the issue should be assigned to "member"
383
+ * Example #2: Then the issue should be assigned to "Member Test"
384
+ * Example #3: And the issue should be assigned to "owner"
385
+ * Example #4: But the issue should be assigned to "member"
386
+ * Example #5: Then the issue should be assigned to "Owner Test"
387
+ *
388
+ */
389
+ Then(/^the issue should be assigned to "([^"]*)"$/, async function (who) {
390
+ openIssue(this);
391
+ const users = (this.parameters && this.parameters.users) || {};
392
+ const entry = Object.values(users).find((u) => u && (u.name === who || u.username === who));
393
+ const login = entry ? entry.username : who;
394
+ const result = await waitForValue(() => assigneesShown(this), (list) => list.some((a) => a.split(/\s/)[0] === login || a.includes(`(${who})`)), budget(this));
395
+ if (!result.ok) throw friendly({ message: `Expected the issue to be assigned to "${who}", but the sidebar shows ${(result.value || []).join(', ') || 'no assignee'}.`, hint: 'The Assignees of the sidebar name each by login (Gitea adds the full name).' });
396
+ });
397
+
398
+ /**
399
+ * Assert the milestone the open issue is in, as its sidebar shows it.
400
+ *
401
+ * Example #1: Then the milestone of the issue should be "Sprint 1"
402
+ * Example #2: Then the milestone of the issue should be "Sprint 2"
403
+ * Example #3: And the milestone of the issue should be "Sprint 1"
404
+ * Example #4: But the milestone of the issue should be "Sprint 1"
405
+ * Example #5: Then the milestone of the issue should be "Release 1.0"
406
+ *
407
+ */
408
+ Then(/^the milestone of the issue should be "([^"]*)"$/, async function (name) {
409
+ openIssue(this);
410
+ const result = await waitForValue(() => milestoneShown(this), (m) => exactly(name).test(m), budget(this));
411
+ if (!result.ok) throw friendly({ message: `Expected the issue to be in the milestone "${name}", but the sidebar shows ${result.value ? `"${result.value}"` : 'none'}.`, hint: 'Put an issue in a milestone with Given there is an issue "…" in the milestone "…".' });
412
+ });
413
+
414
+ // ---------------------------------------------------------------------------
415
+ // What an account may not do
416
+ // ---------------------------------------------------------------------------
417
+
418
+ /**
419
+ * Assert that the open issue offers the session no close button (a reader on someone else's issue).
420
+ *
421
+ * Example #1: Then I should not be able to close the issue
422
+ * Example #2: Then we should not be able to close the issue
423
+ * Example #3: And I should not be able to close the issue
424
+ * Example #4: But I should not be able to close the issue
425
+ * Example #5: Then should not be able to close the issue
426
+ *
427
+ */
428
+ Then(/^(I |we )*should not be able to close the issue$/, async function (pronounCase) {
429
+ openIssue(this);
430
+ await assertPresence(this.page.locator('.timeline-item.comment[id^="issue-"], .issue-title').first(), null, { label: 'the issue', hint: 'Open it first.', timeout: budget(this) });
431
+ if (await this.page.locator('#status-button').count()) {
432
+ throw friendly({ message: 'Expected no close button for this session, but the issue has one.', hint: 'Its author and those with write access may close an issue; a reader may not close someone else\'s.' });
433
+ }
434
+ });
435
+
436
+ /**
437
+ * Assert that the open issue does not let the session change its assignees (the control is disabled, or not there).
438
+ *
439
+ * Example #1: Then I should not be able to assign the issue
440
+ * Example #2: Then we should not be able to assign the issue
441
+ * Example #3: And I should not be able to assign the issue
442
+ * Example #4: But I should not be able to assign the issue
443
+ * Example #5: Then should not be able to assign the issue
444
+ *
445
+ */
446
+ Then(/^(I |we )*should not be able to assign the issue$/, async function (pronounCase) {
447
+ openIssue(this);
448
+ const dropdown = assigneeDropdown(this.page);
449
+ await this.page.locator('.issue-content-right').first().waitFor({ state: 'visible', timeout: budget(this) });
450
+ if ((await dropdown.count()) && !(await dropdown.evaluate((e) => e.classList.contains('disabled')))) {
451
+ throw friendly({ message: 'Expected the Assignees control to be closed to this session, but it may change them.', hint: 'Those with write access may assign an issue; a reader may not.' });
452
+ }
453
+ });
454
+
455
+ /**
456
+ * Assert that the open issue offers the session no time tracker (no "Add Time").
457
+ *
458
+ * Example #1: Then I should not be able to log time on the issue
459
+ * Example #2: Then we should not be able to log time on the issue
460
+ * Example #3: And I should not be able to log time on the issue
461
+ * Example #4: But I should not be able to log time on the issue
462
+ * Example #5: Then should not be able to log time on the issue
463
+ *
464
+ */
465
+ Then(/^(I |we )*should not be able to log time on the issue$/, async function (pronounCase) {
466
+ openIssue(this);
467
+ await this.page.locator('.issue-content-right').first().waitFor({ state: 'visible', timeout: budget(this) });
468
+ if (await this.page.locator('button.issue-add-time').count()) {
469
+ throw friendly({ message: 'Expected no time tracker for this session, but the issue has one.', hint: 'Those with write access may log time on an issue; a reader may not.' });
470
+ }
471
+ });
472
+
473
+ // ---------------------------------------------------------------------------
474
+ // After a scenario: what it made goes
475
+ // ---------------------------------------------------------------------------
476
+
477
+ After(async function () {
478
+ const made = (this.gitea && this.gitea.made) || new Set();
479
+ for (const key of made) {
480
+ const [repository, number] = key.split('#');
481
+ try { await removeIssue(this, repository, number); } catch (e) { console.warn(` could not remove the issue ${key} a scenario made: ${e.message}`); }
482
+ }
483
+ if (this.gitea) this.gitea.made = new Set();
484
+ });
485
+
486
+ AfterAll(async function () {
487
+ await managerContexts.dispose();
488
+ });
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ // Milestone step definitions: the milestones of a repository, and the issues of one milestone. A milestone is the
4
+ // forge's iteration: the tracker family's "current milestone" is the open one due first.
5
+
6
+ const { When, Then } = require('@cucumber/cucumber');
7
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
8
+ const { budget, exactly, open, assertPresence, findRepository, api, apiFailure } = require('./gitea-helpers');
9
+
10
+ /** The repository a step names, else the last one a scenario used, else the one of cucumber.js. */
11
+ async function repositoryOf(world, which) {
12
+ const repo = await findRepository(world, which || (world.gitea && world.gitea.repository));
13
+ world.gitea = Object.assign(world.gitea || {}, { repository: repo.path });
14
+ return repo;
15
+ }
16
+
17
+ /**
18
+ * Open the milestones of a repository (its open milestones).
19
+ *
20
+ * Example #1: When I open the milestones of the repository "owner/webship-site"
21
+ * Example #2: When we open the milestones of the repository "owner/webship-site"
22
+ * Example #3: And I open the milestones of the repository "owner/webship-site"
23
+ * Example #4: Given I open the milestones of the repository "owner/webship-site"
24
+ * Example #5: When open the milestones of the repository "owner/webship-site"
25
+ *
26
+ */
27
+ When(/^(I |we )*open the milestones of the repository "([^"]*)"$/, async function (pronounCase, which) {
28
+ const repo = await repositoryOf(this, which);
29
+ await open(this, `/${repo.path}/milestones`);
30
+ });
31
+
32
+ /**
33
+ * Assert that the milestones on screen list (or do not list) a milestone of this name.
34
+ *
35
+ * Example #1: Then the milestones should list "Sprint 1"
36
+ * Example #2: Then the milestones should not list "Sprint 9"
37
+ * Example #3: And the milestones should list "Sprint 1"
38
+ * Example #4: But the milestones should not list "Release 0.1"
39
+ * Example #5: Then the milestones should list "Sprint 1"
40
+ *
41
+ */
42
+ Then(/^the milestones should( not)? list "([^"]*)"$/, async function (notCase, name) {
43
+ await assertPresence(this.page.locator('.milestone-list a[href*="/milestone/"]').filter({ hasText: exactly(name) }), notCase, {
44
+ label: `the milestone "${name}"`,
45
+ hint: notCase ? 'The page lists the open milestones: a closed one leaves it.' : 'The page lists the open milestones of the repository.',
46
+ timeout: budget(this),
47
+ });
48
+ });
49
+
50
+ /**
51
+ * Open a milestone of a repository by its name: its page, with its issues.
52
+ *
53
+ * Example #1: When I open the milestone "Sprint 1" of the repository "owner/webship-site"
54
+ * Example #2: When I open the milestone "Sprint 1"
55
+ * Example #3: And we open the milestone "Sprint 1" of the repository "owner/webship-site"
56
+ * Example #4: Given I open the milestone "Sprint 1"
57
+ * Example #5: When open the milestone "Sprint 1" of the repository "owner/webship-site"
58
+ *
59
+ */
60
+ When(/^(I |we )*open the milestone "([^"]*)"(?: of the repository "([^"]*)")?$/, async function (pronounCase, name, which) {
61
+ const repo = await repositoryOf(this, which);
62
+ const r = await api(this, 'GET', `/repos/${repo.path}/milestones?state=all&limit=50`);
63
+ if (r.status !== 200) throw apiFailure(`look for the milestone "${name}"`, r, 'The managing account must see the repository.');
64
+ const found = (r.data || []).find((m) => exactly(name).test(m.title));
65
+ if (!found) throw friendly({ message: `There is no milestone "${name}" in ${repo.path}.`, hint: 'The sample content has the milestone Sprint 1.' });
66
+ await open(this, `/${repo.path}/milestone/${found.id}`);
67
+ });
68
+
69
+ /**
70
+ * Assert that the milestone on screen lists (or does not list) an issue of this title among its open issues.
71
+ *
72
+ * Example #1: Then the milestone should list the issue "The greeting script says Helo instead of Hello"
73
+ * Example #2: Then the milestone should not list the issue "The usage line spells greeting as greting"
74
+ * Example #3: And the milestone should list the issue "Webship test sprint"
75
+ * Example #4: But the milestone should not list the issue "Webship test elsewhere"
76
+ * Example #5: Then the milestone should list the issue "Webship test sprint"
77
+ *
78
+ */
79
+ Then(/^the milestone should( not)? list the issue "([^"]*)"$/, async function (notCase, title) {
80
+ if (!/\/milestone\/\d+/.test(this.page.url())) throw friendly({ message: `No milestone is open (the page is ${this.page.url()}).`, hint: 'Open one first with When I open the milestone "…".' });
81
+ await assertPresence(this.page.locator('a[href*="/issues/"]').filter({ hasText: exactly(title) }), notCase, {
82
+ label: `the issue "${title}" in the milestone`,
83
+ hint: notCase ? 'A milestone lists its open issues.' : 'A milestone lists its open issues; put an issue in it with Given there is an issue "…" in the milestone "…".',
84
+ timeout: budget(this),
85
+ });
86
+ });