@webship-js/bbpress-steps 0.0.0-stage → 2.0.1
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.
- package/LICENSE +21 -0
- package/README.md +515 -2
- package/package.json +67 -4
- package/tests/features/accessibility.feature +29 -0
- package/tests/features/administration.feature +126 -0
- package/tests/features/forum-index.feature +96 -0
- package/tests/features/forum-roles.feature +88 -0
- package/tests/features/moderation.feature +223 -0
- package/tests/features/notifications.feature +43 -0
- package/tests/features/profiles.feature +71 -0
- package/tests/features/search-and-tags.feature +72 -0
- package/tests/features/subscriptions-and-favorites.feature +67 -0
- package/tests/features/topics.feature +146 -0
- package/tests/step-definitions/README.md +44 -0
- package/tests/step-definitions/bbpress-admin.steps.js +414 -0
- package/tests/step-definitions/bbpress-content.steps.js +179 -0
- package/tests/step-definitions/bbpress-defaults.js +64 -0
- package/tests/step-definitions/bbpress-forums.steps.js +488 -0
- package/tests/step-definitions/bbpress-helpers.js +668 -0
- package/tests/step-definitions/bbpress-mail.steps.js +95 -0
- package/tests/step-definitions/bbpress-moderation.steps.js +413 -0
- package/tests/step-definitions/bbpress-profile.steps.js +402 -0
- package/tests/step-definitions/bbpress-search.steps.js +235 -0
- package/tests/step-definitions/bbpress-topics.steps.js +577 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// What an account keeps in the forums and its forum profile: subscribing to
|
|
4
|
+
// a topic or a forum, marking a topic as a favorite, the lists of the
|
|
5
|
+
// profile (topics started, replies created, engagements, favorites,
|
|
6
|
+
// subscriptions), removing a row from them, the profile itself (what it
|
|
7
|
+
// shows, the pages it offers, the forum role), and its edit form.
|
|
8
|
+
//
|
|
9
|
+
// Subscribe and Favorite are links the forums answer in place: the click
|
|
10
|
+
// posts to the page (`?bbp-ajax=true`), the forums mark the link's wrapper
|
|
11
|
+
// (`is-subscribed`, `is-favorite`) and turn its text into its opposite. A step
|
|
12
|
+
// waits for that mark. The `×` of a profile's list removes its row the same
|
|
13
|
+
// way.
|
|
14
|
+
|
|
15
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
16
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
17
|
+
const {
|
|
18
|
+
resolveUser,
|
|
19
|
+
} = require('@webship-js/wordpress-steps/tests/step-definitions/wordpress-helpers');
|
|
20
|
+
const {
|
|
21
|
+
FORUMS,
|
|
22
|
+
budget,
|
|
23
|
+
settle,
|
|
24
|
+
navigate,
|
|
25
|
+
visit,
|
|
26
|
+
clean,
|
|
27
|
+
listed,
|
|
28
|
+
same,
|
|
29
|
+
holds,
|
|
30
|
+
eventually,
|
|
31
|
+
clickAndLoad,
|
|
32
|
+
forumsRoot,
|
|
33
|
+
forumPage,
|
|
34
|
+
forumNotices,
|
|
35
|
+
listedForums,
|
|
36
|
+
listedTopics,
|
|
37
|
+
readingTopic,
|
|
38
|
+
} = require('./bbpress-helpers');
|
|
39
|
+
|
|
40
|
+
/** The login name of a handle of the users registry, or the name itself when the registry has no such handle. */
|
|
41
|
+
function loginOf(world, who) {
|
|
42
|
+
const users = (world.parameters && world.parameters.users) || {};
|
|
43
|
+
return users[who] ? resolveUser(world, who).username : who;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The login name of the account the browser is logged in as, read from the site's toolbar. */
|
|
47
|
+
async function currentLogin(world) {
|
|
48
|
+
const login = await world.page.evaluate(() => {
|
|
49
|
+
const own = document.querySelector('#wp-admin-bar-user-info .username, #wp-admin-bar-user-info .display-name');
|
|
50
|
+
return own ? own.textContent.trim() : '';
|
|
51
|
+
}).catch(() => '');
|
|
52
|
+
if (login) return login;
|
|
53
|
+
// No toolbar on the page (a blank page, a page of another site): ask the forums' own redirect.
|
|
54
|
+
await navigate(world, forumsRoot(world));
|
|
55
|
+
const again = await world.page.evaluate(() => {
|
|
56
|
+
const own = document.querySelector('#wp-admin-bar-user-info .username, #wp-admin-bar-user-info .display-name');
|
|
57
|
+
return own ? own.textContent.trim() : '';
|
|
58
|
+
}).catch(() => '');
|
|
59
|
+
if (!again) {
|
|
60
|
+
throw friendly({ message: 'No account is logged in: the page has no toolbar of the site.', hint: 'Log in first: Given I am a logged in user with the "participant" user. A site that hides the toolbar from its members cannot tell the step whose profile "my" means.' });
|
|
61
|
+
}
|
|
62
|
+
return again;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const PROFILE_PAGES = {
|
|
66
|
+
'profile': '',
|
|
67
|
+
'topics started': 'topics/',
|
|
68
|
+
'replies created': 'replies/',
|
|
69
|
+
'engagements': 'engagements/',
|
|
70
|
+
'favorites': 'favorites/',
|
|
71
|
+
'subscriptions': 'subscriptions/',
|
|
72
|
+
'edit': 'edit/',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Open a page of the forum profile of an account. */
|
|
76
|
+
async function openProfile(world, login, page) {
|
|
77
|
+
const status = await visit(world, `${forumsRoot(world)}users/${encodeURIComponent(login)}/${PROFILE_PAGES[page || 'profile']}`);
|
|
78
|
+
const state = await forumPage(world);
|
|
79
|
+
if (state.kind !== 'profile') {
|
|
80
|
+
throw friendly({
|
|
81
|
+
message: `The forum profile of "${login}" did not open: the site answered ${status || 'nothing'} with ${state.heading ? `"${state.heading}"` : 'no page of the forums'} (${state.url}).`,
|
|
82
|
+
hint: 'A profile is found by the login name of its account. A blocked account, and a site whose forums are not at "/forums/" (worldParameters.forums.root), get no profile here.',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The toggle of the page (subscribe or favorite): its link, and whether it is on. */
|
|
88
|
+
async function toggleState(world, kind) {
|
|
89
|
+
return world.page.evaluate(([sel, kind]) => {
|
|
90
|
+
const box = document.querySelector(`${sel} #${kind === 'favorite' ? 'favorite' : 'subscription'}-toggle`);
|
|
91
|
+
if (!box) return null;
|
|
92
|
+
const link = box.querySelector('a');
|
|
93
|
+
const mark = box.querySelector(kind === 'favorite' ? '.is-favorite' : '.is-subscribed');
|
|
94
|
+
return { on: Boolean(mark), text: link ? link.textContent.trim() : '' };
|
|
95
|
+
}, [FORUMS, kind]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Click the subscribe or favorite link of the page and wait for the forums to mark it. */
|
|
99
|
+
async function toggle(world, kind, on, what) {
|
|
100
|
+
await settle(world);
|
|
101
|
+
const state = await toggleState(world, kind);
|
|
102
|
+
if (!state) {
|
|
103
|
+
throw friendly({
|
|
104
|
+
message: `The page offers this account no link to ${what}.`,
|
|
105
|
+
hint: kind === 'favorite'
|
|
106
|
+
? 'A logged-in account gets "Favorite" above a topic, when the forums\' "Favorites" setting allows it.'
|
|
107
|
+
: 'A logged-in account gets "Subscribe" above a topic and a forum, when the forums\' "Subscriptions" setting allows it.',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (state.on === on) return;
|
|
111
|
+
const id = kind === 'favorite' ? 'favorite' : 'subscription';
|
|
112
|
+
await world.page.locator(`${FORUMS} #${id}-toggle a`).first().click();
|
|
113
|
+
await eventually(world, () => toggleState(world, kind), (now) => now && now.on === on, (now) => ({
|
|
114
|
+
message: `Clicked "${state.text}", but the forums did not ${what}: the link still reads "${now ? now.text : ''}".`,
|
|
115
|
+
hint: 'The forums answer the click in place and turn the link into its opposite; a link whose security token is too old is refused, so load the page again.',
|
|
116
|
+
}), budget(world) * 3);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The rows of a list of the profile that is open: topics, or the subscribed forums. */
|
|
120
|
+
async function profileRows(world, list) {
|
|
121
|
+
if (list === 'subscribed forums') return (await listedForums(world)).map((f) => ({ name: f.name, remove: f.remove, id: `bbp-forum-${f.id}` }));
|
|
122
|
+
return (await listedTopics(world)).map((t) => ({ name: t.title, remove: t.remove, id: `bbp-topic-${t.id}` }));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const MY_LISTS = {
|
|
126
|
+
'favorites': 'favorites',
|
|
127
|
+
'subscribed topics': 'subscriptions',
|
|
128
|
+
'subscribed forums': 'subscriptions',
|
|
129
|
+
'topics started': 'topics started',
|
|
130
|
+
'engagements': 'engagements',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Subscriptions and favorites
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Subscribe the account to the topic or the forum that is open, or end the
|
|
139
|
+
* subscription, with the link above it; nothing happens when it is that way
|
|
140
|
+
* already.
|
|
141
|
+
*
|
|
142
|
+
* Example #1: When I subscribe to the topic
|
|
143
|
+
* Example #2: And I unsubscribe from the topic
|
|
144
|
+
* Example #3: When we subscribe to the forum
|
|
145
|
+
* Example #4: When I unsubscribe from the forum
|
|
146
|
+
* Example #5: And we subscribe to the topic
|
|
147
|
+
*/
|
|
148
|
+
When(/^(I |we )*(subscribe to|unsubscribe from) the (topic|forum)$/, async function (pronounCase, action, what) {
|
|
149
|
+
const page = await forumPage(this);
|
|
150
|
+
if (page.kind !== what) {
|
|
151
|
+
throw friendly({ message: `The page is not a ${what}: it is ${page.heading ? `"${page.heading}"` : 'no page of the forums'} (${page.url}).`, hint: `Open the ${what} first.` });
|
|
152
|
+
}
|
|
153
|
+
await toggle(this, 'subscription', action === 'subscribe to', `${action} the ${what}`);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Mark the topic that is open as a favorite of the account, or take the mark
|
|
158
|
+
* away, with the link above it; nothing happens when it is that way already.
|
|
159
|
+
*
|
|
160
|
+
* Example #1: When I favorite the topic
|
|
161
|
+
* Example #2: And I unfavorite the topic
|
|
162
|
+
* Example #3: When we favorite the topic
|
|
163
|
+
* Example #4: When we unfavorite the topic
|
|
164
|
+
* Example #5: And I favorite the topic
|
|
165
|
+
*/
|
|
166
|
+
When(/^(I |we )*(favorite|unfavorite) the topic$/, async function (pronounCase, action) {
|
|
167
|
+
await readingTopic(this);
|
|
168
|
+
await toggle(this, 'favorite', action === 'favorite', `${action} the topic`);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Assert the topic or the forum that is open is (or is not) subscribed to by
|
|
173
|
+
* the account, or the topic a favorite of it: what the link above it says.
|
|
174
|
+
*
|
|
175
|
+
* Example #1: Then the topic should be subscribed to
|
|
176
|
+
* Example #2: And the topic should be a favorite
|
|
177
|
+
* Example #3: Then the forum should not be subscribed to
|
|
178
|
+
* Example #4: Then the topic should not be a favorite
|
|
179
|
+
* Example #5: And the forum should be subscribed to
|
|
180
|
+
*/
|
|
181
|
+
Then(/^the (topic|forum) should( not)* be (subscribed to|a favorite)$/, async function (what, notCase, state) {
|
|
182
|
+
await settle(this);
|
|
183
|
+
const kind = state === 'a favorite' ? 'favorite' : 'subscription';
|
|
184
|
+
const now = await toggleState(this, kind);
|
|
185
|
+
if (!now) {
|
|
186
|
+
throw friendly({ message: `The page offers this account no ${kind} link (${this.page.url()}).`, hint: 'A logged-in account gets the links above a topic (Favorite, Subscribe) and a forum (Subscribe), when the forums\' settings allow them.' });
|
|
187
|
+
}
|
|
188
|
+
if (now.on === Boolean(notCase)) {
|
|
189
|
+
throw friendly({
|
|
190
|
+
message: notCase ? `Expected the ${what} not to be ${state}, but its link reads "${now.text}".` : `Expected the ${what} to be ${state}, but its link reads "${now.text}".`,
|
|
191
|
+
hint: 'A reply sent with "Notify me of follow-up replies via email" unchecked ends the subscription to its topic.',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Assert a list of the account's own forum profile has (or has not) a topic
|
|
198
|
+
* or a forum: its favorites, the topics or the forums it subscribed to, the
|
|
199
|
+
* topics it started, the topics it wrote in (engagements).
|
|
200
|
+
*
|
|
201
|
+
* Example #1: Then my favorites should list "Welcome to the forums"
|
|
202
|
+
* Example #2: And my subscribed topics should list "A community garden in spring"
|
|
203
|
+
* Example #3: Then my subscribed forums should list "Help and support"
|
|
204
|
+
* Example #4: Then my topics started should not list "Forum rules"
|
|
205
|
+
* Example #5: And my engagements should list "Welcome to the forums"
|
|
206
|
+
*/
|
|
207
|
+
Then(/^my (favorites|subscribed topics|subscribed forums|topics started|engagements) should( not)* list "([^"]*)"$/, async function (list, notCase, name) {
|
|
208
|
+
await openProfile(this, await currentLogin(this), MY_LISTS[list]);
|
|
209
|
+
const rows = await profileRows(this, list);
|
|
210
|
+
if (rows.some((r) => same(r.name, name)) === Boolean(notCase)) {
|
|
211
|
+
throw friendly({
|
|
212
|
+
message: notCase ? `Expected my ${list} not to list "${name}", but they do.` : `Expected my ${list} to list "${name}". They list: ${listed(rows.map((r) => r.name))}.`,
|
|
213
|
+
hint: 'The list is the one of the account\'s own forum profile, on its first page (15 topics a page).',
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Remove a topic or a forum from a list of the account's own forum profile,
|
|
220
|
+
* with the `×` of its row: its favorites, its subscribed topics or forums.
|
|
221
|
+
*
|
|
222
|
+
* Example #1: When I remove "Welcome to the forums" from my favorites
|
|
223
|
+
* Example #2: And I remove "A community garden in spring" from my subscribed topics
|
|
224
|
+
* Example #3: When we remove "Help and support" from my subscribed forums
|
|
225
|
+
* Example #4: When I remove "Forum rules" from my favorites
|
|
226
|
+
* Example #5: And we remove "A long conversation" from my subscribed topics
|
|
227
|
+
*/
|
|
228
|
+
When(/^(I |we )*remove "([^"]*)" from my (favorites|subscribed topics|subscribed forums)$/, async function (pronounCase, name, list) {
|
|
229
|
+
await openProfile(this, await currentLogin(this), MY_LISTS[list]);
|
|
230
|
+
const rows = await profileRows(this, list);
|
|
231
|
+
const row = rows.find((r) => same(r.name, name));
|
|
232
|
+
if (!row) {
|
|
233
|
+
throw friendly({ message: `My ${list} do not list "${name}". They list: ${listed(rows.map((r) => r.name))}.`, hint: 'Only what the list shows can be removed from it.' });
|
|
234
|
+
}
|
|
235
|
+
await this.page.locator(`${FORUMS} #${row.id} .bbp-row-actions a`).first().click();
|
|
236
|
+
await eventually(this, () => profileRows(this, list), (now) => !now.some((r) => same(r.name, name)), () => ({
|
|
237
|
+
message: `Clicked the × of "${name}", but my ${list} still list it.`,
|
|
238
|
+
hint: 'The forums take the row away in place.',
|
|
239
|
+
}), budget(this) * 3);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Empty the account's favorites or subscriptions (topics and forums), so a
|
|
244
|
+
* scenario starts from none whatever an earlier run left.
|
|
245
|
+
*
|
|
246
|
+
* Example #1: Given I have no favorites
|
|
247
|
+
* Example #2: And I have no subscriptions
|
|
248
|
+
* Example #3: Given we have no favorites
|
|
249
|
+
* Example #4: Given we have no subscriptions
|
|
250
|
+
* Example #5: And I have no favorites
|
|
251
|
+
*/
|
|
252
|
+
Given(/^(I |we )*have no (favorites|subscriptions)$/, async function (pronounCase, what) {
|
|
253
|
+
const login = await currentLogin(this);
|
|
254
|
+
for (let round = 0; round < 60; round += 1) {
|
|
255
|
+
await openProfile(this, login, what);
|
|
256
|
+
const row = this.page.locator(`${FORUMS} #bbp-user-body .bbp-row-actions a`).first();
|
|
257
|
+
if (!(await row.count())) return;
|
|
258
|
+
// Each removal is a link of its own: followed as a page, so the next round reads the list again.
|
|
259
|
+
await navigate(this, await row.evaluate((a) => a.href));
|
|
260
|
+
}
|
|
261
|
+
throw friendly({ message: `Could not empty my ${what}: the list still has rows after 60 removals.`, hint: 'Look at the list in the profile.' });
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
// The forum profile
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Open the forum profile of an account, by a handle of the users registry or
|
|
270
|
+
* its login name; "my forum profile" is the logged-in account's.
|
|
271
|
+
*
|
|
272
|
+
* Example #1: When I open the forum profile of "participant"
|
|
273
|
+
* Example #2: And I open the forum profile of "moderator"
|
|
274
|
+
* Example #3: When we open the forum profile of "keymaster"
|
|
275
|
+
* Example #4: When I open my forum profile
|
|
276
|
+
* Example #5: And we open my forum profile
|
|
277
|
+
*/
|
|
278
|
+
When(/^(I |we )*open (?:the forum profile of "([^"]*)"|my forum profile)$/, async function (pronounCase, who) {
|
|
279
|
+
await openProfile(this, who ? loginOf(this, who) : await currentLogin(this));
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Open a page of the forum profile that is open, by the name its menu gives
|
|
284
|
+
* it: Profile, Topics Started, Replies Created, Engagements, Favorites,
|
|
285
|
+
* Subscriptions, Edit.
|
|
286
|
+
*
|
|
287
|
+
* Example #1: When I open "Topics Started" in the forum profile
|
|
288
|
+
* Example #2: And I open "Replies Created" in the forum profile
|
|
289
|
+
* Example #3: When we open "Favorites" in the forum profile
|
|
290
|
+
* Example #4: When I open "Subscriptions" in the forum profile
|
|
291
|
+
* Example #5: And I open "Edit" in the forum profile
|
|
292
|
+
*/
|
|
293
|
+
When(/^(I |we )*open "([^"]*)" in the forum profile$/, async function (pronounCase, name) {
|
|
294
|
+
await settle(this);
|
|
295
|
+
const links = await this.page.evaluate((sel) => [...document.querySelectorAll(`${sel} #bbp-user-navigation li a`)].map((a) => ({ text: a.textContent.replace(/\s+/g, ' ').trim(), href: a.href })), FORUMS);
|
|
296
|
+
const link = links.find((l) => same(l.text, name));
|
|
297
|
+
if (!link) {
|
|
298
|
+
throw friendly({
|
|
299
|
+
message: links.length ? `The forum profile offers no page "${name}". It offers: ${listed(links.map((l) => l.text))}.` : `The page is not a forum profile (${this.page.url()}).`,
|
|
300
|
+
hint: 'Open a profile first: When I open the forum profile of "…". Subscriptions and Edit are offered on the account\'s own profile only.',
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
await navigate(this, link.href);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Assert the forum profile that is open offers (or does not offer) a page
|
|
308
|
+
* in its menu.
|
|
309
|
+
*
|
|
310
|
+
* Example #1: Then the forum profile should offer the page "Subscriptions"
|
|
311
|
+
* Example #2: And the forum profile should not offer the page "Edit"
|
|
312
|
+
* Example #3: Then the forum profile should offer the page "Favorites"
|
|
313
|
+
* Example #4: Then the forum profile should not offer the page "Subscriptions"
|
|
314
|
+
* Example #5: And the forum profile should offer the page "Topics Started"
|
|
315
|
+
*/
|
|
316
|
+
Then(/^the forum profile should( not)* offer the page "([^"]*)"$/, async function (notCase, name) {
|
|
317
|
+
await settle(this);
|
|
318
|
+
const page = await forumPage(this);
|
|
319
|
+
if (page.kind !== 'profile') throw friendly({ message: `The page is not a forum profile: it is ${page.heading ? `"${page.heading}"` : 'no page of the forums'} (${page.url}).`, hint: 'Open one first: When I open the forum profile of "…".' });
|
|
320
|
+
const links = await this.page.evaluate((sel) => [...document.querySelectorAll(`${sel} #bbp-user-navigation li a`)].map((a) => a.textContent.replace(/\s+/g, ' ').trim()), FORUMS);
|
|
321
|
+
if (links.some((l) => same(l, name)) === Boolean(notCase)) {
|
|
322
|
+
throw friendly({
|
|
323
|
+
message: notCase ? `Expected the forum profile not to offer "${name}", but it does.` : `Expected the forum profile to offer "${name}". It offers: ${listed(links)}.`,
|
|
324
|
+
hint: 'Subscriptions and Edit are offered on the account\'s own profile, and to an account that may edit users.',
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Assert the forum profile that is open shows (or does not show) a text: the
|
|
331
|
+
* account's name, its counters ("Topics Started: 12"), its forum role
|
|
332
|
+
* ("Forum Role: Moderator"), the rows of the list that is open.
|
|
333
|
+
*
|
|
334
|
+
* Example #1: Then the forum profile should show "Forum Role: Participant"
|
|
335
|
+
* Example #2: And the forum profile should show "@participant"
|
|
336
|
+
* Example #3: Then the forum profile should not show "Forum Role: Keymaster"
|
|
337
|
+
* Example #4: Then the forum profile should show "Topics Started: 12"
|
|
338
|
+
* Example #5: And the forum profile should show "Oh, bother! No topics were found here."
|
|
339
|
+
*/
|
|
340
|
+
Then(/^the forum profile should( not)* show "([^"]*)"$/, async function (notCase, text) {
|
|
341
|
+
const read = async () => {
|
|
342
|
+
const page = await forumPage(this);
|
|
343
|
+
if (page.kind !== 'profile') return null;
|
|
344
|
+
return this.page.evaluate((sel) => document.querySelector(`${sel} #bbp-user-body`).innerText.replace(/\s+/g, ' ').trim(), FORUMS);
|
|
345
|
+
};
|
|
346
|
+
if (notCase) {
|
|
347
|
+
await settle(this);
|
|
348
|
+
const body = await read();
|
|
349
|
+
if (body === null) throw friendly({ message: `The page is not a forum profile (${this.page.url()}).`, hint: 'Open one first: When I open the forum profile of "…".' });
|
|
350
|
+
if (holds(body, text)) throw friendly({ message: `Expected the forum profile not to show "${text}", but it does.`, hint: 'The text is matched as a part of the profile\'s body, letter case aside.' });
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
await eventually(this, read, (body) => body !== null && holds(body, text), (body) => ({
|
|
354
|
+
message: body === null || body === undefined ? `The page is not a forum profile (${this.page.url()}).` : `Expected the forum profile to show "${text}". It shows: "${clean(body).slice(0, 300)}".`,
|
|
355
|
+
hint: 'The text is matched as a part of the profile\'s body, letter case aside.',
|
|
356
|
+
}), 3000);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Assert the forum role of an account, as its forum profile states it:
|
|
361
|
+
* Keymaster, Moderator, Participant, Spectator or Blocked.
|
|
362
|
+
*
|
|
363
|
+
* Example #1: Then the forum role of "moderator" should be "Moderator"
|
|
364
|
+
* Example #2: And the forum role of "participant" should be "Participant"
|
|
365
|
+
* Example #3: Then the forum role of "keymaster" should be "Keymaster"
|
|
366
|
+
* Example #4: Then the forum role of "spectator" should be "Spectator"
|
|
367
|
+
* Example #5: And the forum role of "admin" should be "Keymaster"
|
|
368
|
+
*/
|
|
369
|
+
Then(/^the forum role of "([^"]*)" should be "([^"]*)"$/, async function (who, role) {
|
|
370
|
+
await openProfile(this, loginOf(this, who));
|
|
371
|
+
const actual = await this.page.evaluate((sel) => {
|
|
372
|
+
const line = [...document.querySelectorAll(`${sel} #bbp-user-body p.bbp-user-forum-role`)].map((p) => p.textContent.replace(/\s+/g, ' ').trim()).find((t) => /^Forum Role:/i.test(t));
|
|
373
|
+
return line ? line.replace(/^Forum Role:\s*/i, '') : '';
|
|
374
|
+
}, FORUMS);
|
|
375
|
+
if (!same(actual, role)) {
|
|
376
|
+
throw friendly({
|
|
377
|
+
message: `Expected the forum role of "${who}" to be "${role}", but the profile says "${actual || '(none)'}".`,
|
|
378
|
+
hint: 'The forum role is apart from the role on the site: an administrator is a Keymaster, a new account a Participant unless the forums\' settings say otherwise.',
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Save the edit form of the forum profile that is open ("Update Profile"),
|
|
385
|
+
* and wait for the forums' answer: "User updated."
|
|
386
|
+
*
|
|
387
|
+
* Example #1: When I save my forum profile
|
|
388
|
+
* Example #2: And I save my forum profile
|
|
389
|
+
* Example #3: When we save my forum profile
|
|
390
|
+
* Example #4: And we save my forum profile
|
|
391
|
+
* Example #5: When I save my forum profile
|
|
392
|
+
*/
|
|
393
|
+
When(/^(I |we )*save my forum profile$/, async function (pronounCase) {
|
|
394
|
+
const button = this.page.locator(`${FORUMS} form#bbp-your-profile #bbp_user_edit_submit`);
|
|
395
|
+
if (!(await button.count())) {
|
|
396
|
+
throw friendly({ message: `The page has no edit form of a forum profile (${this.page.url()}).`, hint: 'Open it first: When I open my forum profile, then When I open "Edit" in the forum profile.' });
|
|
397
|
+
}
|
|
398
|
+
await clickAndLoad(this, button, 'save the forum profile');
|
|
399
|
+
const notices = await forumNotices(this);
|
|
400
|
+
const errors = notices.filter((n) => n.kind === 'error').map((n) => n.text);
|
|
401
|
+
if (errors.length) throw friendly({ message: `The forums refused the profile: ${listed(errors)}.`, hint: 'The email must be an address no other account has; a new password must be typed twice.' });
|
|
402
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Finding topics: the forum search (its form, its results, opening one), the
|
|
4
|
+
// pages of a topic tag, and the views of the forums ("Most popular topics",
|
|
5
|
+
// "Topics with no replies").
|
|
6
|
+
//
|
|
7
|
+
// The search answers with a page of its own (`/forums/search/<words>/`): its
|
|
8
|
+
// results are topics and replies together, each headed by the topic it
|
|
9
|
+
// belongs to.
|
|
10
|
+
|
|
11
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
12
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
13
|
+
const {
|
|
14
|
+
FORUMS,
|
|
15
|
+
settle,
|
|
16
|
+
navigate,
|
|
17
|
+
visit,
|
|
18
|
+
supplied,
|
|
19
|
+
clean,
|
|
20
|
+
listed,
|
|
21
|
+
same,
|
|
22
|
+
holds,
|
|
23
|
+
clickAndLoad,
|
|
24
|
+
forumsRoot,
|
|
25
|
+
gotoForumIndex,
|
|
26
|
+
forumPage,
|
|
27
|
+
forumNotices,
|
|
28
|
+
listTotal,
|
|
29
|
+
readingTopic,
|
|
30
|
+
} = require('./bbpress-helpers');
|
|
31
|
+
|
|
32
|
+
/** The results of the search page: a topic or a reply each, with its topic, its forum, its author and its text. */
|
|
33
|
+
async function searchResults(world) {
|
|
34
|
+
return world.page.evaluate((sel) => {
|
|
35
|
+
const text = (el) => (el ? el.textContent.replace(/\s+/g, ' ').trim() : '');
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const body of document.querySelectorAll(`${sel} #bbp-search-results li.bbp-body > div[id^="post-"]`)) {
|
|
38
|
+
const header = body.previousElementSibling;
|
|
39
|
+
const isTopic = body.classList.contains('type-topic');
|
|
40
|
+
const link = header ? header.querySelector(isTopic ? '.bbp-topic-title h3 a' : '.bbp-reply-title h3 a') : null;
|
|
41
|
+
out.push({
|
|
42
|
+
kind: isTopic ? 'topic' : 'reply',
|
|
43
|
+
topic: text(link),
|
|
44
|
+
href: (isTopic ? (link && link.href) : ((header && header.querySelector('a.bbp-reply-permalink')) || {}).href) || '',
|
|
45
|
+
forum: isTopic && header ? text(header.querySelector('.bbp-topic-title-meta a')) : '',
|
|
46
|
+
author: text(body.querySelector('.bbp-author-name')),
|
|
47
|
+
text: text(body.querySelector('.bbp-topic-content, .bbp-reply-content')),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}, FORUMS).catch(() => []);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Assert the page is the search's, or fail. */
|
|
55
|
+
async function onSearch(world) {
|
|
56
|
+
const page = await forumPage(world);
|
|
57
|
+
if (page.kind !== 'search') {
|
|
58
|
+
throw friendly({ message: `The page is not the forum search: it is ${page.heading ? `"${page.heading}"` : 'no page of the forums'} (${page.url}).`, hint: 'Search first: When I search the forums for "…".' });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Search the forums with the search form of the forum index; the step waits
|
|
64
|
+
* for the results page.
|
|
65
|
+
*
|
|
66
|
+
* Example #1: When I search the forums for "marigolds"
|
|
67
|
+
* Example #2: And I search the forums for "password"
|
|
68
|
+
* Example #3: When we search the forums for "long conversation"
|
|
69
|
+
* Example #4: When I search the forums for "nothingmatchesthisword"
|
|
70
|
+
* Example #5: And we search the forums for "Showcase entry 07"
|
|
71
|
+
*/
|
|
72
|
+
When(/^(I |we )*search the forums for "([^"]*)"$/, async function (pronounCase, words) {
|
|
73
|
+
let field = this.page.locator(`${FORUMS} #bbp-search-form #bbp_search`);
|
|
74
|
+
if (!(await field.count())) {
|
|
75
|
+
await gotoForumIndex(this);
|
|
76
|
+
field = this.page.locator(`${FORUMS} #bbp-search-form #bbp_search`);
|
|
77
|
+
}
|
|
78
|
+
if (!(await field.count())) {
|
|
79
|
+
throw friendly({ message: `The forum index has no search form (${this.page.url()}).`, hint: 'The forums\' "Search" setting turns the forum-wide search on; a blocked account gets no forum index.' });
|
|
80
|
+
}
|
|
81
|
+
await field.fill(words);
|
|
82
|
+
await clickAndLoad(this, this.page.locator(`${FORUMS} #bbp-search-form #bbp_search_submit`), 'search the forums');
|
|
83
|
+
await onSearch(this);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Assert how many results the forum search found in all, over its pages
|
|
88
|
+
* ("Viewing 2 results - 1 through 2 (of 2 total)"); 0 when it found none.
|
|
89
|
+
*
|
|
90
|
+
* Example #1: Then the search should find 2 matches
|
|
91
|
+
* Example #2: And the search should find 1 match
|
|
92
|
+
* Example #3: Then the search should find 0 matches
|
|
93
|
+
* Example #4: Then the search should find 18 matches
|
|
94
|
+
* Example #5: And the search should find 3 matches
|
|
95
|
+
*/
|
|
96
|
+
Then(/^the search should find (\d+) match(?:es)?$/, async function (count) {
|
|
97
|
+
await settle(this);
|
|
98
|
+
await onSearch(this);
|
|
99
|
+
const total = await listTotal(this);
|
|
100
|
+
const actual = total && total.total !== null ? total.total : (await searchResults(this)).length;
|
|
101
|
+
if (actual !== Number(count)) {
|
|
102
|
+
const notices = (await forumNotices(this)).map((n) => n.text);
|
|
103
|
+
throw friendly({
|
|
104
|
+
message: `Expected the search to find ${count} match(es), but it found ${actual}${total ? ` ("${clean(total.text)}")` : (notices.length ? `: ${listed(notices)}` : '')}.`,
|
|
105
|
+
hint: 'The search counts topics and replies, each a match of its own, in the forums the account may read.',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Assert the results of the forum search show (or do not show) a text: the
|
|
112
|
+
* title of a topic, or a part of a post.
|
|
113
|
+
*
|
|
114
|
+
* Example #1: Then the search results should show "A community garden in spring"
|
|
115
|
+
* Example #2: And the search results should show "Marigolds keep the aphids away"
|
|
116
|
+
* Example #3: Then the search results should not show "Staff only"
|
|
117
|
+
* Example #4: Then the search results should show "How do I change my password?"
|
|
118
|
+
* Example #5: And the search results should not show "Members only"
|
|
119
|
+
*/
|
|
120
|
+
Then(/^the search results should( not)* show "([^"]*)"$/, async function (notCase, text) {
|
|
121
|
+
await settle(this);
|
|
122
|
+
await onSearch(this);
|
|
123
|
+
const results = await searchResults(this);
|
|
124
|
+
const hit = results.some((r) => holds(r.topic, text) || holds(r.text, text));
|
|
125
|
+
if (hit === Boolean(notCase)) {
|
|
126
|
+
throw friendly({
|
|
127
|
+
message: notCase
|
|
128
|
+
? `Expected the search results not to show "${text}", but they do.`
|
|
129
|
+
: `Expected the search results to show "${text}". ${results.length ? `They show: ${listed(results.map((r) => `${r.kind} in "${r.topic}": ${r.text.slice(0, 60)}`))}` : 'The search found nothing'}.`,
|
|
130
|
+
hint: 'The step reads the page of the results that is open: the topic each result belongs to, and its text.',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Assert a result of the forum search is a topic or a reply, by the topic it
|
|
137
|
+
* belongs to, and for a topic the forum the result names.
|
|
138
|
+
*
|
|
139
|
+
* Example #1: Then the search result "A community garden in spring" should be a topic in "General discussion"
|
|
140
|
+
* Example #2: And the search result "A community garden in spring" should be a reply
|
|
141
|
+
* Example #3: Then the search result "How do I change my password?" should be a topic in "Help and support"
|
|
142
|
+
* Example #4: Then the search result "Welcome to the forums" should be a reply
|
|
143
|
+
* Example #5: And the search result "A long conversation" should be a topic
|
|
144
|
+
*/
|
|
145
|
+
Then(/^the search result "([^"]*)" should be a (topic|reply)(?: in "([^"]*)")?$/, async function (title, kind, forum) {
|
|
146
|
+
await settle(this);
|
|
147
|
+
await onSearch(this);
|
|
148
|
+
const results = (await searchResults(this)).filter((r) => same(r.topic, title));
|
|
149
|
+
const found = results.find((r) => r.kind === kind);
|
|
150
|
+
if (!found) {
|
|
151
|
+
throw friendly({
|
|
152
|
+
message: results.length
|
|
153
|
+
? `The search results of "${title}" are ${listed(results.map((r) => `a ${r.kind}`))}, none a ${kind}.`
|
|
154
|
+
: `The search results name no topic "${title}".`,
|
|
155
|
+
hint: 'A topic is a result when its title or its own post matches; a reply when the reply matches, headed "In reply to: <topic>".',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (supplied(forum) && !same(found.forum, forum)) {
|
|
159
|
+
throw friendly({ message: `The search result "${title}" is in the forum "${found.forum || '(not named)'}", not in "${forum}".`, hint: 'A topic among the results names its forum; a reply names its topic only.' });
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Open a result of the forum search, by the topic it belongs to: the topic
|
|
165
|
+
* itself when it is among the results, else its first reply there.
|
|
166
|
+
*
|
|
167
|
+
* Example #1: When I open the search result "A community garden in spring"
|
|
168
|
+
* Example #2: And I open the search result "How do I change my password?"
|
|
169
|
+
* Example #3: When we open the search result "A long conversation"
|
|
170
|
+
* Example #4: When I open the search result "Welcome to the forums"
|
|
171
|
+
* Example #5: And we open the search result "Forum rules"
|
|
172
|
+
*/
|
|
173
|
+
When(/^(I |we )*open the search result "([^"]*)"$/, async function (pronounCase, title) {
|
|
174
|
+
await settle(this);
|
|
175
|
+
await onSearch(this);
|
|
176
|
+
const results = await searchResults(this);
|
|
177
|
+
const mine = results.filter((r) => same(r.topic, title));
|
|
178
|
+
const result = mine.find((r) => r.kind === 'topic') || mine[0];
|
|
179
|
+
if (!result || !result.href) {
|
|
180
|
+
throw friendly({ message: `The search results name no topic "${title}". They name: ${listed([...new Set(results.map((r) => r.topic))])}.`, hint: 'A result is opened by the title of the topic it belongs to.' });
|
|
181
|
+
}
|
|
182
|
+
await navigate(this, result.href);
|
|
183
|
+
await readingTopic(this, title);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Open the page of a topic tag: the topics that carry it, from every forum
|
|
188
|
+
* the account may read.
|
|
189
|
+
*
|
|
190
|
+
* Example #1: When I open the topic tag "spring"
|
|
191
|
+
* Example #2: And I open the topic tag "howto"
|
|
192
|
+
* Example #3: When we open the topic tag "showcase"
|
|
193
|
+
* Example #4: When I open the topic tag "account"
|
|
194
|
+
* Example #5: And we open the topic tag "welcome"
|
|
195
|
+
*/
|
|
196
|
+
When(/^(I |we )*open the topic tag "([^"]*)"$/, async function (pronounCase, tag) {
|
|
197
|
+
// The tag of a topic that is open is a link; any other is reached by its address.
|
|
198
|
+
const link = await this.page.evaluate(([sel, wanted]) => {
|
|
199
|
+
const norm = (t) => t.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
200
|
+
const found = [...document.querySelectorAll(`${sel} .bbp-topic-tags a`)].find((a) => norm(a.textContent) === norm(wanted));
|
|
201
|
+
return found ? found.href : '';
|
|
202
|
+
}, [FORUMS, tag]).catch(() => '');
|
|
203
|
+
const slug = clean(tag).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
204
|
+
const status = await visit(this, link || `${forumsRoot(this)}topic-tag/${slug}/`);
|
|
205
|
+
const page = await forumPage(this);
|
|
206
|
+
if (page.kind !== 'tag') {
|
|
207
|
+
throw friendly({
|
|
208
|
+
message: `The forums have no page for the topic tag "${tag}": the site answered ${status || 'nothing'} (${page.url}).`,
|
|
209
|
+
hint: 'A tag has a page once a topic the account may read carries it. The forums\' "Topic tags" setting turns tags on.',
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Open a view of the forums by the name its page carries: "Most popular
|
|
216
|
+
* topics", "Topics with no replies".
|
|
217
|
+
*
|
|
218
|
+
* Example #1: When I open the forum view "Most popular topics"
|
|
219
|
+
* Example #2: And I open the forum view "Topics with no replies"
|
|
220
|
+
* Example #3: When we open the forum view "Most popular topics"
|
|
221
|
+
* Example #4: When we open the forum view "Topics with no replies"
|
|
222
|
+
* Example #5: And I open the forum view "Most popular topics"
|
|
223
|
+
*/
|
|
224
|
+
When(/^(I |we )*open the forum view "([^"]*)"$/, async function (pronounCase, name) {
|
|
225
|
+
const views = { 'most popular topics': 'popular', 'topics with no replies': 'no-replies' };
|
|
226
|
+
const slug = views[clean(name).toLowerCase()] || clean(name).toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
227
|
+
const status = await visit(this, `${forumsRoot(this)}view/${slug}/`);
|
|
228
|
+
const page = await forumPage(this);
|
|
229
|
+
if (page.kind !== 'view') {
|
|
230
|
+
throw friendly({
|
|
231
|
+
message: `The forums have no view "${name}": the site answered ${status || 'nothing'} (${page.url}).`,
|
|
232
|
+
hint: `The views the forums come with: ${Object.keys(views).map((v) => `"${v[0].toUpperCase()}${v.slice(1)}"`).join(', ')}. A view a plugin adds is named by its address ("my-view" for /forums/view/my-view/).`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
});
|