@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,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Following changes: the watch star of a page, the watchlist, recent changes,
|
|
4
|
+
// and the preferences of an account.
|
|
5
|
+
//
|
|
6
|
+
// Waits: the request the watch star sends (api.php action=watch or unwatch);
|
|
7
|
+
// the filters app of the watchlist and of recent changes
|
|
8
|
+
// (body.mw-rcfilters-ui-initialized); the preferences module through the module
|
|
9
|
+
// loader.
|
|
10
|
+
|
|
11
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
12
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
13
|
+
const {
|
|
14
|
+
budget,
|
|
15
|
+
clean,
|
|
16
|
+
listed,
|
|
17
|
+
titleText,
|
|
18
|
+
config,
|
|
19
|
+
cutRequest,
|
|
20
|
+
CUT_HINT,
|
|
21
|
+
waitForModules,
|
|
22
|
+
openPage,
|
|
23
|
+
afterNavigation,
|
|
24
|
+
eventually,
|
|
25
|
+
pageSummary,
|
|
26
|
+
messages,
|
|
27
|
+
hasMessage,
|
|
28
|
+
accountName,
|
|
29
|
+
} = require('./mediawiki-helpers');
|
|
30
|
+
|
|
31
|
+
/** The state of the watch star of the page: 'watched', 'unwatched' or null when there is none. */
|
|
32
|
+
async function starState(world) {
|
|
33
|
+
return world.page.evaluate(() => {
|
|
34
|
+
const visible = (sel) => [...document.querySelectorAll(sel)].some((e) => e.offsetParent);
|
|
35
|
+
if (visible('#ca-unwatch')) return 'watched';
|
|
36
|
+
if (visible('#ca-watch')) return 'unwatched';
|
|
37
|
+
return null;
|
|
38
|
+
}).catch(() => null);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The watchlist popover of the default skin ("Organize watchlist"), when it is open. */
|
|
42
|
+
function watchPopup(world) {
|
|
43
|
+
return world.page.locator('.mw-watchstar-WatchlistPopup').filter({ visible: true }).first();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Close the popover the default skin opens over the watch star ("Organize
|
|
48
|
+
* watchlist") with its "Close" button: while it is open, the next click on the
|
|
49
|
+
* page only closes it.
|
|
50
|
+
*/
|
|
51
|
+
async function closeWatchPopup(world) {
|
|
52
|
+
const popup = watchPopup(world);
|
|
53
|
+
await popup.waitFor({ state: 'visible', timeout: 1500 }).catch(() => {});
|
|
54
|
+
if (!(await popup.count())) return;
|
|
55
|
+
const close = popup.getByRole('button', { name: 'Close' });
|
|
56
|
+
if (await close.count()) await close.click();
|
|
57
|
+
else await world.page.keyboard.press('Escape');
|
|
58
|
+
await popup.waitFor({ state: 'hidden', timeout: budget(world) }).catch(() => {});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Watch the page on screen, or stop watching it, with its watch star, as a person
|
|
63
|
+
* does. The default skin of the current release answers a click on the star of a
|
|
64
|
+
* watched page with its "Organize watchlist" popover, whose "Unwatch" button
|
|
65
|
+
* stops watching it; the step clicks it then. The step waits for the wiki's
|
|
66
|
+
* answer to the request (api.php action=watch) and closes the popover.
|
|
67
|
+
*
|
|
68
|
+
* Example #1: When I watch the page
|
|
69
|
+
* Example #2: When I stop watching the page
|
|
70
|
+
* Example #3: And we watch the page
|
|
71
|
+
* Example #4: When we stop watching the page
|
|
72
|
+
* Example #5: Then I watch the page
|
|
73
|
+
*/
|
|
74
|
+
When(/^(I |we )*(watch|stop watching) the page$/, { timeout: 60000 }, async function (pronounCase, action) {
|
|
75
|
+
const page = this.page;
|
|
76
|
+
const want = action === 'watch' ? 'watched' : 'unwatched';
|
|
77
|
+
const state = await starState(this);
|
|
78
|
+
if (!state) throw friendly({ message: `The page has no watch star: ${await pageSummary(this)}.`, hint: 'Log in first: a visitor has no watchlist.' });
|
|
79
|
+
if (state === want) return;
|
|
80
|
+
await closeWatchPopup(this);
|
|
81
|
+
const request = () => page.waitForResponse((r) => /api\.php/.test(r.url()) && /action=watch/.test(r.request().postData() || r.url()), { timeout: budget(this) }).catch(() => null);
|
|
82
|
+
let answered = request();
|
|
83
|
+
const star = page.locator(state === 'unwatched' ? '#ca-watch a, a#ca-watch' : '#ca-unwatch a, a#ca-unwatch').filter({ visible: true }).first();
|
|
84
|
+
await star.click();
|
|
85
|
+
const after = await eventually(this, async () => ({ state: await starState(this), popup: await watchPopup(this).count() }),
|
|
86
|
+
(v) => v.state === want || v.popup > 0,
|
|
87
|
+
(v) => ({ message: `The watch star did not answer (it shows "${v.state}").`, hint: cutRequest(this) ? CUT_HINT : 'The star sends action=watch to the API, or opens the "Organize watchlist" popover.' }));
|
|
88
|
+
if (after.state !== want && want === 'unwatched') {
|
|
89
|
+
const unwatch = watchPopup(this).getByRole('button', { name: 'Unwatch' });
|
|
90
|
+
if (!(await unwatch.count())) throw friendly({ message: 'The "Organize watchlist" popover has no "Unwatch" button.', hint: 'The popover of the star offers "Unwatch" for a watched page.' });
|
|
91
|
+
answered = request();
|
|
92
|
+
await unwatch.click();
|
|
93
|
+
}
|
|
94
|
+
await answered;
|
|
95
|
+
await eventually(this, () => starState(this), (st) => st === want,
|
|
96
|
+
(st) => ({ message: `The watch star did not change to "${want}" (it shows "${st}").`, hint: cutRequest(this) ? CUT_HINT : 'The star sends action=watch (with unwatch=1 to stop watching) to the API.' }));
|
|
97
|
+
await closeWatchPopup(this);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Assert that the account watches, or does not watch, the page on screen (its
|
|
102
|
+
* watch star).
|
|
103
|
+
*
|
|
104
|
+
* Example #1: Then I should be watching the page
|
|
105
|
+
* Example #2: Then I should not be watching the page
|
|
106
|
+
* Example #3: And we should be watching the page
|
|
107
|
+
* Example #4: And we should not be watching the page
|
|
108
|
+
* Example #5: Then I should be watching the page
|
|
109
|
+
*/
|
|
110
|
+
Then(/^(I |we )*should( not)* be watching the page$/, async function (pronounCase, notCase) {
|
|
111
|
+
const state = await starState(this);
|
|
112
|
+
if ((state === 'watched') === !!notCase) {
|
|
113
|
+
throw friendly({ message: `The watch star says the page is ${state || 'not watchable'}.`, hint: 'Log in and open a page first.' });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Assert that the watchlist of the account lists, or does not list, a page
|
|
119
|
+
* (Special:EditWatchlist, the list of watched pages).
|
|
120
|
+
*
|
|
121
|
+
* Example #1: Then my watchlist should list the page "Reading test page"
|
|
122
|
+
* Example #2: Then my watchlist should not list the page "Second test page"
|
|
123
|
+
* Example #3: And our watchlist should list the page "History test page"
|
|
124
|
+
* Example #4: Then my watchlist should list the page "Talk:Reading test page"
|
|
125
|
+
* Example #5: And my watchlist should not list the page "Reading test page"
|
|
126
|
+
*/
|
|
127
|
+
Then(/^(my|our) watchlist should( not)* list the page "([^"]*)"$/, { timeout: 60000 }, async function (possessive, notCase, title) {
|
|
128
|
+
await openPage(this, 'Special:EditWatchlist');
|
|
129
|
+
const titles = await this.page.evaluate(() => [...document.querySelectorAll('#mw-content-text input[type="checkbox"][name="wpTitles[]"], #mw-content-text input[type="checkbox"]')].map((c) => c.value).filter((v) => v && v !== 'on')).catch(() => []);
|
|
130
|
+
const want = titleText(title);
|
|
131
|
+
if (!!notCase === titles.map(titleText).includes(want)) {
|
|
132
|
+
throw friendly({ message: notCase ? `The watchlist lists "${want}".` : `The watchlist does not list "${want}". It lists: ${listed(titles.map(titleText))}.`, hint: 'Log in first; a page is watched with its star, or when the account edits it with "Watch this page" ticked.' });
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/** The lines of a changes list (the watchlist or recent changes), once its filters app is ready. */
|
|
137
|
+
async function changesLines(world, special) {
|
|
138
|
+
await openPage(world, special);
|
|
139
|
+
if (cutRequest(world)) throw friendly({ message: `${special} did not open: ${cutRequest(world)}.`, hint: CUT_HINT });
|
|
140
|
+
await world.page.waitForFunction(() => document.body.classList.contains('mw-rcfilters-ui-initialized') || !document.body.classList.contains('mw-rcfilters-enabled'), null, { timeout: budget(world) }).catch(() => {});
|
|
141
|
+
await world.page.locator('.mw-rcfilters-ui-changesListWrapperWidget-pending, .mw-changeslist-results-empty').first().waitFor({ state: 'detached', timeout: 2000 }).catch(() => {});
|
|
142
|
+
return world.page.evaluate(() => [...document.querySelectorAll('.mw-changeslist .mw-changeslist-line, .mw-changeslist li')].map((line) => ({
|
|
143
|
+
titles: [...line.querySelectorAll('.mw-changeslist-title, .mw-title a')].map((a) => a.textContent.trim()),
|
|
144
|
+
text: line.textContent.replace(/[-]/g, '').replace(/\s+/g, ' ').trim(),
|
|
145
|
+
}))).catch(() => []);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Assert that the watchlist (Special:Watchlist) or recent changes
|
|
150
|
+
* (Special:RecentChanges) show a change to a page, and its edit summary and
|
|
151
|
+
* author when given. A change folded into a group of the same page counts.
|
|
152
|
+
*
|
|
153
|
+
* Example #1: Then the recent changes should show a change to "Reading test page"
|
|
154
|
+
* Example #2: Then the recent changes should show a change to "History test page" with the summary "Second version"
|
|
155
|
+
* Example #3: Then the watchlist should show a change to "Reading test page"
|
|
156
|
+
* Example #4: And the recent changes should show a change to "History test page" by "administrator"
|
|
157
|
+
* Example #5: Then the watchlist should show a change to "History test page" with the summary "Second version"
|
|
158
|
+
*/
|
|
159
|
+
Then(/^the (recent changes|watchlist) should show a change to "([^"]*)"(?: with the summary "([^"]*)")?(?: by "([^"]*)")?$/, { timeout: 60000 }, async function (list, title, summary, who) {
|
|
160
|
+
const special = list === 'watchlist' ? 'Special:Watchlist' : 'Special:RecentChanges';
|
|
161
|
+
const want = titleText(title);
|
|
162
|
+
const author = who ? accountName(this, who) : null;
|
|
163
|
+
const lines = await changesLines(this, special);
|
|
164
|
+
const match = lines.filter((l) => l.titles.includes(want) && (!summary || l.text.includes(summary)) && (!author || l.text.includes(author)));
|
|
165
|
+
if (!match.length) {
|
|
166
|
+
throw friendly({ message: `The ${list} show no change to "${want}"${summary ? ` with the summary "${summary}"` : ''}${author ? ` by ${author}` : ''}. Pages in it: ${listed([].concat(...lines.map((l) => l.titles)).slice(0, 20))}.`, hint: list === 'watchlist' ? 'The watchlist shows the changes to the pages the account watches, from others and its own.' : 'Recent changes show the last 7 days by default; bots are hidden.' });
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Open the preferences of the account (Special:Preferences) and wait for the
|
|
172
|
+
* preferences module.
|
|
173
|
+
*
|
|
174
|
+
* Example #1: When I open my preferences
|
|
175
|
+
* Example #2: When we open our preferences
|
|
176
|
+
* Example #3: And I open my preferences
|
|
177
|
+
* Example #4: Given I open my preferences
|
|
178
|
+
* Example #5: When I open my preferences
|
|
179
|
+
*/
|
|
180
|
+
When(/^(I |we )*open (my|our) preferences$/, { timeout: 60000 }, async function (pronounCase, possessive) {
|
|
181
|
+
await openPage(this, 'Special:Preferences');
|
|
182
|
+
if (cutRequest(this)) throw friendly({ message: `The preferences did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
183
|
+
if ((await config(this, 'wgCanonicalSpecialPageName')) !== 'Preferences' || !(await this.page.locator('#mw-prefs-form').count())) {
|
|
184
|
+
throw friendly({ message: `The preferences did not open: ${await pageSummary(this)}.`, hint: 'Log in first: a visitor has no preferences.' });
|
|
185
|
+
}
|
|
186
|
+
await waitForModules(this, 'mediawiki.special.preferences.ooui', { what: 'The preferences form' });
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/** The checkbox of a preference by its label, after its tab was opened. */
|
|
190
|
+
async function preferenceBox(world, label) {
|
|
191
|
+
const page = world.page;
|
|
192
|
+
const tabIndex = await page.evaluate((text) => {
|
|
193
|
+
const panels = [...document.querySelectorAll('#mw-prefs-form [role="tabpanel"]')];
|
|
194
|
+
return panels.findIndex((p) => [...p.querySelectorAll('label, .oo-ui-labelElement-label')].some((l) => l.textContent.replace(/\s+/g, ' ').trim() === text));
|
|
195
|
+
}, clean(label));
|
|
196
|
+
if (tabIndex < 0) {
|
|
197
|
+
const labels = await page.evaluate(() => [...document.querySelectorAll('#mw-prefs-form .oo-ui-checkboxInputWidget')].map((w) => (w.closest('.oo-ui-fieldLayout') || w).textContent.replace(/\s+/g, ' ').trim()).slice(0, 40)).catch(() => []);
|
|
198
|
+
throw friendly({ message: `The preferences have no "${label}". Some of their boxes: ${listed(labels)}.`, hint: 'Name the preference by its label as the page writes it; open the preferences first ("When I open my preferences").' });
|
|
199
|
+
}
|
|
200
|
+
const tab = page.locator('#mw-prefs-form [role="tab"]').nth(tabIndex);
|
|
201
|
+
if ((await tab.getAttribute('aria-selected')) !== 'true') await tab.click();
|
|
202
|
+
const box = page.getByRole('checkbox', { name: clean(label), exact: true });
|
|
203
|
+
await box.first().waitFor({ state: 'visible', timeout: budget(world) });
|
|
204
|
+
return box.first();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Tick or untick a preference by its label (the step opens the tab it is on).
|
|
209
|
+
*
|
|
210
|
+
* Example #1: When I tick the preference "Mark all edits minor by default"
|
|
211
|
+
* Example #2: When I untick the preference "Mark all edits minor by default"
|
|
212
|
+
* Example #3: And we tick the preference "Show preview before edit box"
|
|
213
|
+
* Example #4: When we untick the preference "Show preview before edit box"
|
|
214
|
+
* Example #5: When I tick the preference "Add pages I create and files I upload to my watchlist"
|
|
215
|
+
*/
|
|
216
|
+
When(/^(I |we )*(tick|untick) the preference "([^"]*)"$/, async function (pronounCase, action, label) {
|
|
217
|
+
const box = await preferenceBox(this, label);
|
|
218
|
+
if (action === 'tick') await box.check();
|
|
219
|
+
else await box.uncheck();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Save the preferences; the step waits for the wiki's answer ("Your preferences
|
|
224
|
+
* have been saved.").
|
|
225
|
+
*
|
|
226
|
+
* Example #1: When I save my preferences
|
|
227
|
+
* Example #2: When we save our preferences
|
|
228
|
+
* Example #3: And I save my preferences
|
|
229
|
+
* Example #4: Then I save my preferences
|
|
230
|
+
* Example #5: When I save my preferences
|
|
231
|
+
*/
|
|
232
|
+
When(/^(I |we )*save (my|our) preferences$/, { timeout: 60000 }, async function (pronounCase, possessive) {
|
|
233
|
+
const save = this.page.locator('#prefcontrol button, #prefcontrol input[type="submit"]').filter({ visible: true }).first();
|
|
234
|
+
await this.page.waitForFunction(() => { const b = document.querySelector('#prefcontrol button, #prefcontrol input[type="submit"]'); return b && !b.disabled; }, null, { timeout: budget(this) }).catch(() => {});
|
|
235
|
+
await afterNavigation(this, () => save.click());
|
|
236
|
+
if (cutRequest(this)) throw friendly({ message: `The preferences were not saved: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
237
|
+
// The wiki answers with a success box that the page's script hides at once and shows again as a
|
|
238
|
+
// notification ("Your preferences have been saved."): either one is the answer.
|
|
239
|
+
const confirmed = () => this.page.evaluate(() => [...document.querySelectorAll('.mw-preferences-messagebox, .mw-notification')]
|
|
240
|
+
.map((e) => e.textContent.replace(/\s+/g, ' ').trim()).filter(Boolean)).catch(() => []);
|
|
241
|
+
const said = await eventually(this, confirmed, (lines) => hasMessage(lines, 'Your preferences have been saved.') || lines.length > 0, () => ({ message: 'The wiki did not answer the save of the preferences.', hint: 'The "Save" button is on only after a change.' }));
|
|
242
|
+
if (!hasMessage(said, 'Your preferences have been saved.')) {
|
|
243
|
+
throw friendly({ message: `The wiki did not confirm the preferences: ${listed(said.concat(await messages(this, 'error')))}.`, hint: 'The "Save" button is on only after a change.' });
|
|
244
|
+
}
|
|
245
|
+
await waitForModules(this, 'mediawiki.special.preferences.ooui', { what: 'The preferences form' });
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Assert that a preference is ticked or not, by its label.
|
|
250
|
+
*
|
|
251
|
+
* Example #1: Then the preference "Mark all edits minor by default" should be ticked
|
|
252
|
+
* Example #2: Then the preference "Mark all edits minor by default" should not be ticked
|
|
253
|
+
* Example #3: And the preference "Show preview before edit box" should be ticked
|
|
254
|
+
* Example #4: Then the preference "Warn me when I leave an edit page with unsaved changes" should be ticked
|
|
255
|
+
* Example #5: And the preference "Show preview before edit box" should not be ticked
|
|
256
|
+
*/
|
|
257
|
+
Then(/^the preference "([^"]*)" should( not)* be ticked$/, async function (label, notCase) {
|
|
258
|
+
const box = await preferenceBox(this, label);
|
|
259
|
+
const checked = await box.isChecked();
|
|
260
|
+
if (checked === !!notCase) {
|
|
261
|
+
throw friendly({ message: `The preference "${label}" is ${checked ? 'ticked' : 'not ticked'}.`, hint: 'Tick or untick it, then save the preferences.' });
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
module.exports = { starState, changesLines };
|