@webship-js/redmine-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,99 @@
1
+ 'use strict';
2
+
3
+ // Version step definitions: a version of a project (its page, the issues it holds and its state) and the roadmap of
4
+ // the project. They only read: an issue moves into a version through the site, not here.
5
+
6
+ const { When, Then } = require('@cucumber/cucumber');
7
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
8
+ const { budget, exactly, tidy, open, assertPresence, findProject, api, apiFailure } = require('./redmine-helpers');
9
+
10
+ /**
11
+ * Open the page of a version of a project, by its name: what it holds and its state.
12
+ *
13
+ * Example #1: When I open the version "Sprint 1" of the project "webship-site"
14
+ * Example #2: When I open the version "Sprint 1" of the project "Webship site"
15
+ * Example #3: And we open the version "Sprint 1" of the project "webship-site"
16
+ * Example #4: Given I open the version "Sprint 2" of the project "webship-site"
17
+ * Example #5: When open the version "Sprint 1" of the project "Webship site"
18
+ *
19
+ */
20
+ When(/^(I |we )*open the version "([^"]*)" of the project "([^"]*)"$/, async function (pronounCase, name, which) {
21
+ const project = await findProject(this, which);
22
+ this.redmine = Object.assign(this.redmine || {}, { project: project.identifier });
23
+ const r = await api(this, 'GET', `/projects/${project.identifier}/versions.json`);
24
+ if (r.status !== 200) throw apiFailure(`read the versions of ${project.name}`, r, 'The managing account must see the project\'s versions.');
25
+ const version = ((r.data && r.data.versions) || []).find((v) => exactly(name).test(v.name));
26
+ if (!version) throw friendly({ message: `${project.name} has no version "${name}".`, hint: 'The versions are in the project\'s settings (Versions) and on its roadmap.' });
27
+ await open(this, `/versions/${version.id}`);
28
+ });
29
+
30
+ /**
31
+ * Assert that the version on screen lists (or does not list) an issue, by its subject.
32
+ *
33
+ * Example #1: Then the version should list the issue "The greeting script says Helo instead of Hello"
34
+ * Example #2: Then the version should not list the issue "The usage page spells greeting as greting"
35
+ * Example #3: And the version should list the issue "Webship test task"
36
+ * Example #4: But the version should not list the issue "Webship test task"
37
+ * Example #5: Then the version should list the issue "The greeting script says Helo instead of Hello"
38
+ *
39
+ */
40
+ Then(/^the version should (not )?list the issue "([^"]*)"$/, async function (notCase, subject) {
41
+ await assertPresence(this.page.locator('h2').first(), null, { label: 'a version', hint: 'Open one first with When I open the version "…" of the project "…".', timeout: budget(this) });
42
+ await assertPresence(this.page.locator('table.related-issues tr.issue').filter({ hasText: subject }), notCase, {
43
+ label: `the issue "${subject}" in the version`,
44
+ hint: notCase ? 'An issue leaves a version when its target version changes.' : 'An issue is in a version when its Target version names it.',
45
+ timeout: budget(this),
46
+ });
47
+ });
48
+
49
+ /**
50
+ * Assert the state the version on screen shows ("open", "locked", "closed").
51
+ *
52
+ * Example #1: Then the version should be "open"
53
+ * Example #2: Then the version should be "closed"
54
+ * Example #3: And the version should be "locked"
55
+ * Example #4: But the version should be "open"
56
+ * Example #5: Then the version should be "open"
57
+ *
58
+ */
59
+ Then(/^the version should be "([^"]*)"$/, async function (state) {
60
+ const badge = this.page.locator('#content .badge[class*="badge-status-"]').first();
61
+ await assertPresence(badge, null, { label: 'the state of the version', hint: 'Open the version first with When I open the version "…" of the project "…".', timeout: budget(this) });
62
+ // Its text, not as the page draws it: the badge is set in capitals.
63
+ const shown = tidy(await badge.textContent());
64
+ if (!exactly(state).test(shown)) throw friendly({ message: `Expected the version to be "${state}", but it shows "${shown}".`, hint: 'A version is open, locked or closed.' });
65
+ });
66
+
67
+ /**
68
+ * Open the roadmap of a project: its open versions.
69
+ *
70
+ * Example #1: When I open the roadmap of the project "webship-site"
71
+ * Example #2: When I open the roadmap of the project "Webship site"
72
+ * Example #3: And we open the roadmap of the project "webship-site"
73
+ * Example #4: Given I open the roadmap of the project "webship-site"
74
+ * Example #5: When open the roadmap of the project "Webship site"
75
+ *
76
+ */
77
+ When(/^(I |we )*open the roadmap of the project "([^"]*)"$/, async function (pronounCase, which) {
78
+ const project = await findProject(this, which);
79
+ this.redmine = Object.assign(this.redmine || {}, { project: project.identifier });
80
+ await open(this, `/projects/${project.identifier}/roadmap`);
81
+ });
82
+
83
+ /**
84
+ * Assert that the roadmap on screen lists (or does not list) a version, by its name.
85
+ *
86
+ * Example #1: Then the roadmap should list the version "Sprint 1"
87
+ * Example #2: Then the roadmap should not list the version "Sprint 0"
88
+ * Example #3: And the roadmap should list the version "Sprint 1"
89
+ * Example #4: But the roadmap should not list the version "Webship test version"
90
+ * Example #5: Then the roadmap should list the version "Sprint 1"
91
+ *
92
+ */
93
+ Then(/^the roadmap should (not )?list the version "([^"]*)"$/, async function (notCase, name) {
94
+ await assertPresence(this.page.locator('article.version-article h3 a').filter({ hasText: exactly(name) }), notCase, {
95
+ label: `the version "${name}" on the roadmap`,
96
+ hint: notCase ? 'A completed or closed version leaves the roadmap (unless its completed versions are shown).' : 'The roadmap lists the project\'s open versions; open it first with When I open the roadmap of the project "…".',
97
+ timeout: budget(this),
98
+ });
99
+ });