@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,488 @@
1
+ 'use strict';
2
+
3
+ // The forum index and a forum: the forums an account sees and their counters
4
+ // and marks (a category, closed, private, hidden, a subforum), the topics of a
5
+ // forum (their order, their marks, their counters), the pages of a list, the
6
+ // forums' breadcrumbs, what the forums say in their notices, and whether the
7
+ // account may start a topic or reply.
8
+ //
9
+ // The lists are rendered on the server: a step reads the rows the forums
10
+ // print (`ul#bbp-forum-<id>`, `ul#bbp-topic-<id>`) and the classes they set
11
+ // on them, after the page settled.
12
+
13
+ const { Given, When, Then } = require('@cucumber/cucumber');
14
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
15
+ const {
16
+ FORUMS,
17
+ settle,
18
+ navigate,
19
+ visit,
20
+ supplied,
21
+ clean,
22
+ listed,
23
+ same,
24
+ holds,
25
+ quotedList,
26
+ eventually,
27
+ gotoForumIndex,
28
+ forumPage,
29
+ forumNotices,
30
+ listTotal,
31
+ listedForums,
32
+ forumNames,
33
+ openForum,
34
+ listedTopics,
35
+ } = require('./bbpress-helpers');
36
+
37
+ /** The forum of a list by its name, a row or a subforum under one; fails with the names that are there. */
38
+ async function forumRow(world, name) {
39
+ const forums = await listedForums(world);
40
+ const row = forums.find((f) => same(f.name, name));
41
+ if (row) return row;
42
+ const parent = forums.find((f) => f.subforums.some((s) => same(s.name, name)));
43
+ if (parent) {
44
+ throw friendly({
45
+ message: `"${name}" is a subforum of "${parent.name}" on this page: the page shows its name and counters in one line, not its marks.`,
46
+ hint: `Open "${parent.name}" first (When I open the forum "${parent.name}"): there "${name}" is a row of its own.`,
47
+ });
48
+ }
49
+ throw friendly({
50
+ message: `The page lists no forum "${name}". It lists: ${listed(forumNames(forums))}.`,
51
+ hint: 'Open the forum index first: Given I am on the forum index. A private forum is listed for a logged-in participant, a hidden one for a moderator.',
52
+ });
53
+ }
54
+
55
+ /** The topic of the list on the page by its title; fails with the titles that are there. */
56
+ async function topicRow(world, title) {
57
+ const topics = await listedTopics(world);
58
+ const row = topics.find((t) => same(t.title, title));
59
+ if (!row) {
60
+ throw friendly({
61
+ message: `The list on the page has no topic "${title}". It lists: ${listed(topics.map((t) => t.title))}.`,
62
+ hint: 'The step reads the page of the list that is open: When I go to page 2 opens the next one. A pending, spammed or trashed topic is left out of it, for a moderator too until it asks for them: When I show the hidden topics.',
63
+ });
64
+ }
65
+ return row;
66
+ }
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // The forum index
70
+ // ---------------------------------------------------------------------------
71
+
72
+ /**
73
+ * Open the forum index: the page that lists the forums of the site
74
+ * ("/forums/"; `worldParameters.forums.root` names another root).
75
+ *
76
+ * Example #1: Given I am on the forum index
77
+ * Example #2: When I go to the forum index
78
+ * Example #3: Given we are on the forum index
79
+ * Example #4: And I go to the forum index
80
+ * Example #5: When we go to the forum index
81
+ */
82
+ Given(/^(?:(?:I am |we are )+on|(?:I |we )*go to) the forum index$/, async function () {
83
+ await gotoForumIndex(this);
84
+ });
85
+
86
+ /**
87
+ * Assert the forum index lists (or does not list) a forum by its name, as a
88
+ * row or as a subforum under one; with a category, under that category.
89
+ *
90
+ * Example #1: Then the forum index should list the forum "Showcase"
91
+ * Example #2: And the forum index should list the forum "General discussion" in the category "Community"
92
+ * Example #3: Then the forum index should not list the forum "Staff room"
93
+ * Example #4: And the forum index should not list the forum "Members lounge"
94
+ * Example #5: Then the forum index should list the forum "Help and support" in the category "Community"
95
+ */
96
+ Then(/^the forum index should( not)* list the forum "([^"]*)"(?: in the category "([^"]*)")?$/, async function (notCase, name, category) {
97
+ await settle(this);
98
+ const page = await forumPage(this);
99
+ if (page.kind !== 'index') {
100
+ if (notCase && page.kind === 'none') return;
101
+ throw friendly({ message: `The page is not the forum index: it is "${page.heading}" (${page.url}).`, hint: 'Open it first: Given I am on the forum index.' });
102
+ }
103
+ const forums = await listedForums(this);
104
+ let found;
105
+ if (supplied(category)) {
106
+ const parent = forums.find((f) => same(f.name, category));
107
+ if (!parent) {
108
+ throw friendly({ message: `The forum index lists no category "${category}". It lists: ${listed(forums.map((f) => f.name))}.`, hint: 'A category is a row of the index that holds forums.' });
109
+ }
110
+ found = parent.subforums.some((s) => same(s.name, name));
111
+ } else {
112
+ found = forumNames(forums).some((n) => same(n, name));
113
+ }
114
+ if (found === Boolean(notCase)) {
115
+ throw friendly({
116
+ message: notCase
117
+ ? `Expected the forum index not to list the forum "${name}"${supplied(category) ? ` in the category "${category}"` : ''}, but it does.`
118
+ : `Expected the forum index to list the forum "${name}"${supplied(category) ? ` in the category "${category}"` : ''}. It lists: ${listed(forumNames(forums))}.`,
119
+ hint: 'A private forum is listed for a logged-in participant, a hidden one for a moderator or a keymaster.',
120
+ });
121
+ }
122
+ });
123
+
124
+ /**
125
+ * Assert a counter of a forum's row: its topics, or its posts (topics and
126
+ * replies together, the column the forums head "Posts").
127
+ *
128
+ * Example #1: Then the forum "Showcase" should have 16 topics in the list
129
+ * Example #2: And the forum "Showcase" should have 16 posts in the list
130
+ * Example #3: Then the forum "Archive" should have 1 topic in the list
131
+ * Example #4: And the forum "Archive" should have 2 posts in the list
132
+ * Example #5: Then the forum "Community" should have 7 topics in the list
133
+ */
134
+ Then(/^the forum "([^"]*)" should have (\d+) (topics?|posts?) in the list$/, async function (name, count, what) {
135
+ const key = what.startsWith('topic') ? 'topics' : 'posts';
136
+ await eventually(this, () => forumRow(this, name), (row) => row[key] === Number(count), (row) => ({
137
+ message: `Expected the forum "${name}" to show ${count} ${key}, but its row shows ${row ? row[key] : 'nothing'}.`,
138
+ hint: 'The row counts what the account may read; "Posts" counts the topics and their replies together. A category counts the forums under it.',
139
+ }), 1500);
140
+ });
141
+
142
+ /**
143
+ * Assert a mark of a forum's row: a category, closed, private or hidden.
144
+ *
145
+ * Example #1: Then the forum "Archive" should be closed in the list
146
+ * Example #2: And the forum "Community" should be a category in the list
147
+ * Example #3: Then the forum "Members lounge" should be private in the list
148
+ * Example #4: And the forum "Staff room" should be hidden in the list
149
+ * Example #5: Then the forum "Showcase" should not be closed in the list
150
+ */
151
+ Then(/^the forum "([^"]*)" should( not)* be (a category|closed|private|hidden) in the list$/, async function (name, notCase, mark) {
152
+ const row = await forumRow(this, name);
153
+ const is = { 'a category': row.category, closed: row.closed, private: row.private, hidden: row.hidden }[mark];
154
+ if (is === Boolean(notCase)) {
155
+ throw friendly({
156
+ message: notCase ? `Expected the forum "${name}" not to be ${mark}, but its row says it is.` : `Expected the forum "${name}" to be ${mark}, but its row does not say so.`,
157
+ hint: 'The marks are the ones the forum\'s own settings give it: its type (forum or category), its status (open or closed) and its visibility (public, private or hidden).',
158
+ });
159
+ }
160
+ });
161
+
162
+ // ---------------------------------------------------------------------------
163
+ // A forum
164
+ // ---------------------------------------------------------------------------
165
+
166
+ /**
167
+ * Open a forum by its name, as a person does: from the page when it lists
168
+ * the forum, else from the forum index.
169
+ *
170
+ * Example #1: When I open the forum "General discussion"
171
+ * Example #2: And I open the forum "Showcase"
172
+ * Example #3: When we open the forum "Help and support"
173
+ * Example #4: When I open the forum "Members lounge"
174
+ * Example #5: And we open the forum "Archive"
175
+ */
176
+ When(/^(I |we )*open the forum "([^"]*)"$/, async function (pronounCase, name) {
177
+ await openForum(this, name);
178
+ });
179
+
180
+ /**
181
+ * Assert the page is a forum, by its name.
182
+ *
183
+ * Example #1: Then I should be in the forum "General discussion"
184
+ * Example #2: And I should be in the forum "Showcase"
185
+ * Example #3: Then we should be in the forum "Help and support"
186
+ * Example #4: Then I should be in the forum "Members lounge"
187
+ * Example #5: And we should be in the forum "Archive"
188
+ */
189
+ Then(/^(I |we )*should be in the forum "([^"]*)"$/, async function (pronounCase, name) {
190
+ await settle(this);
191
+ const page = await forumPage(this);
192
+ const heading = page.heading.replace(/^(?:(?:Private|Hidden|Protected):\s+)+/i, '');
193
+ if (page.kind !== 'forum' || !same(heading, name)) {
194
+ throw friendly({
195
+ message: `The page is not the forum "${name}": it is ${page.kind === 'none' ? 'no page of the forums' : `"${page.heading}"`} (${page.url}).`,
196
+ hint: 'Open it first: When I open the forum "…".',
197
+ });
198
+ }
199
+ });
200
+
201
+ /**
202
+ * Assert the list on the page has (or has not) a topic, by its title, or the
203
+ * forum a subforum, by its name. The list is the one of a forum, a topic
204
+ * tag, a view or a page of a profile.
205
+ *
206
+ * Example #1: Then the forum should list the topic "Welcome to the forums"
207
+ * Example #2: And the forum should not list the topic "Staff only: the moderation notes"
208
+ * Example #3: Then the forum should list the subforum "General discussion"
209
+ * Example #4: And the forum should list the topic "Forum rules"
210
+ * Example #5: Then the forum should not list the subforum "Showcase"
211
+ */
212
+ Then(/^the forum should( not)* list the (topic|subforum) "([^"]*)"$/, async function (notCase, what, name) {
213
+ await settle(this);
214
+ const names = what === 'topic'
215
+ ? (await listedTopics(this)).map((t) => t.title)
216
+ : (await listedForums(this)).map((f) => f.name);
217
+ if (names.some((n) => same(n, name)) === Boolean(notCase)) {
218
+ throw friendly({
219
+ message: notCase
220
+ ? `Expected no ${what} "${name}" on the page, but it is listed.`
221
+ : `Expected the ${what} "${name}" on the page. It lists: ${listed(names)}.`,
222
+ hint: what === 'topic'
223
+ ? 'The step reads the page of the list that is open (15 topics a page). A super sticky topic is listed in every forum.'
224
+ : 'A subforum is a row of the forum that holds it.',
225
+ });
226
+ }
227
+ });
228
+
229
+ /**
230
+ * Assert a mark of a topic in the list on the page: sticky (in its forum),
231
+ * super sticky (in every forum), closed, pending, spam or in the trash.
232
+ *
233
+ * Example #1: Then the topic "Welcome to the forums" should be sticky in the list
234
+ * Example #2: And the topic "Forum rules" should be super sticky in the list
235
+ * Example #3: Then the topic "The spring meetup is over" should be closed in the list
236
+ * Example #4: And the topic "A community garden in spring" should not be sticky in the list
237
+ * Example #5: Then the topic "A community garden in spring" should not be closed in the list
238
+ */
239
+ Then(/^the topic "([^"]*)" should( not)* be (sticky|super sticky|closed|pending|spam|in the trash) in the list$/, async function (title, notCase, mark) {
240
+ await settle(this);
241
+ const row = await topicRow(this, title);
242
+ const is = {
243
+ sticky: row.sticky,
244
+ 'super sticky': row.superSticky,
245
+ closed: row.status === 'closed',
246
+ pending: row.status === 'pending',
247
+ spam: row.status === 'spam',
248
+ 'in the trash': row.status === 'trash',
249
+ }[mark];
250
+ if (is === Boolean(notCase)) {
251
+ throw friendly({
252
+ message: notCase ? `Expected the topic "${title}" not to be ${mark}, but its row says it is.` : `Expected the topic "${title}" to be ${mark}, but its row says: ${row.superSticky ? 'super sticky' : (row.sticky ? 'sticky' : 'not sticky')}, status "${row.status}".`,
253
+ hint: 'A sticky topic stays on top of its forum, a super sticky one on top of every forum. The status of a row is open ("publish"), closed, pending, spam or trash.',
254
+ });
255
+ }
256
+ });
257
+
258
+ /**
259
+ * Assert what the row of a topic says: its replies (the "Posts" column
260
+ * counts the topic's own post too), its voices (the accounts that wrote in
261
+ * it), or who started it.
262
+ *
263
+ * Example #1: Then the topic "Welcome to the forums" should have 2 replies in the list
264
+ * Example #2: And the topic "Welcome to the forums" should have 3 voices in the list
265
+ * Example #3: Then the topic "Forum rules" should be by "keymaster" in the list
266
+ * Example #4: And the topic "Forum rules" should have 0 replies in the list
267
+ * Example #5: Then the topic "A community garden in spring" should have 1 reply in the list
268
+ */
269
+ Then(/^the topic "([^"]*)" should (?:have (\d+) (repl(?:y|ies)|voices?)|be by "([^"]*)") in the list$/, async function (title, count, what, author) {
270
+ await settle(this);
271
+ const row = await topicRow(this, title);
272
+ if (supplied(author)) {
273
+ if (!same(row.author, author)) {
274
+ throw friendly({ message: `Expected the topic "${title}" to be by "${author}", but its row says "${row.author}".`, hint: 'The row names the display name of the account that started the topic.' });
275
+ }
276
+ return;
277
+ }
278
+ const actual = what.startsWith('repl') ? row.posts - 1 : row.voices;
279
+ if (actual !== Number(count)) {
280
+ throw friendly({
281
+ message: `Expected the topic "${title}" to have ${count} ${what}, but its row shows ${actual}.`,
282
+ hint: 'The "Posts" column counts the topic\'s own post and its replies; "Voices" counts the accounts that wrote in the topic.',
283
+ });
284
+ }
285
+ });
286
+
287
+ /**
288
+ * Assert how many topics the list of the page counts in all, over its pages
289
+ * ("Viewing 15 topics - 1 through 15 (of 17 total)").
290
+ *
291
+ * Example #1: Then the forum should have 4 topics
292
+ * Example #2: And the forum should have 17 topics
293
+ * Example #3: Then the forum should have 1 topic
294
+ * Example #4: Then the forum should have 0 topics
295
+ * Example #5: And the forum should have 3 topics
296
+ */
297
+ Then(/^the forum should have (\d+) topics?$/, async function (count) {
298
+ await settle(this);
299
+ const page = await forumPage(this);
300
+ if (page.kind === 'none' || page.kind === 'topic') {
301
+ throw friendly({ message: `The page is not a list of topics: it is ${page.heading ? `"${page.heading}"` : 'no page of the forums'} (${page.url}).`, hint: 'Open a forum first: When I open the forum "…".' });
302
+ }
303
+ const total = await listTotal(this);
304
+ const actual = total && total.total !== null ? total.total : (await listedTopics(this)).length;
305
+ if (actual !== Number(count)) {
306
+ throw friendly({
307
+ message: `Expected ${count} topic(s), but the list counts ${actual}${total ? ` ("${clean(total.text)}")` : ''}.`,
308
+ hint: 'The list counts what the account may read. A super sticky topic counts in every forum.',
309
+ });
310
+ }
311
+ });
312
+
313
+ /**
314
+ * Assert which topic the list on the page shows first.
315
+ *
316
+ * Example #1: Then the first topic of the forum should be "Forum rules"
317
+ * Example #2: And the first topic of the forum should be "Welcome to the forums"
318
+ * Example #3: Then the first topic of the forum should be "Showcase entry 16"
319
+ * Example #4: Then the first topic of the forum should be "A long conversation"
320
+ * Example #5: And the first topic of the forum should be "The forums opened"
321
+ */
322
+ Then(/^the first topic of the forum should be "([^"]*)"$/, async function (title) {
323
+ await settle(this);
324
+ const topics = await listedTopics(this);
325
+ if (!topics.length || !same(topics[0].title, title)) {
326
+ throw friendly({
327
+ message: `Expected the list to begin with the topic "${title}", but it ${topics.length ? `begins with "${topics[0].title}"` : 'is empty'}.`,
328
+ hint: 'A forum lists the super sticky topics first, then its sticky ones, then the others by their last post.',
329
+ });
330
+ }
331
+ });
332
+
333
+ // ---------------------------------------------------------------------------
334
+ // The pages of a list
335
+ // ---------------------------------------------------------------------------
336
+
337
+ /**
338
+ * Go to a page of the list that is open (the topics of a forum, the posts of
339
+ * a topic, the search results), through the page links the forums print.
340
+ *
341
+ * Example #1: When I go to page 2
342
+ * Example #2: And I go to page 1
343
+ * Example #3: When we go to page 2
344
+ * Example #4: When I go to page 3
345
+ * Example #5: And we go to page 1
346
+ */
347
+ When(/^(I |we )*go to page (\d+)$/, async function (pronounCase, number) {
348
+ await settle(this);
349
+ const state = await this.page.evaluate(([sel, wanted]) => {
350
+ const box = document.querySelector(`${sel} .bbp-pagination-links`);
351
+ if (!box) return { links: null };
352
+ const current = box.querySelector('.current');
353
+ const link = [...box.querySelectorAll('a.page-numbers')].find((a) => a.textContent.replace(/[^\d]/g, '') === wanted && !a.classList.contains('next') && !a.classList.contains('prev'));
354
+ return { links: [...box.querySelectorAll('.page-numbers')].map((a) => a.textContent.trim()), current: current ? current.textContent.trim() : '', href: link ? link.href : '' };
355
+ }, [FORUMS, String(number)]);
356
+ if (state.links && state.current === String(number)) return;
357
+ if (!state.links || !state.href) {
358
+ throw friendly({
359
+ message: `The list has no page ${number}${state.links && state.links.length ? `: its pages are ${listed(state.links.filter((l) => /^\d+$/.test(l)))}` : ': it fits on one page'}.`,
360
+ hint: 'A forum shows 15 topics a page and a topic 15 posts, unless the forums\' settings say otherwise.',
361
+ });
362
+ }
363
+ await navigate(this, state.href);
364
+ });
365
+
366
+ /**
367
+ * Assert which page of a list the browser shows.
368
+ *
369
+ * Example #1: Then I should be on page 2
370
+ * Example #2: And I should be on page 1
371
+ * Example #3: Then we should be on page 2
372
+ * Example #4: Then I should be on page 3
373
+ * Example #5: And we should be on page 1
374
+ */
375
+ Then(/^(I |we )*should be on page (\d+)$/, async function (pronounCase, number) {
376
+ await settle(this);
377
+ const current = await this.page.evaluate((sel) => {
378
+ const box = document.querySelector(`${sel} .bbp-pagination-links`);
379
+ const mark = box && box.querySelector('.current');
380
+ return mark ? mark.textContent.replace(/[^\d]/g, '') : '1';
381
+ }, FORUMS);
382
+ if (current !== String(number)) {
383
+ throw friendly({ message: `Expected page ${number} of the list, but the browser shows page ${current} (${this.page.url()}).`, hint: 'The page is the one the page links of the list mark as current.' });
384
+ }
385
+ });
386
+
387
+ // ---------------------------------------------------------------------------
388
+ // Breadcrumbs, notices, what the account may do
389
+ // ---------------------------------------------------------------------------
390
+
391
+ /**
392
+ * Assert the breadcrumbs the forums print above a page, in order.
393
+ *
394
+ * Example #1: Then the forum breadcrumbs should be "Home", "Forums" and "Showcase"
395
+ * Example #2: And the forum breadcrumbs should be "Home" and "Forums"
396
+ * Example #3: Then the forum breadcrumbs should be "Home", "Forums", "Community" and "General discussion"
397
+ * Example #4: Then the forum breadcrumbs should be "Home", "Forums", "Community", "General discussion" and "Forum rules"
398
+ * Example #5: And the forum breadcrumbs should be "Home", "Forums" and "Topic Tag: spring"
399
+ */
400
+ Then(/^the forum breadcrumbs should be ("[^"]*"(?:(?:, | and )"[^"]*")*)$/, async function (list) {
401
+ const expected = quotedList(list);
402
+ const read = () => this.page.evaluate((sel) => {
403
+ const box = document.querySelector(`${sel} .bbp-breadcrumb`);
404
+ if (!box) return null;
405
+ return [...box.querySelectorAll('a, .bbp-breadcrumb-current')].map((e) => e.textContent.replace(/\s+/g, ' ').trim());
406
+ }, FORUMS);
407
+ await eventually(this, read, (crumbs) => Array.isArray(crumbs) && crumbs.length === expected.length && crumbs.every((c, i) => same(c, expected[i])), (crumbs) => ({
408
+ message: crumbs ? `Expected the breadcrumbs ${listed(expected)}, but the page shows ${listed(crumbs)}.` : `The page shows no breadcrumbs of the forums (${this.page.url()}).`,
409
+ hint: 'The breadcrumbs are the line above a page of the forums: the site, the forums\' root, the forums on the way, the page itself.',
410
+ }), 1500);
411
+ });
412
+
413
+ /**
414
+ * Assert a notice of the forums on the page holds (or holds not) a text:
415
+ * what a forum or a topic says about itself ("This forum has 4 topics, …"),
416
+ * a refusal ("You must be logged in to reply to this topic."), a mark ("This
417
+ * topic is marked as spam."), an empty list.
418
+ *
419
+ * Example #1: Then the forums should say "You must be logged in to reply to this topic."
420
+ * Example #2: And the forums should say "This forum has 4 topics, 4 replies"
421
+ * Example #3: Then the forums should not say "You cannot reply to this topic."
422
+ * Example #4: And the forums should say "is closed to new replies"
423
+ * Example #5: Then the forums should say "Oh, bother! No topics were found here."
424
+ */
425
+ Then(/^the forums should( not)* say "([^"]*)"$/, async function (notCase, text) {
426
+ if (notCase) {
427
+ await settle(this);
428
+ const notices = await forumNotices(this);
429
+ const hit = notices.find((n) => holds(n.text, text));
430
+ if (hit) throw friendly({ message: `Expected no notice of the forums saying "${text}", but one says: "${hit.text}".`, hint: 'The notices are the boxes the forums print on a page.' });
431
+ return;
432
+ }
433
+ await eventually(this, () => forumNotices(this), (notices) => notices.some((n) => holds(n.text, text)), (notices) => ({
434
+ message: `Expected a notice of the forums saying "${text}". ${(notices || []).length ? `The page says: ${listed((notices || []).map((n) => n.text))}` : 'The page shows no notice of the forums'} (${this.page.url()}).`,
435
+ hint: 'The text is matched as a part of a notice, letter case aside.',
436
+ }), 3000);
437
+ });
438
+
439
+ /**
440
+ * Assert the account may (or may not) start a topic or reply on the page:
441
+ * whether the forums print the form for it.
442
+ *
443
+ * Example #1: Then I should be able to start a topic
444
+ * Example #2: And I should not be able to reply
445
+ * Example #3: Then I should not be able to start a topic
446
+ * Example #4: And we should be able to reply
447
+ * Example #5: Then we should not be able to reply
448
+ */
449
+ Then(/^(I |we )*should( not)* be able to (start a topic|reply)$/, async function (pronounCase, notCase, what) {
450
+ await settle(this);
451
+ const field = what === 'reply' ? '#bbp_reply_content' : '#bbp_topic_title';
452
+ const has = await this.page.locator(`${FORUMS} form#new-post ${field}`).count() > 0;
453
+ if (has === Boolean(notCase)) {
454
+ const notices = (await forumNotices(this)).filter((n) => n.kind !== 'info').map((n) => n.text);
455
+ throw friendly({
456
+ message: notCase
457
+ ? `Expected no form to ${what}, but the page has one (${this.page.url()}).`
458
+ : `Expected the form to ${what}, but the page has none${notices.length ? `: the forums say ${listed(notices)}` : ''} (${this.page.url()}).`,
459
+ hint: what === 'reply'
460
+ ? 'A topic offers its reply form to a participant; a visitor, a spectator and a closed topic get a notice instead.'
461
+ : 'A forum offers its topic form to a participant; a visitor, a spectator, a category and a closed forum get a notice instead.',
462
+ });
463
+ }
464
+ });
465
+
466
+ /**
467
+ * Assert the forums do not let the account open a page: the address answers
468
+ * "not found" or "forbidden", or sends the browser to the login page.
469
+ *
470
+ * Example #1: Then I should not be allowed to open "/forums/forum/staff-room/"
471
+ * Example #2: And I should not be allowed to open "/forums/forum/members-lounge/"
472
+ * Example #3: Then we should not be allowed to open "/forums/"
473
+ * Example #4: Then I should not be allowed to open "/wp-admin/edit.php?post_type=topic"
474
+ * Example #5: And I should not be allowed to open "/forums/topic/forum-rules/edit/"
475
+ */
476
+ Then(/^(I |we )*should not be allowed to open "([^"]*)"$/, async function (pronounCase, address) {
477
+ const status = await visit(this, address);
478
+ const url = new URL(this.page.url());
479
+ const wanted = new URL(address, this.launchUrl.replace(/\/+$/, '') + '/');
480
+ const refused = status === 403 || status === 404 || /\/wp-login\.php/.test(url.pathname)
481
+ || (url.pathname !== wanted.pathname && !url.pathname.startsWith(wanted.pathname));
482
+ if (!refused) {
483
+ throw friendly({
484
+ message: `Expected the site to refuse "${address}", but it answered ${status} with "${clean(await this.page.title())}" (${this.page.url()}).`,
485
+ hint: 'A refusal is a "not found" page (a private or hidden forum, every forum for a blocked account), a "forbidden" page of the administration, the login page, or the page the forums send the account back to.',
486
+ });
487
+ }
488
+ });