@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,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The history of a page: its revisions (each known by its edit summary, as a
|
|
4
|
+
// person picks it in the list), comparing two of them, and undoing one.
|
|
5
|
+
|
|
6
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
7
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
8
|
+
const {
|
|
9
|
+
listed,
|
|
10
|
+
titleText,
|
|
11
|
+
config,
|
|
12
|
+
cutRequest,
|
|
13
|
+
CUT_HINT,
|
|
14
|
+
openPage,
|
|
15
|
+
afterNavigation,
|
|
16
|
+
pageSummary,
|
|
17
|
+
messages,
|
|
18
|
+
closeWelcomeDialog,
|
|
19
|
+
accountName,
|
|
20
|
+
} = require('./mediawiki-helpers');
|
|
21
|
+
|
|
22
|
+
/** The revisions of the history page, newest first: id, summary, author. */
|
|
23
|
+
async function revisions(world) {
|
|
24
|
+
return world.page.evaluate(() => [...document.querySelectorAll('#pagehistory li[data-mw-revid], #pagehistory li')].map((li) => ({
|
|
25
|
+
id: li.getAttribute('data-mw-revid'),
|
|
26
|
+
summary: (() => { const t = ((li.querySelector('.comment') || {}).textContent || '').replace(/\s+/g, ' ').trim(); return t.startsWith('(') && t.endsWith(')') ? t.slice(1, -1) : t; })(),
|
|
27
|
+
user: ((li.querySelector('.history-user a, .mw-userlink') || {}).textContent || '').replace(/[-]/g, '').trim(),
|
|
28
|
+
}))).catch(() => []);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function historyRow(world, summary) {
|
|
32
|
+
const rows = await revisions(world);
|
|
33
|
+
const index = rows.findIndex((r) => r.summary === summary || r.summary.includes(summary));
|
|
34
|
+
if (index < 0) {
|
|
35
|
+
throw friendly({ message: `The history has no revision "${summary}". Its revisions: ${listed(rows.map((r) => r.summary || '(no summary)'))}.`, hint: 'A revision is named by its edit summary; open the history first ("When I open the history of the page ...").' });
|
|
36
|
+
}
|
|
37
|
+
return { index, row: world.page.locator('#pagehistory li').nth(index), rows };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Open the history of a page (action=history).
|
|
42
|
+
*
|
|
43
|
+
* Example #1: When I open the history of the page "History test page"
|
|
44
|
+
* Example #2: When we open the history of the page "Editing test page"
|
|
45
|
+
* Example #3: And I open the history of the page "Reading test page"
|
|
46
|
+
* Example #4: When I open the history of the page "Visual editor test page"
|
|
47
|
+
* Example #5: When I open the history of the page "Conflict test page"
|
|
48
|
+
*/
|
|
49
|
+
When(/^(I |we )*open the history of the page "([^"]*)"$/, { timeout: 60000 }, async function (pronounCase, title) {
|
|
50
|
+
await openPage(this, title, { action: 'history' });
|
|
51
|
+
if (cutRequest(this)) throw friendly({ message: `The history of "${title}" did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
52
|
+
if ((await config(this, 'wgAction')) !== 'history') throw friendly({ message: `The history of "${titleText(title)}" did not open: ${await pageSummary(this)}.`, hint: 'The page must exist.' });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Assert that the history lists, or does not list, a revision by its edit
|
|
57
|
+
* summary, and by its author (a handle of the users registry or an account name).
|
|
58
|
+
*
|
|
59
|
+
* Example #1: Then the history should list the revision "First version"
|
|
60
|
+
* Example #2: Then the history should list the revision "A typo" by "editor"
|
|
61
|
+
* Example #3: And the history should not list the revision "Never saved"
|
|
62
|
+
* Example #4: Then the history should list the revision "Second version" by "administrator"
|
|
63
|
+
* Example #5: And the history should list the revision "Undid revision"
|
|
64
|
+
*/
|
|
65
|
+
Then(/^the history should( not)* list the revision "([^"]*)"(?: by "([^"]*)")?$/, async function (notCase, summary, who) {
|
|
66
|
+
const rows = await revisions(this);
|
|
67
|
+
const author = who ? accountName(this, who) : null;
|
|
68
|
+
const has = rows.some((r) => (r.summary === summary || r.summary.includes(summary)) && (!author || r.user === author));
|
|
69
|
+
if (!!notCase === has) {
|
|
70
|
+
throw friendly({ message: notCase ? `The history lists the revision "${summary}".` : `The history has no revision "${summary}"${author ? ` by ${author}` : ''}. It lists: ${listed(rows.map((r) => `${r.summary || '(no summary)'} by ${r.user}`))}.`, hint: 'Open the history first ("When I open the history of the page ...").' });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Assert how many revisions the history lists.
|
|
76
|
+
*
|
|
77
|
+
* Example #1: Then the history should list 2 revisions
|
|
78
|
+
* Example #2: Then the history should list 1 revision
|
|
79
|
+
* Example #3: And the history should list 3 revisions
|
|
80
|
+
* Example #4: Then the history should list 4 revisions
|
|
81
|
+
* Example #5: And the history should list 2 revisions
|
|
82
|
+
*/
|
|
83
|
+
Then(/^the history should list (\d+) revisions?$/, async function (count) {
|
|
84
|
+
const rows = await revisions(this);
|
|
85
|
+
if (rows.length !== Number(count)) {
|
|
86
|
+
throw friendly({ message: `The history lists ${rows.length} revision(s), not ${count}: ${listed(rows.map((r) => r.summary || '(no summary)'))}.`, hint: 'Open the history first; it lists up to 50 revisions per page.' });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Compare two revisions from the history, as a person does: the older one as
|
|
92
|
+
* the first, the newer one as the second, then "Compare selected revisions".
|
|
93
|
+
*
|
|
94
|
+
* Example #1: When I compare the revisions "First version" and "Second version"
|
|
95
|
+
* Example #2: When we compare the revisions "First version" and "Undid revision"
|
|
96
|
+
* Example #3: And I compare the revisions "Second version" and "Third version"
|
|
97
|
+
* Example #4: When I compare the revisions "First version" and "Third version"
|
|
98
|
+
* Example #5: When we compare the revisions "Second version" and "First version"
|
|
99
|
+
*/
|
|
100
|
+
When(/^(I |we )*compare the revisions "([^"]*)" and "([^"]*)"$/, { timeout: 60000 }, async function (pronounCase, first, second) {
|
|
101
|
+
const a = await historyRow(this, first);
|
|
102
|
+
const b = await historyRow(this, second);
|
|
103
|
+
// The history lists the newest first: the older revision is the one further down.
|
|
104
|
+
const [older, newer] = a.index > b.index ? [a, b] : [b, a];
|
|
105
|
+
await older.row.locator('input[name="oldid"]').check();
|
|
106
|
+
await newer.row.locator('input[name="diff"]').check();
|
|
107
|
+
await afterNavigation(this, () => this.page.getByRole('button', { name: 'Compare selected revisions' }).first().click());
|
|
108
|
+
if (cutRequest(this)) throw friendly({ message: `The comparison did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
109
|
+
if (!(await this.page.locator('table.diff').count())) throw friendly({ message: `The comparison did not open: ${await pageSummary(this)}.`, hint: 'Compare two different revisions of the page.' });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Undo a revision from the history, as a person does with its "undo" link: the
|
|
114
|
+
* editor opens with the change taken back and the summary written ("Undid
|
|
115
|
+
* revision …"). Save it with "When I save the page".
|
|
116
|
+
*
|
|
117
|
+
* Example #1: When I undo the revision "Second version"
|
|
118
|
+
* Example #2: When we undo the revision "Changed meanwhile"
|
|
119
|
+
* Example #3: And I undo the revision "Third version"
|
|
120
|
+
* Example #4: When I undo the revision "A typo"
|
|
121
|
+
* Example #5: When we undo the revision "Second version"
|
|
122
|
+
*/
|
|
123
|
+
When(/^(I |we )*undo the revision "([^"]*)"$/, { timeout: 60000 }, async function (pronounCase, summary) {
|
|
124
|
+
const { row } = await historyRow(this, summary);
|
|
125
|
+
const undo = row.getByRole('link', { name: 'undo' });
|
|
126
|
+
if (!(await undo.count())) throw friendly({ message: `The revision "${summary}" has no "undo" link.`, hint: 'The first revision of a page cannot be undone; the account must be allowed to edit the page.' });
|
|
127
|
+
await afterNavigation(this, () => undo.first().click());
|
|
128
|
+
await closeWelcomeDialog(this);
|
|
129
|
+
const ok = await this.page.locator('.mw-undo-success').count();
|
|
130
|
+
if (!ok) {
|
|
131
|
+
throw friendly({ message: `The wiki cannot undo the revision "${summary}": ${listed((await messages(this, 'error')).concat(await messages(this, 'warning')))}; ${await pageSummary(this)}.`, hint: 'A revision whose lines changed again later cannot be undone ("The edit could not be undone due to conflicting intermediate edits.").' });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
module.exports = { revisions };
|