@webship-js/leantime-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,185 @@
1
+ 'use strict';
2
+
3
+ // Logging in and out, the session's account, and who may open a project.
4
+ //
5
+ // The site logs in with an e-mail address and a password on one form (/auth/login), and out at /auth/logout. The
6
+ // session's account is read from the site's own API, so a step never guesses it from the page. A project is opened by
7
+ // its name; an account that is not in its team is refused it.
8
+
9
+ const { Given, When, Then, After, AfterAll } = require('@cucumber/cucumber');
10
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
11
+ const h = require('./leantime-helpers');
12
+
13
+ /**
14
+ * Log in as an account of the users registry (cucumber.js, worldParameters.users), or keep its session when it is the
15
+ * browser's already.
16
+ *
17
+ * Example #1: Given I am a logged in user with the "member" user
18
+ * Example #2: Given we are a logged in user with the "owner" user
19
+ * Example #3: And I am a logged in user with the "member" user
20
+ * Example #4: And we are a logged in user with the "owner" user
21
+ * Example #5: Given we are a logged in user with the "member" user
22
+ */
23
+ Given(/^(I am|we are) a logged in user with the "([^"]*)" user$/, async function (_who, handle) {
24
+ await h.signInAs(this, handle);
25
+ });
26
+
27
+ /**
28
+ * Log in through the form as an account of the users registry: a new session, whatever the browser held.
29
+ *
30
+ * Example #1: When I log in with the "member" user
31
+ * Example #2: When log in with the "reader" user
32
+ * Example #3: And I log in with the "member" user
33
+ * Example #4: And log in with the "reader" user
34
+ * Example #5: When we log in with the "member" user
35
+ */
36
+ When(/^(I |we )*log in with the "([^"]*)" user$/, async function (_who, handle) {
37
+ const user = h.resolveUser(this, handle);
38
+ await h.dropSession(this);
39
+ await h.submitLogin(this, user.username, user.password);
40
+ const same = (email) => String(email).toLowerCase() === String(user.username).toLowerCase();
41
+ const result = await h.waitForValue(() => h.currentUser(this), same, h.budget(this));
42
+ if (!result.ok) throw friendly({ message: `Logging in as "${handle}" (${user.username}) did not work; the page is ${this.page.url()}.`, hint: 'Check the account\'s e-mail address and password in worldParameters.users of cucumber.js.' });
43
+ await h.closeTour(this);
44
+ });
45
+
46
+ /**
47
+ * Log in through the form with an e-mail address and a password that need not be right: the step asserts nothing, a
48
+ * refusal is read by the steps after it.
49
+ *
50
+ * Example #1: When I log in as "member@example.com" with the password "not-the-right-password"
51
+ * Example #2: When log in as "nobody@example.com" with the password "dD.123123ddd"
52
+ * Example #3: And I log in as "member@example.com" with the password "not-the-right-password"
53
+ * Example #4: And log in as "nobody@example.com" with the password "dD.123123ddd"
54
+ * Example #5: When we log in as "member@example.com" with the password "not-the-right-password"
55
+ */
56
+ When(/^(I |we )*log in as "([^"]*)" with the password "([^"]*)"$/, async function (_who, email, password) {
57
+ await h.dropSession(this);
58
+ await h.submitLogin(this, email, password);
59
+ });
60
+
61
+ /**
62
+ * Start without a session: the browser holds none of the site's.
63
+ *
64
+ * Example #1: Given I am not logged in
65
+ * Example #2: Given we are not logged in
66
+ * Example #3: And I am not logged in
67
+ * Example #4: And we are not logged in
68
+ * Example #5: When I am not logged in
69
+ */
70
+ Given(/^(I am|we are) not logged in$/, async function (_who) {
71
+ await h.dropSession(this);
72
+ });
73
+
74
+ /**
75
+ * Log out, the way the site does it (its logout address), and wait until the session is gone.
76
+ *
77
+ * Example #1: When I log out
78
+ * Example #2: When we log out
79
+ * Example #3: And I log out
80
+ * Example #4: And we log out
81
+ * Example #5: Then I log out
82
+ */
83
+ When(/^(I |we )*log out$/, async function (_who) {
84
+ await h.open(this, '/auth/logout');
85
+ const gone = await h.waitForValue(() => h.currentUser(this), (email) => email === '', h.budget(this));
86
+ if (!gone.ok) throw friendly({ message: `Logging out did not end the session of ${gone.value}.`, hint: 'The site logs out at /auth/logout and goes back to its login form.' });
87
+ });
88
+
89
+ /**
90
+ * The browser's session is an account's: its e-mail address, or its whole name as the site shows it.
91
+ *
92
+ * Example #1: Then I should be logged in as "Member Test"
93
+ * Example #2: Then I should be logged in as "member@example.com"
94
+ * Example #3: And I should be logged in as "Member Test"
95
+ * Example #4: But I should be logged in as "member@example.com"
96
+ * Example #5: Then we should be logged in as "Member Test"
97
+ */
98
+ Then(/^(I |we )*should be logged in as "([^"]*)"$/, async function (_who, who) {
99
+ const wanted = String(who).trim().toLowerCase();
100
+ const result = await h.waitForValue(() => h.currentAccount(this), (me) => !!me && (me.email.toLowerCase() === wanted || me.full.toLowerCase() === wanted), h.budget(this));
101
+ if (!result.ok) {
102
+ const me = result.value;
103
+ throw friendly({ message: `Expected to be logged in as "${who}", but ${me ? `the session is ${me.full} (${me.email})` : 'there is no session'}.`, hint: 'Name the account by its e-mail address or by its whole name, as the site shows it.' });
104
+ }
105
+ });
106
+
107
+ /**
108
+ * The browser holds no session of the site's.
109
+ *
110
+ * Example #1: Then I should not be logged in
111
+ * Example #2: Then we should not be logged in
112
+ * Example #3: And I should not be logged in
113
+ * Example #4: But we should not be logged in
114
+ * Example #5: Given I should not be logged in
115
+ */
116
+ Then(/^(I |we )*should not be logged in$/, async function (_who) {
117
+ const result = await h.waitForValue(() => h.currentUser(this), (email) => email === '', h.budget(this));
118
+ if (!result.ok) throw friendly({ message: `Expected no session, but the session is ${result.value}'s.`, hint: 'Log out first, or start with Given I am not logged in.' });
119
+ });
120
+
121
+ /**
122
+ * The login form came back with the site's message: the account was refused.
123
+ *
124
+ * Example #1: Then the login should be refused with "Username or password incorrect"
125
+ * Example #2: Then the login should be refused with "incorrect"
126
+ * Example #3: And the login should be refused with "Username or password incorrect"
127
+ * Example #4: But the login should be refused with "incorrect"
128
+ * Example #5: Given the login should be refused with "Username or password incorrect"
129
+ */
130
+ Then(/^the login should be refused with "([^"]*)"$/, async function (message) {
131
+ const page = this.page;
132
+ const form = page.locator('input[name="password"]');
133
+ await h.assertPresence(form, null, { label: 'the login form', hint: 'A refused login comes back to the form at /auth/login.', timeout: h.budget(this) });
134
+ const said = page.getByText(new RegExp(h.escapeRegExp(message), 'i'));
135
+ await h.assertPresence(said, null, { label: `the message "${message}"`, hint: 'The site says "Username or password incorrect!" under the form.', timeout: h.budget(this) });
136
+ });
137
+
138
+ /**
139
+ * Open a project by its name: its tasks, on its own page.
140
+ *
141
+ * Example #1: When I open the project "Webship site"
142
+ * Example #2: When we open the project "Webship site"
143
+ * Example #3: And I open the project "Webship site"
144
+ * Example #4: And we open the project "Webship site"
145
+ * Example #5: Then I open the project "Webship site"
146
+ */
147
+ When(/^(I |we )*open the project "([^"]*)"$/, async function (_who, name) {
148
+ const project = await h.findProject(this, name);
149
+ this.leantime = this.leantime || {};
150
+ this.leantime.project = project.name;
151
+ await h.open(this, `/projects/changeCurrentProject/${project.id}`);
152
+ await h.open(this, '/tickets/showAll');
153
+ });
154
+
155
+ /**
156
+ * The browser's account is refused a project: the site does not open it for an account that is not in its team.
157
+ *
158
+ * Example #1: Then I should be refused the project "Webship site"
159
+ * Example #2: Then we should be refused the project "Webship site"
160
+ * Example #3: And I should be refused the project "Webship site"
161
+ * Example #4: But we should be refused the project "Webship site"
162
+ * Example #5: Given I should be refused the project "Webship site"
163
+ */
164
+ Then(/^(I |we )*should be refused the project "([^"]*)"$/, async function (_who, name) {
165
+ const project = await h.findProject(this, name);
166
+ const r = await h.rpcWith(this.context.request, h.siteRoot(this), 'Tickets.Tickets.getAll', { searchCriteria: { currentProject: Number(project.id), excludeType: 'milestone' }, limit: 5 });
167
+ const rows = Array.isArray(r.result) ? r.result : [];
168
+ if (rows.length) throw friendly({ message: `Expected the project "${name}" to be refused, but the account reads ${rows.length} of its tasks.`, hint: 'An account in the project\'s team may open it; only one outside the team is refused.' });
169
+ await h.open(this, `/projects/changeCurrentProject/${project.id}`);
170
+ const opened = await this.page.getByText(project.name, { exact: true }).first().isVisible().catch(() => false);
171
+ const tasks = await this.page.locator('a[href*="/tickets/showTicket/"]').count().catch(() => 0);
172
+ if (opened && tasks) throw friendly({ message: `Expected the project "${name}" to be refused, but its page shows ${tasks} task link(s).`, hint: 'An account outside the project\'s team should not see its tasks.' });
173
+ });
174
+
175
+ // A scenario's tasks go after it, as the managing account, so a run leaves the site as it found it.
176
+ After(async function () {
177
+ const made = this.leantime && this.leantime.made;
178
+ if (!made || !made.size) return;
179
+ for (const id of made) await h.removeTask(this, id).catch(() => {});
180
+ made.clear();
181
+ });
182
+
183
+ AfterAll(async function () {
184
+ await h.managerContexts.dispose();
185
+ });
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ // The sprints of a project: a sprint's tasks, on the project's task list filtered to it.
4
+
5
+ const { When, Then } = require('@cucumber/cucumber');
6
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
7
+ const h = require('./leantime-helpers');
8
+
9
+ /**
10
+ * Open a sprint of a project: the project's task list, of that sprint only.
11
+ *
12
+ * Example #1: When I open the sprint "Sprint 1" of the project "Webship site"
13
+ * Example #2: When we open the sprint "Sprint 1" of the project "Webship site"
14
+ * Example #3: And I open the sprint "Sprint 1" of the project "Webship site"
15
+ * Example #4: And we open the sprint "Sprint 1" of the project "Webship site"
16
+ * Example #5: Then I open the sprint "Sprint 1" of the project "Webship site"
17
+ */
18
+ When(/^(I |we )*open the sprint "([^"]*)" of the project "([^"]*)"$/, async function (_who, sprintName, projectName) {
19
+ const project = await h.findProject(this, projectName);
20
+ const sprint = await h.findSprint(this, project, sprintName);
21
+ this.leantime = this.leantime || {};
22
+ this.leantime.project = project.name;
23
+ this.leantime.sprint = sprint;
24
+ await h.open(this, `/projects/changeCurrentProject/${project.id}`);
25
+ await h.open(this, `/tickets/showAll?sprint=${sprint.id}`);
26
+ });
27
+
28
+ /**
29
+ * The open sprint lists (or does not list) a task of this title.
30
+ *
31
+ * Example #1: Then the sprint should list the task "The greeting script says Helo instead of Hello"
32
+ * Example #2: Then the sprint should not list the task "The usage line spells greeting as greting"
33
+ * Example #3: And the sprint should list the task "The greeting script says Helo instead of Hello"
34
+ * Example #4: But the sprint should not list the task "The usage line spells greeting as greting"
35
+ * Example #5: Given the sprint should list the task "The greeting script says Helo instead of Hello"
36
+ */
37
+ Then(/^the sprint should (not )?list the task "([^"]*)"$/, async function (notCase, title) {
38
+ const sprint = this.leantime && this.leantime.sprint;
39
+ if (!sprint) throw friendly({ message: 'No sprint is open.', hint: 'Open one first: When I open the sprint "…" of the project "…".' });
40
+ const row = this.page.locator('table tbody tr', { has: this.page.locator('a[href*="/tickets/showTicket/"]', { hasText: h.exactly(title) }) });
41
+ await h.assertPresence(row, notCase, { label: `the task "${title}" in the sprint ${sprint.name}`, hint: 'The sprint\'s list shows the tasks put in that sprint.', timeout: h.budget(this) });
42
+ });
@@ -0,0 +1,337 @@
1
+ 'use strict';
2
+
3
+ // The tasks of a project: a task made or removed for a scenario, the task list, a new task, and one task in its
4
+ // window (its status, its comments, its assignee, the time logged on it, who made it), and what an account that may
5
+ // not change a task cannot do.
6
+ //
7
+ // A task opens in a window of the page, which the steps find by the task's own address (its form sends to
8
+ // /tickets/showTicket/<number>), never by its order. What a step changes is read back from the site's own API.
9
+
10
+ const { Given, When, Then } = require('@cucumber/cucumber');
11
+ const { friendly, smartSettle } = require('webship-js/tests/step-definitions/webship');
12
+ const h = require('./leantime-helpers');
13
+
14
+ /**
15
+ * A task of this title is in the project, made for the scenario by the managing account when it is not there yet; a
16
+ * task the step makes goes after the scenario. The project of cucumber.js when the step names none.
17
+ *
18
+ * Example #1: Given there is a task "Webship test site" in the project "Webship site"
19
+ * Example #2: Given there is a task "Webship test a task"
20
+ * Example #3: And there is a task "Webship test site" in the project "Webship site"
21
+ * Example #4: And there is a task "Webship test a task"
22
+ * Example #5: When there is a task "Webship test site" in the project "Webship site"
23
+ */
24
+ Given(/^there is a task "([^"]*)"(?: in the project "([^"]*)")?$/, async function (title, projectName) {
25
+ const project = await h.findProject(this, projectName);
26
+ this.leantime = this.leantime || {};
27
+ this.leantime.project = project.name;
28
+ const found = await h.findTasks(this, project, title);
29
+ if (!found.length) await h.makeTask(this, project, title);
30
+ });
31
+
32
+ /**
33
+ * No task of this title is in the project: the managing account removes the ones there are.
34
+ *
35
+ * Example #1: Given there is no task "Webship test new" in the project "Webship site"
36
+ * Example #2: Given there is no task "Webship test new"
37
+ * Example #3: And there is no task "Webship test new" in the project "Webship site"
38
+ * Example #4: And there is no task "Webship test new"
39
+ * Example #5: When there is no task "Webship test new" in the project "Webship site"
40
+ */
41
+ Given(/^there is no task "([^"]*)"(?: in the project "([^"]*)")?$/, async function (title, projectName) {
42
+ const project = await h.findProject(this, projectName);
43
+ this.leantime = this.leantime || {};
44
+ this.leantime.project = project.name;
45
+ for (const t of await h.findTasks(this, project, title)) await h.removeTask(this, t.id);
46
+ });
47
+
48
+ /**
49
+ * The task list of the open project shows (or does not show) a task of this title.
50
+ *
51
+ * Example #1: Then the task list should show "The greeting script says Helo instead of Hello"
52
+ * Example #2: Then the task list should not show "Webship test new"
53
+ * Example #3: And the task list should show "The greeting script says Helo instead of Hello"
54
+ * Example #4: But the task list should not show "Webship test new"
55
+ * Example #5: Given the task list should show "The greeting script says Helo instead of Hello"
56
+ */
57
+ Then(/^the task list should (not )?show "([^"]*)"$/, async function (notCase, title) {
58
+ if (!/\/tickets\/show(All|Kanban)/.test(this.page.url())) await h.open(this, '/tickets/showAll');
59
+ const link = this.page.locator('a[href*="/tickets/showTicket/"]', { hasText: h.exactly(title) });
60
+ await h.assertPresence(link, notCase, { label: `the task "${title}" in the list`, hint: 'Open the project first: When I open the project "…". The list shows the project\'s tasks that are not done.', timeout: h.budget(this) });
61
+ });
62
+
63
+ /**
64
+ * Make a task on the project's board, the way a person does: Add To-Do, its title, Enter. It goes after the scenario.
65
+ *
66
+ * Example #1: When I create a task "Webship test new" in the project "Webship site"
67
+ * Example #2: When we create a task "Webship test new"
68
+ * Example #3: And I create a task "Webship test new" in the project "Webship site"
69
+ * Example #4: And we create a task "Webship test new"
70
+ * Example #5: When we create a task "Webship test new" in the project "Webship site"
71
+ */
72
+ When(/^(I |we )*create a task "([^"]*)"(?: in the project "([^"]*)")?$/, async function (_who, title, projectName) {
73
+ const project = await h.findProject(this, projectName || (this.leantime && this.leantime.project));
74
+ this.leantime = this.leantime || {};
75
+ this.leantime.project = project.name;
76
+ await h.open(this, `/projects/changeCurrentProject/${project.id}`);
77
+ await h.open(this, '/tickets/showKanban');
78
+ await h.actOrExplain('make the task', title, async () => {
79
+ await this.page.locator('a:visible', { hasText: /^\s*Add To-Do\s*$/ }).first().click();
80
+ const field = this.page.locator('input.quickAddInput:visible').first();
81
+ await field.waitFor({ state: 'visible', timeout: h.budget(this) });
82
+ await field.fill(title);
83
+ await field.press('Enter');
84
+ }, 'The board offers "Add To-Do" to an Editor or above of the project; a Commenter and a Read Only person get none.');
85
+ await smartSettle(this.page, 2000);
86
+ const made = await h.waitForValue(() => h.findTasks(this, project, title), (list) => list.length > 0, h.budget(this));
87
+ if (!made.ok) throw friendly({ message: `The task "${title}" was not made in ${project.name}.`, hint: 'The board makes a task when its title is entered in "Add To-Do".' });
88
+ for (const t of made.value) h.remember(this, t.id);
89
+ });
90
+
91
+ /**
92
+ * Open a task of the project by its title (or its number, as "#1"), in its window. A window of help the board shows
93
+ * once a session is closed first, and the task asked for again when one came over it: the step may take up to two
94
+ * minutes on a slow site.
95
+ *
96
+ * Example #1: When I open the task "The greeting script says Helo instead of Hello"
97
+ * Example #2: When we open the task "#1"
98
+ * Example #3: And I open the task "The greeting script says Helo instead of Hello"
99
+ * Example #4: And we open the task "#1"
100
+ * Example #5: When we open the task "The greeting script says Helo instead of Hello"
101
+ */
102
+ When(/^(I |we )*open the task "([^"]*)"$/, { timeout: 120 * 1000 }, async function (_who, title) {
103
+ const task = await h.taskNamed(this, title);
104
+ await h.openTask(this, task);
105
+ });
106
+
107
+ /**
108
+ * Set the open task's status, as its window offers it, and save the task.
109
+ *
110
+ * Example #1: When I set the status of the task to "In Progress"
111
+ * Example #2: When we set the status of the task to "Done"
112
+ * Example #3: And I set the status of the task to "In Progress"
113
+ * Example #4: And we set the status of the task to "Done"
114
+ * Example #5: When we set the status of the task to "In Progress"
115
+ */
116
+ When(/^(I |we )*set the status of the task to "([^"]*)"$/, async function (_who, status) {
117
+ await h.pickInTask(this, 'status', status);
118
+ await h.saveTask(this);
119
+ });
120
+
121
+ /**
122
+ * The open task's status, as the site has it now.
123
+ *
124
+ * Example #1: Then the status of the task should be "In Progress"
125
+ * Example #2: Then the status of the task should be "New"
126
+ * Example #3: And the status of the task should be "In Progress"
127
+ * Example #4: But the status of the task should be "New"
128
+ * Example #5: Given the status of the task should be "In Progress"
129
+ */
130
+ Then(/^the status of the task should be "([^"]*)"$/, async function (status) {
131
+ const task = await h.taskNow(this);
132
+ const labels = await h.api(this, 'Tickets.Tickets.getStatusLabels', { projectId: Number(task.projectId) }, 'read the project\'s statuses');
133
+ const read = async () => { const t = await h.taskNow(this); const l = labels[String(t.status)]; return l ? String(l.name) : String(t.status); };
134
+ const result = await h.waitForValue(read, (name) => h.exactly(status).test(name), h.budget(this));
135
+ if (!result.ok) throw friendly({ message: `Expected the task's status to be "${status}", but it is "${result.value}".`, hint: 'Name a status as the task\'s window shows it (New, In Progress, Done…).' });
136
+ });
137
+
138
+ /**
139
+ * Add a comment to the open task, from its Discussion.
140
+ *
141
+ * Example #1: When I add the comment "Checked on the test site" to the task
142
+ * Example #2: When we add the comment "A word on it" to the task
143
+ * Example #3: And I add the comment "Checked on the test site" to the task
144
+ * Example #4: And we add the comment "A word on it" to the task
145
+ * Example #5: When we add the comment "Checked on the test site" to the task
146
+ */
147
+ When(/^(I |we )*add the comment "([^"]*)" to the task$/, async function (_who, text) {
148
+ const win = h.taskWindow(this);
149
+ await h.actOrExplain('add the comment', text, async () => {
150
+ await win.getByText('Add a new comment', { exact: true }).first().click();
151
+ const editor = win.locator('.ProseMirror:visible').last();
152
+ await editor.waitFor({ state: 'visible', timeout: h.budget(this) });
153
+ await editor.click();
154
+ await this.page.keyboard.type(text);
155
+ await win.locator('input[type="submit"][name="comment"]:visible').last().click();
156
+ }, 'A task\'s Discussion offers "Add a new comment" to a Commenter or above of the project; a Read Only person gets none.');
157
+ await smartSettle(this.page, 2000);
158
+ });
159
+
160
+ /**
161
+ * The open task shows a comment with this text, by this person (their whole name) when the step names one.
162
+ *
163
+ * Example #1: Then the task should show the comment "Checked on the test site" by "Member Test"
164
+ * Example #2: Then the task should show the comment "Checked on the test site"
165
+ * Example #3: And the task should show the comment "Checked on the test site" by "Member Test"
166
+ * Example #4: But the task should show the comment "Checked on the test site"
167
+ * Example #5: Given the task should show the comment "Checked on the test site" by "Member Test"
168
+ */
169
+ Then(/^the task should show the comment "([^"]*)"(?: by "([^"]*)")?$/, async function (text, by) {
170
+ const id = h.openTaskId(this);
171
+ const read = async () => {
172
+ const list = await h.api(this, 'Comments.Comments.getComments', { module: 'ticket', entityId: Number(id) }, `read the comments of #${id}`);
173
+ return (Array.isArray(list) ? list : []).map((c) => ({ text: h.tidy(String(c.text || '').replace(/<[^>]*>/g, ' ')), by: h.tidy(`${c.firstname || ''} ${c.lastname || ''}`) }));
174
+ };
175
+ const result = await h.waitForValue(read, (list) => list.some((c) => c.text.includes(text) && (!by || h.exactly(by).test(c.by))), h.budget(this));
176
+ if (!result.ok) throw friendly({ message: `Expected the task #${id} to show the comment "${text}"${by ? ` by ${by}` : ''}. Its comments: ${(result.value || []).map((c) => `"${c.text}" by ${c.by}`).join('; ') || 'none'}.`, hint: 'Name the comment\'s author by their whole name, as the site shows it.' });
177
+ const shown = h.taskWindow(this).getByText(text).first();
178
+ await h.assertPresence(shown, null, { label: `the comment "${text}" in the task's window`, hint: 'The comment is the site\'s, but its window does not show it: open the task again.', timeout: h.budget(this) }).catch(async () => {
179
+ await h.openTask(this, await h.taskNamed(this, `#${id}`));
180
+ await h.assertPresence(h.taskWindow(this).getByText(text).first(), null, { label: `the comment "${text}" in the task's window`, hint: 'The task\'s Discussion lists its comments.', timeout: h.budget(this) });
181
+ });
182
+ });
183
+
184
+ /**
185
+ * Assign the open task to someone of the project's team, by their whole name, and save the task.
186
+ *
187
+ * Example #1: When I assign the task to "Member Test"
188
+ * Example #2: When we assign the task to "Owner Test"
189
+ * Example #3: And I assign the task to "Member Test"
190
+ * Example #4: And we assign the task to "Owner Test"
191
+ * Example #5: When we assign the task to "Member Test"
192
+ */
193
+ When(/^(I |we )*assign the task to "([^"]*)"$/, async function (_who, name) {
194
+ await h.pickInTask(this, 'editorId', name);
195
+ await h.saveTask(this);
196
+ });
197
+
198
+ /**
199
+ * The open task's assignee, as the site has it now (their whole name).
200
+ *
201
+ * Example #1: Then the task should be assigned to "Member Test"
202
+ * Example #2: Then the task should be assigned to "Owner Test"
203
+ * Example #3: And the task should be assigned to "Member Test"
204
+ * Example #4: But the task should be assigned to "Owner Test"
205
+ * Example #5: Given the task should be assigned to "Member Test"
206
+ */
207
+ Then(/^the task should be assigned to "([^"]*)"$/, async function (name) {
208
+ const read = async () => { const t = await h.taskNow(this); return h.tidy(`${t.editorFirstname || ''} ${t.editorLastname || ''}`); };
209
+ const result = await h.waitForValue(read, (who) => h.exactly(name).test(who), h.budget(this));
210
+ if (!result.ok) throw friendly({ message: `Expected the task to be assigned to "${name}", but it is assigned to ${result.value || 'nobody'}.`, hint: 'Name the person by their whole name, as the site shows it.' });
211
+ });
212
+
213
+ /**
214
+ * Log time on the open task, from its Time Tracking: the hours, and a note.
215
+ *
216
+ * Example #1: When I log "1.5" hours on the task with the note "Looked into it"
217
+ * Example #2: When we log "2" hours on the task with the note "Fixed the greeting"
218
+ * Example #3: And I log "1.5" hours on the task with the note "Looked into it"
219
+ * Example #4: And we log "2" hours on the task with the note "Fixed the greeting"
220
+ * Example #5: When we log "1.5" hours on the task with the note "Looked into it"
221
+ */
222
+ When(/^(I |we )*log "([0-9]+(?:\.[0-9]+)?)" hours on the task with the note "([^"]*)"$/, async function (_who, hours, note) {
223
+ const win = h.taskWindow(this);
224
+ await h.actOrExplain('log time on the task', `${hours} h`, async () => {
225
+ await win.locator('a[href="#timesheet"]').first().click();
226
+ const form = win.locator('form[action*="#timesheet"]').first();
227
+ await form.locator('input[name="hours"]').waitFor({ state: 'visible', timeout: h.budget(this) });
228
+ await form.locator('input[name="hours"]').fill(hours);
229
+ await form.locator('textarea[name="description"]').fill(note);
230
+ await form.locator('input[type="submit"][name="saveTimes"]').click();
231
+ }, 'A task\'s Time Tracking takes hours from an Editor or above of the project; a Commenter and a Read Only person have no such tab.');
232
+ await smartSettle(this.page, 2000);
233
+ });
234
+
235
+ /**
236
+ * The open task holds this much logged time in all, as the site counts it.
237
+ *
238
+ * Example #1: Then the task should have "1.5" hours logged
239
+ * Example #2: Then the task should have "3" hours logged
240
+ * Example #3: And the task should have "1.5" hours logged
241
+ * Example #4: But the task should have "3" hours logged
242
+ * Example #5: Given the task should have "1.5" hours logged
243
+ */
244
+ Then(/^the task should have "([0-9]+(?:\.[0-9]+)?)" hours logged$/, async function (hours) {
245
+ const id = h.openTaskId(this);
246
+ const read = async () => Number(await h.api(this, 'Timesheets.Timesheets.getSumLoggedHoursForTicket', { ticketId: Number(id) }, `read the time logged on #${id}`)) || 0;
247
+ const result = await h.waitForValue(read, (sum) => Math.abs(sum - Number(hours)) < 0.001, h.budget(this));
248
+ if (!result.ok) throw friendly({ message: `Expected ${hours} hours logged on the task #${id}, but it has ${result.value}.`, hint: 'The time of every person counts.' });
249
+ });
250
+
251
+ /**
252
+ * The open task was made by this person, as its window says ("Created by …").
253
+ *
254
+ * Example #1: Then the task should be created by "Owner"
255
+ * Example #2: Then the task should be created by "Member Test"
256
+ * Example #3: And the task should be created by "Owner"
257
+ * Example #4: But the task should be created by "Member Test"
258
+ * Example #5: Given the task should be created by "Owner"
259
+ */
260
+ Then(/^the task should be created by "([^"]*)"$/, async function (name) {
261
+ const t = await h.taskNow(this);
262
+ const full = h.tidy(`${t.userFirstname || ''} ${t.userLastname || ''}`);
263
+ if (!(h.exactly(name).test(full) || h.exactly(name).test(String(t.userFirstname || '')))) throw friendly({ message: `Expected the task to be created by "${name}", but it was created by ${full || 'nobody'}.`, hint: 'Name the person by their first name or their whole name.' });
264
+ const header = h.taskWindow(this).getByText(new RegExp(`Created by\\s+${h.escapeRegExp(String(t.userFirstname || name))}`, 'i')).first();
265
+ await h.assertPresence(header, null, { label: `"Created by ${t.userFirstname}" in the task's window`, hint: 'The task\'s window says who made it under its title.', timeout: h.budget(this) });
266
+ });
267
+
268
+ /**
269
+ * The browser's account may not change the open task: its Save buttons and its lists are disabled.
270
+ *
271
+ * Example #1: Then I should not be able to change the task
272
+ * Example #2: Then we should not be able to change the task
273
+ * Example #3: And I should not be able to change the task
274
+ * Example #4: But we should not be able to change the task
275
+ * Example #5: Given I should not be able to change the task
276
+ */
277
+ Then(/^(I |we )*should not be able to change the task$/, async function (_who) {
278
+ const win = h.taskWindow(this);
279
+ const save = win.locator('input[name="saveTicket"]').first();
280
+ await save.waitFor({ state: 'attached', timeout: h.budget(this) });
281
+ const states = await win.evaluate((root) => ({
282
+ save: [...root.querySelectorAll('input[name="saveTicket"], input[name="saveAndCloseTicket"]')].map((i) => i.disabled),
283
+ assignee: [...root.querySelectorAll('select[name="editorId"]')].map((s) => s.disabled),
284
+ }));
285
+ if (!states.save.length || states.save.some((d) => !d) || states.assignee.some((d) => !d)) throw friendly({ message: 'Expected the task to be closed to this account, but its window lets it save the task.', hint: 'A Commenter and a Read Only person get the task\'s window with its Save buttons and lists disabled.' });
286
+ });
287
+
288
+ /**
289
+ * The browser's account may not comment on the open task: its Discussion offers no new comment.
290
+ *
291
+ * Example #1: Then I should not be able to comment on the task
292
+ * Example #2: Then we should not be able to comment on the task
293
+ * Example #3: And I should not be able to comment on the task
294
+ * Example #4: But we should not be able to comment on the task
295
+ * Example #5: Given I should not be able to comment on the task
296
+ */
297
+ Then(/^(I |we )*should not be able to comment on the task$/, async function (_who) {
298
+ const win = h.taskWindow(this);
299
+ await win.getByText('Discussion', { exact: true }).first().waitFor({ state: 'visible', timeout: h.budget(this) }).catch(() => {});
300
+ const offered = await win.getByText('Add a new comment', { exact: true }).first().isVisible().catch(() => false);
301
+ if (offered) throw friendly({ message: 'Expected no way to comment on the task, but its Discussion offers "Add a new comment".', hint: 'A Read Only person reads a task\'s comments and adds none; a Commenter may comment.' });
302
+ });
303
+
304
+ /**
305
+ * The browser's account may not make a task in the project: its board offers no Add To-Do.
306
+ *
307
+ * Example #1: Then I should not be able to create a task in the project "Webship site"
308
+ * Example #2: Then we should not be able to create a task in the project "Webship site"
309
+ * Example #3: And I should not be able to create a task in the project "Webship site"
310
+ * Example #4: But we should not be able to create a task in the project "Webship site"
311
+ * Example #5: Given I should not be able to create a task in the project "Webship site"
312
+ */
313
+ Then(/^(I |we )*should not be able to create a task in the project "([^"]*)"$/, async function (_who, name) {
314
+ const project = await h.findProject(this, name);
315
+ await h.open(this, `/projects/changeCurrentProject/${project.id}`);
316
+ await h.open(this, '/tickets/showKanban');
317
+ const offered = await this.page.locator('a:visible', { hasText: /^\s*Add To-Do\s*$/ }).count();
318
+ if (offered) throw friendly({ message: `Expected no way to make a task in ${project.name}, but its board offers "Add To-Do".`, hint: 'An Editor or above makes tasks; a Commenter and a Read Only person do not.' });
319
+ });
320
+
321
+ /**
322
+ * The browser's account is refused a task: the site gives it no window and no data of it.
323
+ *
324
+ * Example #1: Then I should be refused the task "The greeting script says Helo instead of Hello"
325
+ * Example #2: Then we should be refused the task "#1"
326
+ * Example #3: And I should be refused the task "The greeting script says Helo instead of Hello"
327
+ * Example #4: But we should be refused the task "#1"
328
+ * Example #5: Then we should be refused the task "The greeting script says Helo instead of Hello"
329
+ */
330
+ Then(/^(I |we )*should be refused the task "([^"]*)"$/, async function (_who, title) {
331
+ const task = await h.taskNamed(this, title);
332
+ const r = await h.rpcWith(this.context.request, h.siteRoot(this), 'Tickets.Tickets.getTicket', { id: Number(task.id) });
333
+ if (r.result && typeof r.result === 'object') throw friendly({ message: `Expected the task #${task.id} to be refused, but the account reads it ("${r.result.headline}").`, hint: 'An account outside the project\'s team is refused its tasks.' });
334
+ await h.open(this, `/tickets/showKanban#/tickets/showTicket/${task.id}`);
335
+ const shown = await h.taskWindow(this, task.id).locator('input[name="headline"]').first().isVisible({ timeout: 3000 }).catch(() => false);
336
+ if (shown) throw friendly({ message: `Expected the task #${task.id} to be refused, but its window opened.`, hint: 'An account outside the project\'s team should get no window of its tasks.' });
337
+ });