@webship-js/mediawiki-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.
- package/LICENSE +21 -0
- package/README.md +550 -2
- package/package.json +63 -4
- package/tests/features/README.md +26 -0
- package/tests/features/accessibility.feature +16 -0
- package/tests/features/account-creation.feature +28 -0
- package/tests/features/administration.feature +49 -0
- package/tests/features/categories.feature +28 -0
- package/tests/features/edit-conflict.feature +15 -0
- package/tests/features/history.feature +30 -0
- package/tests/features/preferences.feature +15 -0
- package/tests/features/reading.feature +84 -0
- package/tests/features/search.feature +34 -0
- package/tests/features/session.feature +43 -0
- package/tests/features/source-editor.feature +42 -0
- package/tests/features/talk-page.feature +19 -0
- package/tests/features/upload.feature +20 -0
- package/tests/features/visual-editor.feature +18 -0
- package/tests/features/watchlist.feature +24 -0
- package/tests/fixtures/blue-square.png +0 -0
- package/tests/step-definitions/README.md +41 -0
- package/tests/step-definitions/mediawiki-admin.steps.js +241 -0
- package/tests/step-definitions/mediawiki-editing.steps.js +413 -0
- package/tests/step-definitions/mediawiki-files.steps.js +93 -0
- package/tests/step-definitions/mediawiki-helpers.js +768 -0
- package/tests/step-definitions/mediawiki-history.steps.js +135 -0
- package/tests/step-definitions/mediawiki-pages.steps.js +710 -0
- package/tests/step-definitions/mediawiki-search.steps.js +234 -0
- package/tests/step-definitions/mediawiki-session.steps.js +287 -0
- package/tests/step-definitions/mediawiki-watchlist.steps.js +265 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Pages: the test pages a scenario works on (made, protected and deleted again
|
|
4
|
+
// through the wiki's API, as the administrator of the users registry), opening a
|
|
5
|
+
// page by its title, and what a reader sees on it: its title, its sections and
|
|
6
|
+
// contents list, its links, its references, its categories, the category tree of
|
|
7
|
+
// a category page, and its talk page.
|
|
8
|
+
//
|
|
9
|
+
// A test page is made by the scenario and deleted after it, whatever happens in
|
|
10
|
+
// it (the After hook below), so the suite leaves the wiki as it found it. A page a
|
|
11
|
+
// person made is never overwritten: "has the text" changes only a page that a
|
|
12
|
+
// test scenario made (its latest edit summary carries the marker).
|
|
13
|
+
|
|
14
|
+
const { Before, After, Given, When, Then } = require('@cucumber/cucumber');
|
|
15
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
16
|
+
const {
|
|
17
|
+
budget,
|
|
18
|
+
clean,
|
|
19
|
+
listed,
|
|
20
|
+
titleKey,
|
|
21
|
+
titleText,
|
|
22
|
+
config,
|
|
23
|
+
cutRequest,
|
|
24
|
+
CUT_HINT,
|
|
25
|
+
settle,
|
|
26
|
+
pageModulesReady,
|
|
27
|
+
openPage,
|
|
28
|
+
afterNavigation,
|
|
29
|
+
eventually,
|
|
30
|
+
shownTitle,
|
|
31
|
+
pageSummary,
|
|
32
|
+
messages,
|
|
33
|
+
closeWelcomeDialog,
|
|
34
|
+
fixturePath,
|
|
35
|
+
MARKER,
|
|
36
|
+
adminApi,
|
|
37
|
+
pageInfo,
|
|
38
|
+
apiEdit,
|
|
39
|
+
apiDelete,
|
|
40
|
+
apiProtect,
|
|
41
|
+
apiUpload,
|
|
42
|
+
apiUnblock,
|
|
43
|
+
waitForJobs,
|
|
44
|
+
waitForCategoryCounts,
|
|
45
|
+
categoriesOf,
|
|
46
|
+
resolveUser,
|
|
47
|
+
} = require('./mediawiki-helpers');
|
|
48
|
+
|
|
49
|
+
// What a scenario made or changed on the wiki, undone after it.
|
|
50
|
+
Before(function () {
|
|
51
|
+
this.__wikiCleanup = { pages: new Set(), blocks: new Set() };
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
After({ timeout: 120000 }, async function () {
|
|
55
|
+
const cleanup = this.__wikiCleanup;
|
|
56
|
+
if (!cleanup || (!cleanup.pages.size && !cleanup.blocks.size)) return;
|
|
57
|
+
const problems = [];
|
|
58
|
+
for (const name of cleanup.blocks) {
|
|
59
|
+
try { await apiUnblock(this, name, 'Cleanup after a test scenario'); } catch (err) { problems.push(`unblock ${name}: ${clean(err.message).slice(0, 120)}`); }
|
|
60
|
+
}
|
|
61
|
+
for (const title of cleanup.pages) {
|
|
62
|
+
const talk = talkTitle(title);
|
|
63
|
+
for (const t of talk ? [title, talk] : [title]) {
|
|
64
|
+
try { await apiDelete(this, t, 'Cleanup after a test scenario'); } catch (err) { problems.push(`delete ${t}: ${clean(err.message).slice(0, 120)}`); }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (problems.length) process.stderr.write(`\n[mediawiki-steps] cleanup after the scenario left work undone: ${problems.join('; ')}\n`);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** The talk page of a title ("Talk:X" of "X", "User talk:X" of "User:X"), or '' for a talk page. */
|
|
71
|
+
function talkTitle(title) {
|
|
72
|
+
const t = titleText(title);
|
|
73
|
+
const m = t.match(/^([^:]+):(.+)$/);
|
|
74
|
+
const namespaces = { Category: 'Category talk', File: 'File talk', User: 'User talk', Help: 'Help talk', Template: 'Template talk', Project: 'Project talk' };
|
|
75
|
+
if (!m) return `Talk:${t}`;
|
|
76
|
+
if (/talk$/i.test(m[1])) return '';
|
|
77
|
+
return namespaces[m[1]] ? `${namespaces[m[1]]}:${m[2]}` : '';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Register a title for deletion after the scenario. */
|
|
81
|
+
function cleanUpAfter(world, title) {
|
|
82
|
+
if (!world.__wikiCleanup) world.__wikiCleanup = { pages: new Set(), blocks: new Set() };
|
|
83
|
+
world.__wikiCleanup.pages.add(titleText(title));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Make or change a test page; a page a person made is not touched. */
|
|
87
|
+
async function writeTestPage(world, title, text, summary) {
|
|
88
|
+
const info = await pageInfo(world, title);
|
|
89
|
+
const ours = !info.exists || (world.__wikiCleanup && world.__wikiCleanup.pages.has(titleText(title))) || (info.revision && info.revision.comment.includes(MARKER));
|
|
90
|
+
if (!ours) {
|
|
91
|
+
throw friendly({
|
|
92
|
+
message: `The page "${titleText(title)}" is on the wiki already and a test scenario did not make it (its latest edit: "${info.revision ? info.revision.comment : ''}" by ${info.revision ? info.revision.user : '?'}).`,
|
|
93
|
+
hint: 'A test page is deleted after the scenario: give the scenario a page of its own, with a title no person uses, or say first that the page does not exist ("Given the page ... does not exist").',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
cleanUpAfter(world, title);
|
|
97
|
+
const before = info.exists && info.revision ? categoriesOf(info.revision.text) : [];
|
|
98
|
+
await apiEdit(world, title, text, `${summary || 'Test page of a scenario'} ${MARKER}`);
|
|
99
|
+
await waitForJobs(world);
|
|
100
|
+
// The categories the page is put in (and taken out of) get their counts once a job of the wiki ran.
|
|
101
|
+
await waitForCategoryCounts(world, before.concat(categoriesOf(text)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Make a test page with wikitext, through the wiki's API as the administrator of
|
|
106
|
+
* the users registry (`worldParameters.wikiAdmin`). The page is deleted after the
|
|
107
|
+
* scenario. Run again, it makes a new revision of the same test page.
|
|
108
|
+
*
|
|
109
|
+
* Example #1: Given the page "Reading test page" has the text:
|
|
110
|
+
* Example #2: Given the page "Category:Test guides" has the text:
|
|
111
|
+
* Example #3: And the page "Second test page" has the text:
|
|
112
|
+
* Example #4: Given the page "Talk:Reading test page" has the text:
|
|
113
|
+
* Example #5: Given the page "History test page" has the text:
|
|
114
|
+
*/
|
|
115
|
+
Given(/^the page "([^"]*)" has the text:$/, { timeout: 90000 }, async function (title, text) {
|
|
116
|
+
await writeTestPage(this, title, String(text));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Make a test page with one line of wikitext, as the step above ("\n" starts a
|
|
121
|
+
* new line), with an edit summary of its own when given (the history lists the
|
|
122
|
+
* revision by it).
|
|
123
|
+
*
|
|
124
|
+
* Example #1: Given the page "History test page" has the text "First version of the page." with the summary "First version"
|
|
125
|
+
* Example #2: And the page "History test page" has the text "Second version of the page." with the summary "Second version"
|
|
126
|
+
* Example #3: Given the page "Editing test page" has the text "Words to change."
|
|
127
|
+
* Example #4: Given the page "Category:Test guides" has the text "Guides of the test wiki."
|
|
128
|
+
* Example #5: Given the page "Conflict test page" has the text "The first line."
|
|
129
|
+
*/
|
|
130
|
+
Given(/^the page "([^"]*)" has the text "([^"]*)"(?: with the summary "([^"]*)")?$/, { timeout: 90000 }, async function (title, text, summary) {
|
|
131
|
+
await writeTestPage(this, title, text.replace(/\\n/g, '\n'), summary);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Make sure a page is not on the wiki (it is deleted through the API when it is),
|
|
136
|
+
* and delete it again after the scenario: for the page the scenario makes itself.
|
|
137
|
+
*
|
|
138
|
+
* Example #1: Given the page "Page made in the source editor" does not exist
|
|
139
|
+
* Example #2: Given the page "Talk:Reading test page" does not exist
|
|
140
|
+
* Example #3: And the page "File:Test square.png" does not exist
|
|
141
|
+
* Example #4: Given the page "Visual editor test page" does not exist
|
|
142
|
+
* Example #5: Given the page "Deletion test page" does not exist
|
|
143
|
+
*/
|
|
144
|
+
Given(/^the page "([^"]*)" does not exist$/, { timeout: 90000 }, async function (title) {
|
|
145
|
+
cleanUpAfter(this, title);
|
|
146
|
+
await apiDelete(this, title, `Test page of a scenario ${MARKER}`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Protect a test page through the API: only autoconfirmed users (the "confirmed"
|
|
151
|
+
* group and established accounts) or only administrators may edit or move it.
|
|
152
|
+
*
|
|
153
|
+
* Example #1: Given the page "Protected test page" is protected so that only autoconfirmed users can edit it
|
|
154
|
+
* Example #2: Given the page "Protected test page" is protected so that only administrators can edit it
|
|
155
|
+
* Example #3: And the page "Second test page" is protected so that only administrators can edit it
|
|
156
|
+
* Example #4: Given the page "Reading test page" is protected so that only autoconfirmed users can edit it
|
|
157
|
+
* Example #5: And the page "History test page" is protected so that only autoconfirmed users can edit it
|
|
158
|
+
*/
|
|
159
|
+
Given(/^the page "([^"]*)" is protected so that only (autoconfirmed users|administrators) can edit it$/, { timeout: 60000 }, async function (title, who) {
|
|
160
|
+
if (!this.__wikiCleanup || !this.__wikiCleanup.pages.has(titleText(title))) {
|
|
161
|
+
throw friendly({ message: `"${titleText(title)}" is not a test page of this scenario.`, hint: 'Make it first ("Given the page ... has the text ..."): only a test page is protected, and it is deleted after the scenario.' });
|
|
162
|
+
}
|
|
163
|
+
await apiProtect(this, title, who === 'administrators' ? 'sysop' : 'autoconfirmed');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Upload a test file through the API, whatever the wiki warns (a duplicate, a
|
|
168
|
+
* name in use): the file is deleted after the scenario. The local file is a path
|
|
169
|
+
* from the project, or from this pack (tests/fixtures/ ships with it).
|
|
170
|
+
*
|
|
171
|
+
* Example #1: Given the file "Test square.png" is uploaded from "tests/fixtures/blue-square.png"
|
|
172
|
+
* Example #2: Given the file "Second square.png" is uploaded from "tests/fixtures/blue-square.png"
|
|
173
|
+
* Example #3: And the file "Test square.png" is uploaded from "tests/fixtures/blue-square.png"
|
|
174
|
+
* Example #4: Given the file "Duplicate source.png" is uploaded from "tests/fixtures/blue-square.png"
|
|
175
|
+
* Example #5: Given the file "Reading test image.png" is uploaded from "tests/fixtures/blue-square.png"
|
|
176
|
+
*/
|
|
177
|
+
Given(/^the file "([^"]*)" is uploaded from "([^"]*)"$/, { timeout: 90000 }, async function (name, file) {
|
|
178
|
+
const local = fixturePath(file);
|
|
179
|
+
cleanUpAfter(this, `File:${name}`);
|
|
180
|
+
await apiUpload(this, name, local);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Make sure an account has no block (it is lifted through the API when it has
|
|
185
|
+
* one), for the scenarios that block it.
|
|
186
|
+
*
|
|
187
|
+
* Example #1: Given the account "reader" is not blocked
|
|
188
|
+
* Example #2: And the account "reader" is not blocked
|
|
189
|
+
* Example #3: Given the account "editor" is not blocked
|
|
190
|
+
* Example #4: Given the account "Reader" is not blocked
|
|
191
|
+
* Example #5: And the account "editor" is not blocked
|
|
192
|
+
*/
|
|
193
|
+
Given(/^the account "([^"]*)" is not blocked$/, { timeout: 60000 }, async function (who) {
|
|
194
|
+
const users = (this.parameters && this.parameters.users) || {};
|
|
195
|
+
const name = users[who] ? resolveUser(this, who).wikiName : who;
|
|
196
|
+
await apiUnblock(this, name, 'Test account given back by a scenario');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Open a page of the wiki by its title (index.php?title=…, with the skin of
|
|
201
|
+
* `worldParameters.skin`), and wait for the scripts the page asked for.
|
|
202
|
+
*
|
|
203
|
+
* Example #1: When I open the page "Reading test page"
|
|
204
|
+
* Example #2: Given I am on the page "Main Page"
|
|
205
|
+
* Example #3: When we open the page "Category:Test guides"
|
|
206
|
+
* Example #4: Given we are on the page "Special:RecentChanges"
|
|
207
|
+
* Example #5: And I open the page "Talk:Reading test page"
|
|
208
|
+
*/
|
|
209
|
+
When(/^(?:I open|we open|I am on|we are on) the page "([^"]*)"$/, { timeout: 90000 }, async function (title) {
|
|
210
|
+
await openPage(this, title);
|
|
211
|
+
if (cutRequest(this)) throw friendly({ message: `The page "${title}" did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
212
|
+
await pageModulesReady(this).catch(() => []);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Assert that the browser shows a page by its title (the page's own name,
|
|
217
|
+
* `wgPageName`, and the title it shows).
|
|
218
|
+
*
|
|
219
|
+
* Example #1: Then I should see the page "Reading test page"
|
|
220
|
+
* Example #2: Then we should see the page "Talk:Reading test page"
|
|
221
|
+
* Example #3: And I should see the page "Category:Test guides"
|
|
222
|
+
* Example #4: Then I should see the page "File:Test square.png"
|
|
223
|
+
* Example #5: Then I should see the page "Main Page"
|
|
224
|
+
*/
|
|
225
|
+
Then(/^(I |we )*should see the page "([^"]*)"$/, async function (pronounCase, title) {
|
|
226
|
+
await eventually(this, async () => ({ name: await config(this, 'wgPageName'), shown: await shownTitle(this) }),
|
|
227
|
+
(v) => v.name === titleKey(title) || v.shown === titleText(title),
|
|
228
|
+
(v) => ({ message: `Expected the page "${titleText(title)}"; ${v.name ? `the browser shows "${titleText(v.name)}" (${v.shown})` : `the browser shows no page of the wiki (${this.page.url()})`}.`, hint: cutRequest(this) ? CUT_HINT : 'Titles are matched as the wiki writes them: the first letter upper case, spaces and underscores alike.' }));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Assert the text of the page's body (the rendered content, without the skin
|
|
233
|
+
* around it), or that a text is not there.
|
|
234
|
+
*
|
|
235
|
+
* Example #1: Then the page text should contain "First version of the page."
|
|
236
|
+
* Example #2: Then the page text should not contain "Second version"
|
|
237
|
+
* Example #3: And the page text should contain "Typed in the visual editor"
|
|
238
|
+
* Example #4: Then the page text should contain "A wiki is a website"
|
|
239
|
+
* Example #5: And the page text should not contain "Words to change."
|
|
240
|
+
*/
|
|
241
|
+
Then(/^the page text should( not)* contain "([^"]*)"$/, async function (notCase, expected) {
|
|
242
|
+
const read = async () => clean(await this.page.locator('#mw-content-text .mw-parser-output, #mw-content-text').first().innerText({ timeout: 2000 }).catch(() => ''));
|
|
243
|
+
await eventually(this, read, (text) => !!notCase !== text.includes(clean(expected)),
|
|
244
|
+
(text) => ({ message: notCase ? `The page text contains "${expected}".` : `The page text does not contain "${expected}". It reads: "${text.slice(0, 300)}".`, hint: 'The page text is the content of the page (#mw-content-text), not the menus of the skin.' }));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/** The sections of the page: every heading of the content, with its anchor, in order. */
|
|
248
|
+
async function sections(world) {
|
|
249
|
+
return world.page.evaluate(() => {
|
|
250
|
+
const root = document.querySelector('#mw-content-text .mw-parser-output') || document.querySelector('#mw-content-text');
|
|
251
|
+
if (!root) return [];
|
|
252
|
+
const out = [];
|
|
253
|
+
for (const h of root.querySelectorAll('h2, h3, h4, h5, h6')) {
|
|
254
|
+
if (h.closest('#toc, .toc') || h.id === 'mw-toc-heading') continue;
|
|
255
|
+
const headline = h.querySelector('.mw-headline');
|
|
256
|
+
const clone = h.cloneNode(true);
|
|
257
|
+
clone.querySelectorAll('.mw-editsection').forEach((e) => e.remove());
|
|
258
|
+
const text = (headline ? headline.textContent : clone.textContent).replace(/\s+/g, ' ').trim();
|
|
259
|
+
if (text) out.push({ id: h.id || (headline && headline.id) || '', text, level: Number(h.tagName[1]) });
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
}).catch(() => []);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Assert that the page has, or has not, a section by its heading.
|
|
267
|
+
*
|
|
268
|
+
* Example #1: Then the page should have the section "Overview"
|
|
269
|
+
* Example #2: Then the page should not have the section "History"
|
|
270
|
+
* Example #3: And the page should have the section "Source editing"
|
|
271
|
+
* Example #4: Then the page should have the section "A question about this page"
|
|
272
|
+
* Example #5: And the page should not have the section "Removed section"
|
|
273
|
+
*/
|
|
274
|
+
Then(/^the page should( not)* have the section "([^"]*)"$/, async function (notCase, name) {
|
|
275
|
+
await pageModulesReady(this).catch(() => []);
|
|
276
|
+
const found = await sections(this);
|
|
277
|
+
const has = found.some((s) => s.text === clean(name));
|
|
278
|
+
if (!!notCase === has) {
|
|
279
|
+
throw friendly({ message: notCase ? `The page has the section "${name}".` : `The page has no section "${name}". Its sections: ${listed(found.map((s) => s.text))}.`, hint: 'A section is a heading of the content (== Heading == in wikitext), matched as written.' });
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Assert the sections of the page, in order, with their levels (2 for
|
|
285
|
+
* == Heading ==, 3 for === Heading ===).
|
|
286
|
+
*
|
|
287
|
+
* Example #1: Then the page should have these sections in order:
|
|
288
|
+
* Example #2: And the page should have these sections in order:
|
|
289
|
+
* Example #3: Then the page should have these sections in order:
|
|
290
|
+
* Example #4: Then the page should have these sections in order:
|
|
291
|
+
* Example #5: And the page should have these sections in order:
|
|
292
|
+
*/
|
|
293
|
+
Then(/^the page should have these sections in order:$/, async function (table) {
|
|
294
|
+
const expected = table.hashes().map((row) => ({ text: clean(row.section), level: Number(row.level || 0) }));
|
|
295
|
+
const found = await sections(this);
|
|
296
|
+
const got = found.map((s) => `${s.text} (${s.level})`);
|
|
297
|
+
const want = expected.map((s) => `${s.text} (${s.level || '?'})`);
|
|
298
|
+
const ok = expected.length === found.length && expected.every((s, i) => s.text === found[i].text && (!s.level || s.level === found[i].level));
|
|
299
|
+
if (!ok) {
|
|
300
|
+
throw friendly({ message: `The sections of the page are ${listed(got)}, not ${listed(want)}.`, hint: 'The table has the columns "section" and "level" (2 for == Heading ==, 3 for === Heading ===).' });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
/** The entries of the contents list (the sidebar list of the default skin, or the list in the page). */
|
|
305
|
+
async function contentsEntries(world) {
|
|
306
|
+
return world.page.evaluate(() => {
|
|
307
|
+
const links = [...document.querySelectorAll('#vector-toc a.vector-toc-link, #toc a, .toc a, #mw-panel-toc a')];
|
|
308
|
+
return links.filter((a) => a.getAttribute('href') && a.getAttribute('href') !== '#').map((a) => {
|
|
309
|
+
const label = a.querySelector('.toctext, .vector-toc-text > span:not(.vector-toc-numb)') || a;
|
|
310
|
+
return { href: a.getAttribute('href'), text: label.textContent.replace(/\s+/g, ' ').trim() };
|
|
311
|
+
});
|
|
312
|
+
}).catch(() => []);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Assert that the contents list of the page lists, or does not list, a section.
|
|
317
|
+
*
|
|
318
|
+
* Example #1: Then the contents list should list "Overview"
|
|
319
|
+
* Example #2: Then the contents list should not list "History"
|
|
320
|
+
* Example #3: And the contents list should list "Source editing"
|
|
321
|
+
* Example #4: Then the contents list should list "References"
|
|
322
|
+
* Example #5: And the contents list should not list "Removed section"
|
|
323
|
+
*/
|
|
324
|
+
Then(/^the contents list should( not)* list "([^"]*)"$/, async function (notCase, name) {
|
|
325
|
+
await pageModulesReady(this).catch(() => []);
|
|
326
|
+
const entries = await contentsEntries(this);
|
|
327
|
+
const has = entries.some((e) => e.text === clean(name));
|
|
328
|
+
if (!!notCase === has) {
|
|
329
|
+
throw friendly({ message: notCase ? `The contents list lists "${name}".` : `The contents list does not list "${name}". It lists: ${listed(entries.map((e) => e.text))}.`, hint: 'The wiki shows a contents list on a page with four sections or more (or __TOC__ in the wikitext).' });
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Follow an entry of the contents list, as a person does: the page goes to the
|
|
335
|
+
* section.
|
|
336
|
+
*
|
|
337
|
+
* Example #1: When I follow "Overview" in the contents list
|
|
338
|
+
* Example #2: When we follow "Source editing" in the contents list
|
|
339
|
+
* Example #3: And I follow "Links" in the contents list
|
|
340
|
+
* Example #4: When I follow "References" in the contents list
|
|
341
|
+
* Example #5: When I follow "Visual editing" in the contents list
|
|
342
|
+
*/
|
|
343
|
+
When(/^(I |we )*follow "([^"]*)" in the contents list$/, async function (pronounCase, name) {
|
|
344
|
+
await pageModulesReady(this).catch(() => []);
|
|
345
|
+
const entries = await contentsEntries(this);
|
|
346
|
+
const entry = entries.find((e) => e.text === clean(name));
|
|
347
|
+
if (!entry) throw friendly({ message: `The contents list has no entry "${name}". It lists: ${listed(entries.map((e) => e.text))}.`, hint: 'Name the entry as the list writes it, without its number.' });
|
|
348
|
+
const link = this.page.locator(`#vector-toc a.vector-toc-link[href="${entry.href}"], #toc a[href="${entry.href}"], .toc a[href="${entry.href}"]`).filter({ visible: true }).first();
|
|
349
|
+
await link.click();
|
|
350
|
+
await settle(this, 1500);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Assert that the page is at a section: the address ends with its anchor and its
|
|
355
|
+
* heading is in view.
|
|
356
|
+
*
|
|
357
|
+
* Example #1: Then I should be at the section "Overview"
|
|
358
|
+
* Example #2: Then we should be at the section "Source editing"
|
|
359
|
+
* Example #3: And I should be at the section "Links"
|
|
360
|
+
* Example #4: Then I should be at the section "A question about this page"
|
|
361
|
+
* Example #5: Then I should be at the section "References"
|
|
362
|
+
*/
|
|
363
|
+
Then(/^(I |we )*should be at the section "([^"]*)"$/, async function (pronounCase, name) {
|
|
364
|
+
const found = await sections(this);
|
|
365
|
+
const section = found.find((s) => s.text === clean(name));
|
|
366
|
+
if (!section) throw friendly({ message: `The page has no section "${name}". Its sections: ${listed(found.map((s) => s.text))}.`, hint: 'Name the section by its heading.' });
|
|
367
|
+
await eventually(this, () => this.page.evaluate((id) => {
|
|
368
|
+
const el = document.getElementById(id);
|
|
369
|
+
const rect = el ? el.getBoundingClientRect() : null;
|
|
370
|
+
return { hash: decodeURIComponent(location.hash.slice(1)), inView: !!rect && rect.top >= -2 && rect.top < window.innerHeight };
|
|
371
|
+
}, section.id), (v) => v.hash === section.id && v.inView,
|
|
372
|
+
(v) => ({ message: `The page is not at the section "${name}": the address ends with "#${v.hash}" (expected "#${section.id}") and the heading is ${v.inView ? '' : 'not '}in view.`, hint: 'Follow the section from the contents list or a link to it first.' }));
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
/** The links of the page's content, with the page each one leads to (its title), and their kind. */
|
|
376
|
+
async function contentLinks(world) {
|
|
377
|
+
return world.page.evaluate(() => {
|
|
378
|
+
const root = document.querySelector('#mw-content-text .mw-parser-output') || document.querySelector('#mw-content-text');
|
|
379
|
+
const articlePath = (window.mw && mw.config.get('wgArticlePath') || '/index.php?title=$1').split('$1')[0];
|
|
380
|
+
return [...(root ? root.querySelectorAll('a[href]') : [])].filter((a) => !a.closest('.mw-editsection, #toc, .toc')).map((a) => {
|
|
381
|
+
let title = null;
|
|
382
|
+
try {
|
|
383
|
+
const u = new URL(a.href, location.href);
|
|
384
|
+
title = u.searchParams.get('title');
|
|
385
|
+
if (!title && articlePath.indexOf('?') === -1 && u.pathname.startsWith(articlePath)) title = decodeURIComponent(u.pathname.slice(articlePath.length));
|
|
386
|
+
} catch (e) { /* not an address */ }
|
|
387
|
+
return { text: a.textContent.replace(/\s+/g, ' ').trim(), href: a.getAttribute('href'), title: title ? title.replace(/_/g, ' ') : null, missing: a.classList.contains('new'), external: a.classList.contains('external') };
|
|
388
|
+
});
|
|
389
|
+
}).catch(() => []);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Assert that the page links to another page of the wiki that exists (a blue
|
|
394
|
+
* link), or to a page that does not exist yet (a red link), by the title the
|
|
395
|
+
* link leads to. A red link to a page that exists says so: the page on screen
|
|
396
|
+
* was drawn before that page was made.
|
|
397
|
+
*
|
|
398
|
+
* Example #1: Then the page should link to the page "Editing help"
|
|
399
|
+
* Example #2: Then the page should link to the missing page "Page not written yet"
|
|
400
|
+
* Example #3: And the page should link to the page "Second test page"
|
|
401
|
+
* Example #4: Then the page should not link to the page "Unrelated page"
|
|
402
|
+
* Example #5: Then the page should not link to the missing page "Second test page"
|
|
403
|
+
*/
|
|
404
|
+
Then(/^the page should( not)* link to the (page|missing page) "([^"]*)"$/, async function (notCase, kind, title) {
|
|
405
|
+
const links = await contentLinks(this);
|
|
406
|
+
const want = titleText(title);
|
|
407
|
+
const has = links.some((l) => l.title && titleText(l.title) === want && !l.external && l.missing === (kind === 'missing page'));
|
|
408
|
+
if (!notCase && !has && kind === 'page' && links.some((l) => l.title && titleText(l.title) === want && l.missing)) {
|
|
409
|
+
// A red link to a page that exists: the page on screen was drawn before that page was made.
|
|
410
|
+
const info = await pageInfo(this, want).catch(() => null);
|
|
411
|
+
if (info && info.exists) {
|
|
412
|
+
throw friendly({
|
|
413
|
+
message: `The link to "${want}" is red, although the page exists: the wiki drew this page before "${want}" was made, and draws it again only when a job of the wiki runs (or the page is opened again later).`,
|
|
414
|
+
hint: `Make "${want}" first, then the page that links to it ("Given the page "${want}" has the text …" before the page with the link).`,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (!!notCase === has) {
|
|
419
|
+
const internal = links.filter((l) => l.title && !l.external).map((l) => `${l.title}${l.missing ? ' (missing)' : ''}`);
|
|
420
|
+
throw friendly({ message: notCase ? `The page links to the ${kind} "${want}".` : `The page has no link to the ${kind} "${want}". Its links to pages: ${listed(internal)}.`, hint: 'A link to a page that does not exist yet is a red link (class "new"); the title is the page the link leads to, not its text.' });
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Assert that the page links to an address outside the wiki (an external link).
|
|
426
|
+
*
|
|
427
|
+
* Example #1: Then the page should link to the external site "https://example.org"
|
|
428
|
+
* Example #2: Then the page should not link to the external site "https://example.com"
|
|
429
|
+
* Example #3: And the page should link to the external site "https://example.org/"
|
|
430
|
+
* Example #4: Then the page should link to the external site "https://example.org/docs"
|
|
431
|
+
* Example #5: And the page should not link to the external site "https://example.net"
|
|
432
|
+
*/
|
|
433
|
+
Then(/^the page should( not)* link to the external site "([^"]*)"$/, async function (notCase, url) {
|
|
434
|
+
const links = await contentLinks(this);
|
|
435
|
+
const norm = (u) => String(u || '').replace(/\/+$/, '');
|
|
436
|
+
const has = links.some((l) => l.external && norm(l.href) === norm(url));
|
|
437
|
+
if (!!notCase === has) {
|
|
438
|
+
throw friendly({ message: notCase ? `The page links to "${url}".` : `The page has no external link to "${url}". Its external links: ${listed(links.filter((l) => l.external).map((l) => l.href))}.`, hint: 'An external link is written [https://example.org text] in wikitext.' });
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Follow a link of the page's content to another page of the wiki, by the title
|
|
444
|
+
* it leads to.
|
|
445
|
+
*
|
|
446
|
+
* Example #1: When I follow the link to the page "Editing help"
|
|
447
|
+
* Example #2: When we follow the link to the page "Second test page"
|
|
448
|
+
* Example #3: And I follow the link to the page "Reading test page"
|
|
449
|
+
* Example #4: When I follow the link to the page "Page not written yet"
|
|
450
|
+
* Example #5: When I follow the link to the page "Main Page"
|
|
451
|
+
*/
|
|
452
|
+
When(/^(I |we )*follow the link to the page "([^"]*)"$/, { timeout: 60000 }, async function (pronounCase, title) {
|
|
453
|
+
const links = await contentLinks(this);
|
|
454
|
+
const link = links.find((l) => l.title && titleText(l.title) === titleText(title) && !l.external);
|
|
455
|
+
if (!link) throw friendly({ message: `The page has no link to "${titleText(title)}". Its links: ${listed(links.filter((l) => l.title).map((l) => l.title))}.`, hint: 'Name the page the link leads to.' });
|
|
456
|
+
await afterNavigation(this, () => this.page.locator(`#mw-content-text a[href="${link.href}"]`).filter({ visible: true }).first().click());
|
|
457
|
+
if (cutRequest(this)) throw friendly({ message: `The link to "${title}" did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Assert that a reference of the page (a footnote: <ref>…</ref>) leads to a text
|
|
462
|
+
* in the list of references, by its number as the page shows it.
|
|
463
|
+
*
|
|
464
|
+
* Example #1: Then the reference "1" should read "Every page keeps its history."
|
|
465
|
+
* Example #2: And the reference "2" should read "A second source."
|
|
466
|
+
* Example #3: Then the reference "1" should read "Every page keeps"
|
|
467
|
+
* Example #4: Then the reference "3" should read "The third note."
|
|
468
|
+
* Example #5: And the reference "1" should read "its history"
|
|
469
|
+
*/
|
|
470
|
+
Then(/^the reference "(\d+)" should read "([^"]*)"$/, async function (number, expected) {
|
|
471
|
+
const note = await this.page.evaluate((n) => {
|
|
472
|
+
const sup = [...document.querySelectorAll('#mw-content-text sup.reference a')].find((a) => a.textContent.replace(/[[\]\s]/g, '') === n);
|
|
473
|
+
if (!sup) return { found: false, numbers: [...document.querySelectorAll('#mw-content-text sup.reference a')].map((a) => a.textContent.trim()) };
|
|
474
|
+
const id = decodeURIComponent((sup.getAttribute('href') || '').replace(/^#/, ''));
|
|
475
|
+
const li = document.getElementById(id);
|
|
476
|
+
const text = li ? (li.querySelector('.reference-text') || li).textContent.replace(/\s+/g, ' ').trim() : '';
|
|
477
|
+
return { found: true, id, text };
|
|
478
|
+
}, String(number));
|
|
479
|
+
if (!note.found || !note.text.includes(clean(expected))) {
|
|
480
|
+
throw friendly({
|
|
481
|
+
message: note.found ? `The reference [${number}] reads "${note.text}", not "${expected}".` : `The page has no reference [${number}]. Its references: ${listed(note.numbers)}.`,
|
|
482
|
+
hint: 'References are made with <ref>…</ref> and listed by <references /> (the Cite extension).',
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
/** The categories the page is in, as its categories box lists them. */
|
|
488
|
+
async function pageCategories(world) {
|
|
489
|
+
return world.page.evaluate(() => [...document.querySelectorAll('#mw-normal-catlinks ul li a')].map((a) => a.textContent.trim())).catch(() => []);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Assert that the page is, or is not, in a category, as its categories box at
|
|
494
|
+
* the foot of the page lists it.
|
|
495
|
+
*
|
|
496
|
+
* Example #1: Then the page should be in the category "Test guides"
|
|
497
|
+
* Example #2: Then the page should not be in the category "Drafts"
|
|
498
|
+
* Example #3: And the page should be in the category "Test pages"
|
|
499
|
+
* Example #4: Then the page should be in the category "Editing guides"
|
|
500
|
+
* Example #5: And the page should not be in the category "Test guides"
|
|
501
|
+
*/
|
|
502
|
+
Then(/^the page should( not)* be in the category "([^"]*)"$/, async function (notCase, name) {
|
|
503
|
+
const cats = await pageCategories(this);
|
|
504
|
+
if (!!notCase === cats.includes(titleText(name))) {
|
|
505
|
+
throw friendly({ message: notCase ? `The page is in the category "${name}".` : `The page is not in the category "${name}". Its categories: ${listed(cats)}.`, hint: 'A page is put in a category with [[Category:Name]] in its wikitext.' });
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Follow a category of the page's categories box to the category's page.
|
|
511
|
+
*
|
|
512
|
+
* Example #1: When I follow the category "Test guides"
|
|
513
|
+
* Example #2: When we follow the category "Test pages"
|
|
514
|
+
* Example #3: And I follow the category "Editing guides"
|
|
515
|
+
* Example #4: When I follow the category "Test guides"
|
|
516
|
+
* Example #5: When we follow the category "Editing guides"
|
|
517
|
+
*/
|
|
518
|
+
When(/^(I |we )*follow the category "([^"]*)"$/, { timeout: 60000 }, async function (pronounCase, name) {
|
|
519
|
+
const link = this.page.locator('#mw-normal-catlinks ul li a').filter({ hasText: new RegExp(`^\\s*${titleText(name).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`) });
|
|
520
|
+
if (!(await link.count())) throw friendly({ message: `The categories box has no category "${name}". It lists: ${listed(await pageCategories(this))}.`, hint: 'Open a page of the category first.' });
|
|
521
|
+
await afterNavigation(this, () => link.first().click());
|
|
522
|
+
await pageModulesReady(this).catch(() => []);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Assert that a category page lists, or does not list, a page or a subcategory.
|
|
527
|
+
*
|
|
528
|
+
* Example #1: Then the category should list the page "Reading test page"
|
|
529
|
+
* Example #2: Then the category should list the subcategory "Editing guides"
|
|
530
|
+
* Example #3: And the category should not list the page "Second test page"
|
|
531
|
+
* Example #4: Then the category should not list the subcategory "Drafts"
|
|
532
|
+
* Example #5: And the category should list the page "Second test page"
|
|
533
|
+
*/
|
|
534
|
+
Then(/^the category should( not)* list the (page|subcategory) "([^"]*)"$/, async function (notCase, kind, name) {
|
|
535
|
+
const selector = kind === 'page' ? '#mw-pages a' : '#mw-subcategories a';
|
|
536
|
+
const read = () => this.page.evaluate((s) => [...document.querySelectorAll(s)].map((a) => a.textContent.trim()).filter(Boolean), selector).catch(() => []);
|
|
537
|
+
const want = kind === 'page' ? titleText(name) : titleText(name).replace(/^Category:/, '');
|
|
538
|
+
await eventually(this, read, (names) => !!notCase !== names.includes(want),
|
|
539
|
+
(names) => ({ message: notCase ? `The category lists the ${kind} "${want}".` : `The category does not list the ${kind} "${want}". It lists: ${listed(names)}.`, hint: 'Open the category\'s page first ("When I open the page "Category:…"").' }));
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
/** The item of the category tree for a category, by its name. */
|
|
543
|
+
function treeItem(world, name) {
|
|
544
|
+
const want = titleText(name).replace(/^Category:/, '');
|
|
545
|
+
return world.page.locator('.CategoryTreeItem').filter({ has: world.page.locator('a:not(.CategoryTreeToggle)', { hasText: new RegExp(`^\\s*${want.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`) }) }).first();
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Expand or collapse a category in the category tree of a category page, as a
|
|
550
|
+
* person does with its toggle. Expanding waits for the tree's own request
|
|
551
|
+
* (api.php action=categorytree) and for the list it brings.
|
|
552
|
+
*
|
|
553
|
+
* Example #1: When I expand the category "Test guides" in the category tree
|
|
554
|
+
* Example #2: When I collapse the category "Test guides" in the category tree
|
|
555
|
+
* Example #3: And we expand the category "Editing guides" in the category tree
|
|
556
|
+
* Example #4: When we collapse the category "Editing guides" in the category tree
|
|
557
|
+
* Example #5: When I expand the category "Test pages" in the category tree
|
|
558
|
+
*/
|
|
559
|
+
When(/^(I |we )*(expand|collapse) the category "([^"]*)" in the category tree$/, { timeout: 60000 }, async function (pronounCase, action, name) {
|
|
560
|
+
await pageModulesReady(this).catch(() => []);
|
|
561
|
+
const item = treeItem(this, name);
|
|
562
|
+
if (!(await item.count())) {
|
|
563
|
+
const names = await this.page.locator('.CategoryTreeItem > bdi a, .CategoryTreeItem a:not(.CategoryTreeToggle)').allInnerTexts().catch(() => []);
|
|
564
|
+
throw friendly({ message: `The category tree has no category "${name}". It shows: ${listed(names)}.`, hint: 'The category tree is on the page of a category with subcategories (the CategoryTree extension).' });
|
|
565
|
+
}
|
|
566
|
+
let toggle = item.locator('.CategoryTreeToggle');
|
|
567
|
+
if (!(await toggle.count())) {
|
|
568
|
+
// The page may have been drawn before the wiki's job wrote the category's counts: wait for them, then
|
|
569
|
+
// draw it again.
|
|
570
|
+
const behind = await waitForCategoryCounts(this, [name]);
|
|
571
|
+
if (!behind.length) {
|
|
572
|
+
await openPage(this, await config(this, 'wgPageName'));
|
|
573
|
+
await pageModulesReady(this).catch(() => []);
|
|
574
|
+
toggle = treeItem(this, name).locator('.CategoryTreeToggle');
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (!(await toggle.count())) throw friendly({ message: `The category "${name}" has no toggle in the tree: the wiki counts no subcategory in it.`, hint: 'A category without subcategories shows a plain bullet. The counts are written by the wiki\'s job queue: the test-data steps wait for it.' });
|
|
578
|
+
const open = (await toggle.getAttribute('aria-expanded')) === 'true';
|
|
579
|
+
if ((action === 'expand') === open) return;
|
|
580
|
+
const answered = action === 'expand' ? this.page.waitForResponse((r) => /action=categorytree/.test(r.url()), { timeout: budget(this) }).catch(() => null) : null;
|
|
581
|
+
await toggle.click();
|
|
582
|
+
if (answered) await answered;
|
|
583
|
+
const want = action === 'expand' ? 'true' : 'false';
|
|
584
|
+
await eventually(this, async () => ({
|
|
585
|
+
expanded: await toggle.getAttribute('aria-expanded').catch(() => null),
|
|
586
|
+
loading: await item.locator('xpath=..').locator(':scope > .CategoryTreeChildren').innerText().then((t) => /loading/i.test(t)).catch(() => false),
|
|
587
|
+
}), (v) => v.expanded === want && !v.loading,
|
|
588
|
+
(v) => ({ message: `The category "${name}" did not ${action} in the tree (aria-expanded ${v.expanded}${v.loading ? ', still loading' : ''}).`, hint: 'The tree asks the wiki for the subcategories (api.php action=categorytree); see the browser console.' }));
|
|
589
|
+
await settle(this, 1500);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Assert that the category tree shows, or does not show, a category under
|
|
594
|
+
* another one (after expanding it).
|
|
595
|
+
*
|
|
596
|
+
* Example #1: Then the category tree should show "Editing guides" under "Test guides"
|
|
597
|
+
* Example #2: Then the category tree should not show "Editing guides" under "Test guides"
|
|
598
|
+
* Example #3: And the category tree should show "Test guides" under "Test pages"
|
|
599
|
+
* Example #4: Then the category tree should not show "Drafts" under "Test guides"
|
|
600
|
+
* Example #5: And the category tree should show "Editing guides" under "Test guides"
|
|
601
|
+
*/
|
|
602
|
+
Then(/^the category tree should( not)* show "([^"]*)" under "([^"]*)"$/, async function (notCase, child, parent) {
|
|
603
|
+
const want = titleText(child).replace(/^Category:/, '');
|
|
604
|
+
const parentName = titleText(parent).replace(/^Category:/, '');
|
|
605
|
+
const read = () => this.page.evaluate(({ p }) => {
|
|
606
|
+
const items = [...document.querySelectorAll('.CategoryTreeItem')].filter((i) => [...i.querySelectorAll('a:not(.CategoryTreeToggle)')].some((a) => a.textContent.trim() === p));
|
|
607
|
+
const names = [];
|
|
608
|
+
for (const item of items) {
|
|
609
|
+
const children = item.parentElement && item.parentElement.querySelector(':scope > .CategoryTreeChildren');
|
|
610
|
+
if (!children || getComputedStyle(children).display === 'none') continue;
|
|
611
|
+
for (const a of children.querySelectorAll('.CategoryTreeItem a:not(.CategoryTreeToggle)')) names.push(a.textContent.trim());
|
|
612
|
+
}
|
|
613
|
+
return names;
|
|
614
|
+
}, { p: parentName }).catch(() => []);
|
|
615
|
+
await eventually(this, read, (names) => !!notCase !== names.includes(want),
|
|
616
|
+
(names) => ({ message: notCase ? `The category tree shows "${want}" under "${parentName}".` : `The category tree does not show "${want}" under "${parentName}". Under it: ${listed(names)}.`, hint: 'Expand the category first ("When I expand the category ... in the category tree").' }));
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Open the talk page of the page on screen, as a person does with its
|
|
621
|
+
* "Discussion" tab. A talk page that does not exist yet opens in the editor.
|
|
622
|
+
*
|
|
623
|
+
* Example #1: When I open the talk page
|
|
624
|
+
* Example #2: When we open the talk page
|
|
625
|
+
* Example #3: And I open the talk page
|
|
626
|
+
* Example #4: Then I open the talk page
|
|
627
|
+
* Example #5: Given I open the talk page
|
|
628
|
+
*/
|
|
629
|
+
When(/^(I |we )*open the talk page$/, { timeout: 60000 }, async function (pronounCase) {
|
|
630
|
+
const tab = this.page.locator('#ca-talk a, a#ca-talk').filter({ visible: true }).first();
|
|
631
|
+
if (!(await tab.count())) throw friendly({ message: `The page has no "Discussion" tab: ${await pageSummary(this)}.`, hint: 'Open a page of the wiki first; a talk page has no talk page of its own.' });
|
|
632
|
+
await afterNavigation(this, () => tab.click());
|
|
633
|
+
await closeWelcomeDialog(this);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Add a topic to the talk page of a page (a new section with a subject and its
|
|
638
|
+
* text), as a person does with "Add topic", and save it. On a talk page that does
|
|
639
|
+
* not exist yet, the wiki's new-section form makes it.
|
|
640
|
+
*
|
|
641
|
+
* Example #1: When I add the topic "A question about this page" with the text "Is this page complete?"
|
|
642
|
+
* Example #2: When we add the topic "Sources" with the text "Which sources are missing?"
|
|
643
|
+
* Example #3: And I add the topic "Layout" with the text "The table is too wide."
|
|
644
|
+
* Example #4: When I add the topic "Thanks" with the text "Thank you for the page."
|
|
645
|
+
* Example #5: When we add the topic "A second question" with the text "Who wrote the overview?"
|
|
646
|
+
*/
|
|
647
|
+
When(/^(I |we )*add the topic "([^"]*)" with the text "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, subject, text) {
|
|
648
|
+
const page = this.page;
|
|
649
|
+
const add = page.locator('#ca-addsection a, a#ca-addsection').filter({ visible: true }).first();
|
|
650
|
+
if (await add.count()) {
|
|
651
|
+
await afterNavigation(this, () => add.click());
|
|
652
|
+
} else {
|
|
653
|
+
const name = await config(this, 'wgPageName');
|
|
654
|
+
const ns = await config(this, 'wgNamespaceNumber');
|
|
655
|
+
if (!name) throw friendly({ message: `No page of the wiki is open: ${await pageSummary(this)}.`, hint: 'Open the page or its talk page first.' });
|
|
656
|
+
const talk = ns % 2 === 1 ? name : (talkTitle(name) || name);
|
|
657
|
+
await openPage(this, talk, { action: 'edit', section: 'new' });
|
|
658
|
+
}
|
|
659
|
+
await closeWelcomeDialog(this);
|
|
660
|
+
const form = page.locator('#editform');
|
|
661
|
+
try {
|
|
662
|
+
await form.waitFor({ state: 'visible', timeout: budget(this) });
|
|
663
|
+
} catch (err) {
|
|
664
|
+
throw friendly({ message: `The new topic form did not open: ${await pageSummary(this)}.`, cause: err, hint: cutRequest(this) ? CUT_HINT : 'The account must be allowed to edit the talk page.' });
|
|
665
|
+
}
|
|
666
|
+
await page.locator('#wpSummary').fill(subject);
|
|
667
|
+
await page.locator('#wpTextbox1').fill(text);
|
|
668
|
+
await afterNavigation(this, () => page.locator('#wpSave').click());
|
|
669
|
+
const saved = await config(this, 'wgPostEdit');
|
|
670
|
+
if (!saved) {
|
|
671
|
+
throw friendly({ message: `The topic "${subject}" was not saved: ${await pageSummary(this)}. Errors: ${listed(await messages(this, 'error'))}.`, hint: cutRequest(this) ? CUT_HINT : 'The wiki answers a saved edit with the page and a notice ("Your edit was saved.").' });
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Assert that the talk page on screen has, or has not, a topic (a section).
|
|
677
|
+
*
|
|
678
|
+
* Example #1: Then the talk page should have the topic "A question about this page"
|
|
679
|
+
* Example #2: Then the talk page should not have the topic "Sources"
|
|
680
|
+
* Example #3: And the talk page should have the topic "Layout"
|
|
681
|
+
* Example #4: Then the talk page should have the topic "Thanks"
|
|
682
|
+
* Example #5: And the talk page should not have the topic "A second question"
|
|
683
|
+
*/
|
|
684
|
+
Then(/^the talk page should( not)* have the topic "([^"]*)"$/, async function (notCase, subject) {
|
|
685
|
+
const ns = await config(this, 'wgNamespaceNumber');
|
|
686
|
+
if (ns === null || ns % 2 !== 1) throw friendly({ message: `The browser does not show a talk page: ${await pageSummary(this)}.`, hint: 'Open the talk page first ("When I open the talk page").' });
|
|
687
|
+
const found = await sections(this);
|
|
688
|
+
if (!!notCase === found.some((s) => s.text === clean(subject))) {
|
|
689
|
+
throw friendly({ message: notCase ? `The talk page has the topic "${subject}".` : `The talk page has no topic "${subject}". Its topics: ${listed(found.map((s) => s.text))}.`, hint: 'A topic is a section of the talk page; "Add topic" makes one.' });
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Assert that every script the page asked for loaded (the wiki's module loader
|
|
695
|
+
* resolved them all): a module whose script failed is named.
|
|
696
|
+
*
|
|
697
|
+
* Example #1: Then the scripts of the page should all load
|
|
698
|
+
* Example #2: And the scripts of the page should all load
|
|
699
|
+
* Example #3: Then the scripts of the page should all load
|
|
700
|
+
* Example #4: Then the scripts of the page should all load
|
|
701
|
+
* Example #5: And the scripts of the page should all load
|
|
702
|
+
*/
|
|
703
|
+
Then(/^the scripts of the page should all load$/, async function () {
|
|
704
|
+
const failed = await pageModulesReady(this);
|
|
705
|
+
if (failed.length) {
|
|
706
|
+
throw friendly({ message: `Some scripts of the page did not load: ${failed.join(', ')}.`, hint: 'See the browser console for the error of each module; "error" means its script threw.' });
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
module.exports = { talkTitle, cleanUpAfter, sections, contentsEntries, contentLinks, pageCategories };
|