@webship-js/bbpress-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,95 @@
1
+ 'use strict';
2
+
3
+ // The notifications the forums send by e-mail, read in the mail catcher of
4
+ // the test site (Mailpit, which every DDEV project has at port 8026;
5
+ // `worldParameters.mailUrl` names another): the mail of a reply to the
6
+ // subscribers of its topic, the mail of a new topic to the subscribers of its
7
+ // forum, and the absence of any.
8
+ //
9
+ // The forums send one mail per post to a no-reply address of the site, with
10
+ // the subscribers in Bcc, in the request that takes the post: once the page
11
+ // of the post is back, the mail is out. A step reads only the mail that
12
+ // arrived since the scenario began. The subject is "[<forum>] <topic>": a step
13
+ // matches a part of it, letter case aside. An address stands for itself, a
14
+ // handle of the users registry for the account's address.
15
+
16
+ const { Then } = require('@cucumber/cucumber');
17
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
18
+ const {
19
+ budget,
20
+ clean,
21
+ listed,
22
+ holds,
23
+ eventually,
24
+ addressOf,
25
+ mailTo,
26
+ mailText,
27
+ } = require('./bbpress-helpers');
28
+
29
+ /** The notification to an address whose subject holds a text; waits for it. */
30
+ async function notification(world, who, subject) {
31
+ const address = addressOf(world, who);
32
+ const all = await eventually(world, () => mailTo(world, address), (messages) => messages.some((m) => holds(m.Subject, subject)), (messages) => ({
33
+ message: `Expected a notification with "${subject}" in its subject to ${address}. ${(messages || []).length ? `Since the scenario began it got: ${listed((messages || []).map((m) => m.Subject))}` : 'Since the scenario began it got no mail'}.`,
34
+ hint: 'The forums notify the subscribers of a topic of each reply, and the subscribers of a forum of each new topic, but never the author of the post. The subject reads "[<forum>] <topic>".',
35
+ }), budget(world) * 3);
36
+ return all.find((m) => holds(m.Subject, subject));
37
+ }
38
+
39
+ /**
40
+ * Assert the forums sent a notification whose subject holds a text to an
41
+ * account (a handle of the users registry, or an address) since the scenario
42
+ * began; the step waits for it to arrive.
43
+ *
44
+ * Example #1: Then a forum notification with the subject "Webship test topic" should be sent to "participant"
45
+ * Example #2: And a forum notification with the subject "[Help and support]" should be sent to "participant"
46
+ * Example #3: Then a forum notification with the subject "Webship test question" should be sent to "moderator"
47
+ * Example #4: Then a forum notification with the subject "[General discussion] Webship test topic" should be sent to "participant@example.com"
48
+ * Example #5: And a forum notification with the subject "Webship test" should be sent to "keymaster"
49
+ */
50
+ Then(/^a forum notification with the subject "([^"]*)" should be sent to "([^"]*)"$/, async function (subject, who) {
51
+ await notification(this, who, subject);
52
+ });
53
+
54
+ /**
55
+ * Assert the forums sent no notification to an account since the scenario
56
+ * began. The forums send their mail in the request that takes a post, so the
57
+ * mail catcher is read at once.
58
+ *
59
+ * Example #1: Then no forum notification should be sent to "moderator"
60
+ * Example #2: And no forum notification should be sent to "participant"
61
+ * Example #3: Then no forum notification should be sent to "spectator"
62
+ * Example #4: Then no forum notification should be sent to "nobody@example.com"
63
+ * Example #5: But no forum notification should be sent to "keymaster"
64
+ */
65
+ Then(/^no forum notification should be sent to "([^"]*)"$/, async function (who) {
66
+ const address = addressOf(this, who);
67
+ const messages = await mailTo(this, address);
68
+ if (messages.length) {
69
+ throw friendly({
70
+ message: `Expected no notification to ${address}, but since the scenario began it got: ${listed(messages.map((m) => m.Subject))}.`,
71
+ hint: 'The step counts every mail to the address since the scenario began. The author of a post is never notified of it.',
72
+ });
73
+ }
74
+ });
75
+
76
+ /**
77
+ * Assert a notification whose subject holds a text, to an account, holds a
78
+ * text in its body: who wrote, what, the link of the post.
79
+ *
80
+ * Example #1: Then the forum notification with the subject "Webship test topic" to "participant" should contain "moderator wrote:"
81
+ * Example #2: And the forum notification with the subject "Webship test topic" to "participant" should contain "Webship test reply"
82
+ * Example #3: Then the forum notification with the subject "[Help and support]" to "participant" should contain "Topic Link:"
83
+ * Example #4: Then the forum notification with the subject "Webship test topic" to "participant" should contain "Post Link:"
84
+ * Example #5: And the forum notification with the subject "Webship test" to "participant@example.com" should contain "You are receiving this email because you subscribed to a forum topic."
85
+ */
86
+ Then(/^the forum notification with the subject "([^"]*)" to "([^"]*)" should contain "([^"]*)"$/, async function (subject, who, text) {
87
+ const mail = await notification(this, who, subject);
88
+ const body = await mailText(this, mail.ID);
89
+ if (!holds(body, text)) {
90
+ throw friendly({
91
+ message: `The notification "${clean(mail.Subject)}" does not contain "${text}". It reads: "${body.slice(0, 400)}".`,
92
+ hint: 'The text is matched as a part of the mail\'s text, letter case and white space aside.',
93
+ });
94
+ }
95
+ });
@@ -0,0 +1,413 @@
1
+ 'use strict';
2
+
3
+ // Moderation, from the links the forums offer a moderator on a post: close
4
+ // and open a topic, stick it (in its forum, or on top of every forum),
5
+ // unapprove and approve, spam, trash, restore and delete a topic or a reply,
6
+ // merge a topic into another, split a topic at a reply, move a reply, and
7
+ // move a topic to another forum.
8
+ //
9
+ // Each link loads the page again, and the forums say what they did through
10
+ // the post itself: its status (a class of the post) and the link, which turns
11
+ // into its opposite (Close into Open, Trash into Restore and Delete). A step
12
+ // follows the link, waits for the page, and checks that turn.
13
+
14
+ const { When, Then } = require('@cucumber/cucumber');
15
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
16
+ const {
17
+ FORUMS,
18
+ settle,
19
+ navigate,
20
+ supplied,
21
+ clean,
22
+ listed,
23
+ same,
24
+ clickAndLoad,
25
+ forumPage,
26
+ forumNotices,
27
+ readingTopic,
28
+ topicPosts,
29
+ postOnPage,
30
+ followPostLink,
31
+ } = require('./bbpress-helpers');
32
+
33
+ // What each action of a moderator is on the page: the link it follows (by the class the forums give it,
34
+ // for a topic and for a reply), the text that link must have, and the status the post has afterwards.
35
+ const ACTIONS = {
36
+ close: { links: ['bbp-topic-close-link'], text: /^close$/i, status: 'closed' },
37
+ open: { links: ['bbp-topic-close-link'], text: /^open$/i, status: 'publish' },
38
+ stick: { links: ['bbp-topic-sticky-link'], text: /^stick$/i },
39
+ unstick: { links: ['bbp-topic-sticky-link'], text: /^unstick$/i },
40
+ unapprove: { links: ['bbp-topic-approve-link', 'bbp-reply-approve-link'], text: /^unapprove$/i, status: 'pending' },
41
+ approve: { links: ['bbp-topic-approve-link', 'bbp-reply-approve-link'], text: /^approve$/i, status: 'publish' },
42
+ spam: { links: ['bbp-topic-spam-link', 'bbp-reply-spam-link'], text: /^spam$/i, status: 'spam' },
43
+ unspam: { links: ['bbp-topic-spam-link', 'bbp-reply-spam-link'], text: /^unspam$/i, status: 'publish' },
44
+ trash: { links: ['bbp-topic-trash-link', 'bbp-reply-trash-link'], text: /^trash$/i, status: 'trash' },
45
+ restore: { links: ['bbp-topic-restore-link', 'bbp-reply-restore-link'], text: /^restore$/i, status: 'publish' },
46
+ };
47
+
48
+ const STATUS_WORDS = { publish: 'open', closed: 'closed', pending: 'pending', spam: 'spam', trash: 'in the trash' };
49
+
50
+ /** Follow a moderation link of a post, and check the post took the status the action gives it. */
51
+ async function moderate(world, post, label, action) {
52
+ const spec = ACTIONS[action];
53
+ const link = post.links.find((l) => spec.links.includes(l.name));
54
+ if (!link || !spec.text.test(link.text)) {
55
+ throw friendly({
56
+ message: `Could not ${action} ${label}: it offers no "${action[0].toUpperCase()}${action.slice(1)}" link. It offers: ${listed(post.links.map((l) => l.text))}.`,
57
+ hint: `The post is ${STATUS_WORDS[post.status] || post.status}. The moderation links are offered to a moderator and a keymaster, and each turns into its opposite once followed.`,
58
+ });
59
+ }
60
+ await followPostLink(world, post, [link.name], `${action} ${label}`);
61
+ const after = (await topicPosts(world)).find((p) => p.id === post.id);
62
+ if (!after) {
63
+ throw friendly({ message: `After "${link.text}" the page no longer shows ${label} (${world.page.url()}).`, hint: 'The forums send a moderator back to the topic, with its hidden posts shown.' });
64
+ }
65
+ if (spec.status && after.status !== spec.status) {
66
+ throw friendly({
67
+ message: `Followed "${link.text}", but ${label} is ${STATUS_WORDS[after.status] || after.status}, not ${STATUS_WORDS[spec.status]}.`,
68
+ hint: 'The forums refuse a link whose security token is too old: open the topic again.',
69
+ });
70
+ }
71
+ if (!spec.status) {
72
+ const turned = after.links.find((l) => spec.links.includes(l.name));
73
+ if (!turned || spec.text.test(turned.text)) {
74
+ throw friendly({ message: `Followed "${link.text}", but the topic still offers "${turned ? turned.text : 'no such link'}".`, hint: 'A sticky topic offers Unstick, any other Stick.' });
75
+ }
76
+ }
77
+ }
78
+
79
+ /** The lead post of the topic that is open (on its first page), or fail. */
80
+ async function leadPost(world) {
81
+ await readingTopic(world);
82
+ const lead = (await topicPosts(world)).find((p) => p.lead);
83
+ if (!lead) {
84
+ throw friendly({ message: 'The page does not show the topic\'s own post, which carries the topic\'s links.', hint: 'Go to the first page of the topic: When I go to page 1.' });
85
+ }
86
+ return lead;
87
+ }
88
+
89
+ /** Choose an option of a list of a moderation form by its text (the forums indent the forums of a list). */
90
+ async function chooseOption(world, select, wanted, what) {
91
+ const options = await select.locator('option').evaluateAll((all) => all.map((o) => ({ value: o.value, text: o.textContent.replace(/ /g, ' ').replace(/\s+/g, ' ').trim(), disabled: o.disabled })));
92
+ const match = options.find((o) => same(o.text, wanted) && !o.disabled);
93
+ if (!match) {
94
+ throw friendly({
95
+ message: `The list has no ${what} "${wanted}". It has: ${listed(options.filter((o) => !o.disabled && o.value).map((o) => o.text))}.`,
96
+ hint: 'Merge, split and move offer the topics of the same forum; the edit form offers the forums the account may post in (a category is not one).',
97
+ });
98
+ }
99
+ await select.selectOption(match.value);
100
+ }
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // A topic
104
+ // ---------------------------------------------------------------------------
105
+
106
+ /**
107
+ * Follow a moderation link of the topic that is open: close or open it,
108
+ * stick or unstick it, unapprove or approve it, mark it as spam or not, put
109
+ * it in the trash or restore it. The step checks the topic took the state.
110
+ *
111
+ * Example #1: When I close the topic
112
+ * Example #2: And I open the topic
113
+ * Example #3: When I stick the topic
114
+ * Example #4: When we unapprove the topic
115
+ * Example #5: And I trash the topic
116
+ * Example #6: When I restore the topic
117
+ * Example #7: And we spam the topic
118
+ * Example #8: When I unspam the topic
119
+ * Example #9: And I approve the topic
120
+ * Example #10: When we unstick the topic
121
+ */
122
+ When(/^(I |we )*(close|open|stick|unstick|unapprove|approve|spam|unspam|trash|restore) the topic$/, async function (pronounCase, action) {
123
+ await moderate(this, await leadPost(this), 'the topic', action);
124
+ });
125
+
126
+ /**
127
+ * Stick the topic that is open to the front: on top of every forum (a super
128
+ * sticky topic).
129
+ *
130
+ * Example #1: When I stick the topic to the front
131
+ * Example #2: And I stick the topic to the front
132
+ * Example #3: When we stick the topic to the front
133
+ * Example #4: And we stick the topic to the front
134
+ * Example #5: When I stick the topic to the front of every forum
135
+ */
136
+ When(/^(I |we )*stick the topic to the front(?: of every forum)?$/, async function (pronounCase) {
137
+ const lead = await leadPost(this);
138
+ await followPostLink(this, lead, ['bbp-topic-super-sticky-link'], 'stick the topic to the front');
139
+ const after = (await topicPosts(this)).find((p) => p.id === lead.id);
140
+ const link = after && after.links.find((l) => l.name === 'bbp-topic-sticky-link');
141
+ if (!link || !/^unstick$/i.test(link.text)) {
142
+ throw friendly({ message: 'Followed "(to front)", but the topic does not offer Unstick.', hint: 'A topic that is sticky already offers Unstick only: unstick it first.' });
143
+ }
144
+ });
145
+
146
+ /**
147
+ * Delete the topic that is open for good, from the trash: the forums ask "are
148
+ * you sure", the step says yes, and the topic and its replies are gone.
149
+ *
150
+ * Example #1: When I delete the topic permanently
151
+ * Example #2: And I delete the topic permanently
152
+ * Example #3: When we delete the topic permanently
153
+ * Example #4: And we delete the topic permanently
154
+ * Example #5: When I delete the topic permanently
155
+ */
156
+ When(/^(I |we )*delete the topic permanently$/, async function (pronounCase) {
157
+ let lead = await leadPost(this);
158
+ if (lead.status !== 'trash') {
159
+ await moderate(this, lead, 'the topic', 'trash');
160
+ lead = await leadPost(this);
161
+ }
162
+ await followPostLink(this, lead, ['bbp-topic-delete-link'], 'delete the topic');
163
+ const page = await forumPage(this);
164
+ if (page.kind === 'topic' && (await topicPosts(this)).some((p) => p.id === lead.id)) {
165
+ throw friendly({ message: 'Followed "Delete", but the topic is still there.', hint: 'Only a keymaster and a moderator may delete a topic; the forums ask for a confirmation the step gives.' });
166
+ }
167
+ });
168
+
169
+ /**
170
+ * Merge the topic that is open into another topic of the same forum: it
171
+ * becomes a reply there, with its replies; the browser lands on that topic.
172
+ *
173
+ * Example #1: When I merge the topic into "Webship test topic"
174
+ * Example #2: And I merge the topic into "A community garden in spring"
175
+ * Example #3: When we merge the topic into "Welcome to the forums"
176
+ * Example #4: When I merge the topic into "Webship test destination"
177
+ * Example #5: And we merge the topic into "Forum rules"
178
+ */
179
+ When(/^(I |we )*merge the topic into "([^"]*)"$/, async function (pronounCase, destination) {
180
+ const lead = await leadPost(this);
181
+ const link = lead.links.find((l) => l.name === 'bbp-topic-merge-link');
182
+ if (!link) {
183
+ throw friendly({ message: `The topic offers this account no Merge link. It offers: ${listed(lead.links.map((l) => l.text))}.`, hint: 'A moderator and a keymaster may merge topics.' });
184
+ }
185
+ await navigate(this, link.href);
186
+ const form = this.page.locator(`${FORUMS} form#merge_topic`);
187
+ if (!(await form.count())) throw friendly({ message: `The merge form did not open (${this.page.url()}).`, hint: 'The forums show it to a moderator and a keymaster.' });
188
+ await chooseOption(this, form.locator('#bbp_destination_topic'), destination, 'topic');
189
+ await clickAndLoad(this, form.locator('#bbp_merge_topic_submit'), 'merge the topic');
190
+ await readingTopic(this, destination);
191
+ });
192
+
193
+ /**
194
+ * Split the topic that is open at a post of the page: that reply and every
195
+ * later one go to a new topic of the same forum with the title given; the
196
+ * browser lands on the new topic.
197
+ *
198
+ * Example #1: When I split the topic from post 3 into "Webship test split"
199
+ * Example #2: And I split the topic from post 2 into "Webship test: a new question"
200
+ * Example #3: When we split the topic from post 4 into "Webship test split"
201
+ * Example #4: When I split the topic from post 2 into "Webship test: off topic"
202
+ * Example #5: And we split the topic from post 3 into "Webship test: the second half"
203
+ */
204
+ When(/^(I |we )*split the topic from post (\d+) into "([^"]*)"$/, async function (pronounCase, number, title) {
205
+ const { post, label } = await postOnPage(this, number);
206
+ const link = post.links.find((l) => l.name === 'bbp-topic-split-link');
207
+ if (!link) {
208
+ throw friendly({
209
+ message: `${label} offers no Split link. It offers: ${listed(post.links.map((l) => l.text))}.`,
210
+ hint: 'A topic is split at a reply, by a moderator or a keymaster: the topic\'s own post (post 1 of the first page) has no Split link.',
211
+ });
212
+ }
213
+ await navigate(this, link.href);
214
+ const form = this.page.locator(`${FORUMS} form#split_topic`);
215
+ if (!(await form.count())) throw friendly({ message: `The split form did not open (${this.page.url()}).`, hint: 'The forums show it to a moderator and a keymaster.' });
216
+ await form.locator('#bbp_topic_split_option_reply').check();
217
+ await form.locator('#bbp_topic_split_destination_title').fill(title);
218
+ await clickAndLoad(this, form.locator('#bbp_merge_topic_submit'), 'split the topic');
219
+ await readingTopic(this, title);
220
+ this.forumTopics.push({ title, url: this.page.url().split('#')[0].split('?')[0] });
221
+ });
222
+
223
+ /**
224
+ * Move the topic that is open to another forum, through its edit form.
225
+ *
226
+ * Example #1: When I move the topic to "Help and support"
227
+ * Example #2: And I move the topic to "General discussion"
228
+ * Example #3: When we move the topic to "Showcase"
229
+ * Example #4: When I move the topic to "Staff room"
230
+ * Example #5: And we move the topic to "Members lounge"
231
+ */
232
+ When(/^(I |we )*move the topic to "([^"]*)"$/, async function (pronounCase, forum) {
233
+ const lead = await leadPost(this);
234
+ const link = lead.links.find((l) => l.name === 'bbp-topic-edit-link');
235
+ if (!link) throw friendly({ message: `The topic offers this account no Edit link. It offers: ${listed(lead.links.map((l) => l.text))}.`, hint: 'A moderator and a keymaster may move a topic.' });
236
+ await navigate(this, link.href);
237
+ const select = this.page.locator(`${FORUMS} form#new-post #bbp_forum_id`);
238
+ if (!(await select.count())) {
239
+ throw friendly({ message: 'The edit form of the topic has no list of forums for this account.', hint: 'A moderator and a keymaster get it; a participant edits the title and the text only.' });
240
+ }
241
+ await chooseOption(this, select, forum, 'forum');
242
+ await clickAndLoad(this, this.page.locator(`${FORUMS} form#new-post #bbp_topic_submit`), 'save the topic');
243
+ const errors = (await forumNotices(this)).filter((n) => n.kind === 'error').map((n) => n.text);
244
+ if (errors.length) throw friendly({ message: `The forums refused to move the topic: ${listed(errors)}.`, hint: 'A topic cannot go into a category or a forum the account may not post in.' });
245
+ const crumbs = await this.page.evaluate((sel) => [...document.querySelectorAll(`${sel} .bbp-breadcrumb a`)].map((a) => a.textContent.trim()), FORUMS);
246
+ if (!crumbs.some((c) => same(c, forum))) {
247
+ throw friendly({ message: `The topic was saved, but its breadcrumbs do not name "${forum}": ${listed(crumbs)}.`, hint: 'The breadcrumbs of a topic name the forum it is in.' });
248
+ }
249
+ });
250
+
251
+ // ---------------------------------------------------------------------------
252
+ // A reply
253
+ // ---------------------------------------------------------------------------
254
+
255
+ /**
256
+ * Follow a moderation link of a post of the page, by its number or the last
257
+ * one: unapprove or approve it, mark it as spam or not, put it in the trash
258
+ * or restore it. The step checks the post took the state.
259
+ *
260
+ * Example #1: When I unapprove the last post
261
+ * Example #2: And I approve the last post
262
+ * Example #3: When I spam post 2
263
+ * Example #4: When we unspam post 2
264
+ * Example #5: And I trash the last post
265
+ * Example #6: When I restore the last post
266
+ */
267
+ When(/^(I |we )*(unapprove|approve|spam|unspam|trash|restore) (?:post (\d+)|the last post)$/, async function (pronounCase, action, number) {
268
+ const { post, label } = await postOnPage(this, number);
269
+ await moderate(this, post, label.toLowerCase(), action);
270
+ });
271
+
272
+ /**
273
+ * Delete a post of the page for good, by its number or the last one: it goes
274
+ * to the trash first when it is not there, then the forums ask "are you
275
+ * sure" and the step says yes.
276
+ *
277
+ * Example #1: When I delete the last post permanently
278
+ * Example #2: And I delete post 2 permanently
279
+ * Example #3: When we delete the last post permanently
280
+ * Example #4: When I delete post 3 permanently
281
+ * Example #5: And we delete post 2 permanently
282
+ */
283
+ When(/^(I |we )*delete (?:post (\d+)|the last post) permanently$/, async function (pronounCase, number) {
284
+ let { post, label } = await postOnPage(this, number);
285
+ if (post.lead) {
286
+ throw friendly({ message: `${label} is the topic's own post.`, hint: 'Delete the topic instead: When I delete the topic permanently.' });
287
+ }
288
+ if (post.status !== 'trash') {
289
+ await moderate(this, post, label.toLowerCase(), 'trash');
290
+ post = (await topicPosts(this)).find((p) => p.id === post.id);
291
+ }
292
+ await followPostLink(this, post, ['bbp-reply-delete-link'], `delete ${label.toLowerCase()}`);
293
+ if ((await topicPosts(this)).some((p) => p.id === post.id)) {
294
+ throw friendly({ message: `Followed "Delete", but ${label.toLowerCase()} is still there.`, hint: 'Only a keymaster and a moderator may delete a reply.' });
295
+ }
296
+ });
297
+
298
+ /**
299
+ * Assert the state of a post of the page as a moderator reads it: published,
300
+ * pending, spam, or in the trash.
301
+ *
302
+ * Example #1: Then the last post should be pending
303
+ * Example #2: And the last post should be published
304
+ * Example #3: Then post 2 should be spam
305
+ * Example #4: Then the last post should be in the trash
306
+ * Example #5: And post 2 should not be spam
307
+ */
308
+ Then(/^(?:post (\d+)|the last post) should( not)* be (published|pending|spam|in the trash)$/, async function (number, notCase, state) {
309
+ await settle(this);
310
+ const { post, label } = await postOnPage(this, number);
311
+ const wanted = { published: ['publish', 'closed'], pending: ['pending'], spam: ['spam'], 'in the trash': ['trash'] }[state];
312
+ if (wanted.includes(post.status) === Boolean(notCase)) {
313
+ throw friendly({
314
+ message: notCase ? `Expected ${label.toLowerCase()} not to be ${state}, but it is.` : `Expected ${label.toLowerCase()} to be ${state}, but it is ${STATUS_WORDS[post.status] === 'open' ? 'published' : (STATUS_WORDS[post.status] || post.status)}.`,
315
+ hint: 'A moderator sees the pending, spammed and trashed posts of a topic; another account does not see them at all.',
316
+ });
317
+ }
318
+ });
319
+
320
+ /**
321
+ * Move a reply of the page out of its topic, by its number or the last one:
322
+ * into a new topic of the same forum with the title given, or into another
323
+ * topic of that forum. The browser lands on the topic the reply went to.
324
+ *
325
+ * Example #1: When I move the last post to a new topic "Webship test: moved reply"
326
+ * Example #2: And I move post 2 to the topic "Webship test destination"
327
+ * Example #3: When we move post 3 to a new topic "Webship test: a question of its own"
328
+ * Example #4: When I move the last post to the topic "A community garden in spring"
329
+ * Example #5: And we move post 2 to a new topic "Webship test: split off"
330
+ */
331
+ When(/^(I |we )*move (?:post (\d+)|the last post) to (a new topic|the topic) "([^"]*)"$/, async function (pronounCase, number, where, title) {
332
+ const { post, label } = await postOnPage(this, number);
333
+ const link = post.links.find((l) => l.name === 'bbp-reply-move-link');
334
+ if (!link) {
335
+ throw friendly({
336
+ message: `${label} offers no Move link. It offers: ${listed(post.links.map((l) => l.text))}.`,
337
+ hint: 'A reply is moved by a moderator or a keymaster; the topic\'s own post moves with its topic (When I move the topic to "…").',
338
+ });
339
+ }
340
+ await navigate(this, link.href);
341
+ const form = this.page.locator(`${FORUMS} form#move_reply`);
342
+ if (!(await form.count())) throw friendly({ message: `The move form did not open (${this.page.url()}).`, hint: 'The forums show it to a moderator and a keymaster.' });
343
+ if (where === 'a new topic') {
344
+ await form.locator('#bbp_reply_move_option_reply').check();
345
+ await form.locator('#bbp_reply_move_destination_title').fill(title);
346
+ } else {
347
+ await form.locator('#bbp_reply_move_option_existing').check();
348
+ await chooseOption(this, form.locator('#bbp_destination_topic'), title, 'topic');
349
+ }
350
+ await clickAndLoad(this, form.locator('#bbp_move_reply_submit'), 'move the reply');
351
+ await readingTopic(this, title);
352
+ if (where === 'a new topic') this.forumTopics.push({ title, url: this.page.url().split('#')[0].split('?')[0] });
353
+ });
354
+
355
+ /**
356
+ * Show what the forums hide from the members on the page that is open: the
357
+ * pending, spammed and trashed replies of a topic, or topics of a forum. A
358
+ * moderator reads "(+1 hidden)" in the line that describes the page, and
359
+ * follows it.
360
+ *
361
+ * Example #1: When I show the hidden posts
362
+ * Example #2: And I show the hidden topics
363
+ * Example #3: When we show the hidden posts
364
+ * Example #4: When we show the hidden topics
365
+ * Example #5: And I show the hidden posts
366
+ */
367
+ When(/^(I |we )*show the hidden (posts|topics)$/, async function (pronounCase, what) {
368
+ await settle(this);
369
+ const box = what === 'posts' ? '.bbp-topic-description' : '.bbp-forum-description';
370
+ const state = await this.page.evaluate(([sel, box]) => {
371
+ const line = document.querySelector(`${sel} ${box}`);
372
+ const link = line && line.querySelector('a[href*="view=all"]');
373
+ return { line: line ? line.textContent.replace(/\s+/g, ' ').trim() : '', href: link ? link.href : '' };
374
+ }, [FORUMS, box]);
375
+ if (!state.href) {
376
+ throw friendly({
377
+ message: state.line ? `The page hides no ${what} from this account: it says "${state.line}".` : `The page is not a ${what === 'posts' ? 'topic' : 'forum'} (${this.page.url()}).`,
378
+ hint: 'A moderator and a keymaster read "(+1 hidden)" on a topic with a pending, spammed or trashed reply, and on a forum with such a topic.',
379
+ });
380
+ }
381
+ await navigate(this, state.href);
382
+ });
383
+
384
+ // ---------------------------------------------------------------------------
385
+ // What an account is offered
386
+ // ---------------------------------------------------------------------------
387
+
388
+ /**
389
+ * Assert the topic that is open offers (or does not offer) the account the
390
+ * moderator's tools: the links that close, stick, trash and merge it.
391
+ *
392
+ * Example #1: Then I should see the moderator tools
393
+ * Example #2: And I should not see the moderator tools
394
+ * Example #3: Then we should see the moderator tools
395
+ * Example #4: Then we should not see the moderator tools
396
+ * Example #5: But I should not see the moderator tools
397
+ */
398
+ Then(/^(I |we )*should( not)* see the moderator tools$/, async function (pronounCase, notCase) {
399
+ await settle(this);
400
+ await readingTopic(this);
401
+ const posts = await topicPosts(this);
402
+ const tools = ['bbp-topic-close-link', 'bbp-topic-sticky-link', 'bbp-topic-trash-link', 'bbp-topic-merge-link', 'bbp-reply-trash-link', 'bbp-reply-move-link', 'bbp-topic-split-link'];
403
+ const offered = [...new Set(posts.flatMap((p) => p.links.filter((l) => tools.includes(l.name)).map((l) => l.text)))];
404
+ if (Boolean(offered.length) === Boolean(notCase)) {
405
+ throw friendly({
406
+ message: notCase
407
+ ? `Expected no moderator tools on the topic, but it offers: ${listed(offered)}.`
408
+ : `Expected the moderator tools on the topic. Its posts offer: ${listed([...new Set(posts.flatMap((p) => p.links.map((l) => l.text)))])} (${clean(this.page.url())}).`,
409
+ hint: 'The tools are offered to a moderator and a keymaster of the forums.',
410
+ });
411
+ }
412
+ });
413
+