@webship-js/mediawiki-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 +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,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Files: the upload form (Special:Upload, when the wiki allows uploads), its
|
|
4
|
+
// warnings, and the page of an uploaded file.
|
|
5
|
+
|
|
6
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
7
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
8
|
+
const {
|
|
9
|
+
clean,
|
|
10
|
+
listed,
|
|
11
|
+
titleText,
|
|
12
|
+
config,
|
|
13
|
+
cutRequest,
|
|
14
|
+
CUT_HINT,
|
|
15
|
+
openPage,
|
|
16
|
+
afterNavigation,
|
|
17
|
+
eventually,
|
|
18
|
+
pageSummary,
|
|
19
|
+
fixturePath,
|
|
20
|
+
} = require('./mediawiki-helpers');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Upload a file with the upload form, as a person does: the file, the name it
|
|
24
|
+
* gets on the wiki, a summary, and "Ignore any warnings" when asked. The local
|
|
25
|
+
* file is a path from the project, or from this pack (tests/fixtures/ ships with
|
|
26
|
+
* it). The step waits for the wiki's answer: the file's page, or a warning.
|
|
27
|
+
*
|
|
28
|
+
* Example #1: When I upload the file "tests/fixtures/blue-square.png" as "Test square.png"
|
|
29
|
+
* Example #2: When I upload the file "tests/fixtures/blue-square.png" as "Test square.png" with the summary "A blue square"
|
|
30
|
+
* Example #3: When we upload the file "tests/fixtures/blue-square.png" as "Second square.png" ignoring warnings
|
|
31
|
+
* Example #4: And I upload the file "tests/fixtures/blue-square.png" as "Test square.png" with the summary "A blue square" ignoring warnings
|
|
32
|
+
* Example #5: When I upload the file "tests/fixtures/blue-square.png" as "Duplicate square.png"
|
|
33
|
+
*/
|
|
34
|
+
When(/^(I |we )*upload the file "([^"]*)" as "([^"]*)"(?: with the summary "([^"]*)")?( ignoring warnings)?$/, { timeout: 120000 }, async function (pronounCase, file, name, summary, ignoreCase) {
|
|
35
|
+
const local = fixturePath(file);
|
|
36
|
+
const page = this.page;
|
|
37
|
+
await openPage(this, 'Special:Upload');
|
|
38
|
+
if (!(await page.locator('#wpUploadFile').count())) {
|
|
39
|
+
throw friendly({ message: `The upload form is not on Special:Upload: ${await pageSummary(this)}.`, hint: 'The wiki must allow uploads ($wgEnableUploads), and the account must have the "upload" right (logged in).' });
|
|
40
|
+
}
|
|
41
|
+
await page.locator('#wpUploadFile').setInputFiles(local);
|
|
42
|
+
await page.locator('#wpDestFile').fill(name);
|
|
43
|
+
if (summary) await page.locator('#wpUploadDescription').fill(summary);
|
|
44
|
+
if (ignoreCase) await page.locator('#wpIgnoreWarning').check();
|
|
45
|
+
await afterNavigation(this, () => page.locator('input[name="wpUpload"], button[name="wpUpload"]').first().click());
|
|
46
|
+
if (cutRequest(this)) throw friendly({ message: `The upload did not reach the wiki: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Assert that the wiki held the upload back with a warning (or a part of it):
|
|
51
|
+
* the upload form came back under "Upload warning".
|
|
52
|
+
*
|
|
53
|
+
* Example #1: Then the upload should be held back with the warning "This file is a duplicate of the following file"
|
|
54
|
+
* Example #2: Then the upload should be held back with the warning "A file with this name exists already"
|
|
55
|
+
* Example #3: And the upload should be held back with the warning "duplicate"
|
|
56
|
+
* Example #4: Then the upload should be held back with the warning "This file is a duplicate of the following file: Test square.png"
|
|
57
|
+
* Example #5: Then the upload should be held back with the warning "Please modify the file description below and try again."
|
|
58
|
+
*/
|
|
59
|
+
Then(/^the upload should be held back with the warning "([^"]*)"$/, async function (expected) {
|
|
60
|
+
const state = await this.page.evaluate(() => {
|
|
61
|
+
const heading = [...document.querySelectorAll('#mw-content-text h2')].find((h) => /Upload warning/i.test(h.textContent));
|
|
62
|
+
let text = '';
|
|
63
|
+
if (heading) {
|
|
64
|
+
for (let el = heading.nextElementSibling; el && el.tagName !== 'FORM' && el.id !== 'mw-upload-form'; el = el.nextElementSibling) text += ' ' + el.textContent;
|
|
65
|
+
if (!text.trim()) text = (heading.parentElement || document.body).textContent;
|
|
66
|
+
}
|
|
67
|
+
return { warned: !!heading, text: text.replace(/\s+/g, ' ').trim(), special: window.mw ? mw.config.get('wgCanonicalSpecialPageName') : null };
|
|
68
|
+
}).catch(() => ({ warned: false, text: '', special: null }));
|
|
69
|
+
if (!state.warned || state.special !== 'Upload' || !state.text.toLowerCase().includes(clean(expected).toLowerCase())) {
|
|
70
|
+
throw friendly({ message: state.warned ? `The upload warning says "${state.text.slice(0, 300)}", not "${expected}".` : `The wiki did not hold the upload back with a warning: ${await pageSummary(this)}.`, hint: 'Upload with "When I upload the file ... as ..." (without "ignoring warnings").' });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Assert that the browser shows the page of an uploaded file, with its image
|
|
76
|
+
* loaded.
|
|
77
|
+
*
|
|
78
|
+
* Example #1: Then I should see the file "Test square.png"
|
|
79
|
+
* Example #2: Then we should see the file "Second square.png"
|
|
80
|
+
* Example #3: And I should see the file "Test square.png"
|
|
81
|
+
* Example #4: Then I should see the file "Duplicate square.png"
|
|
82
|
+
* Example #5: Then I should see the file "Reading test image.png"
|
|
83
|
+
*/
|
|
84
|
+
Then(/^(I |we )*should see the file "([^"]*)"$/, async function (pronounCase, name) {
|
|
85
|
+
const want = titleText(`File:${name}`);
|
|
86
|
+
await eventually(this, async () => ({
|
|
87
|
+
page: titleText(String(await config(this, 'wgPageName') || '')),
|
|
88
|
+
image: await this.page.evaluate(() => { const img = document.querySelector('#file img, .fullImageLink img'); return img ? { loaded: img.complete && img.naturalWidth > 0, src: img.getAttribute('src') } : null; }).catch(() => null),
|
|
89
|
+
}), (v) => v.page === want && v.image && v.image.loaded,
|
|
90
|
+
(v) => ({ message: v.page === want ? `The page of "${name}" shows ${v.image ? `an image that did not load (${v.image.src})` : 'no image'}.` : `Expected the page "${want}"; the browser shows "${v.page || this.page.url()}".`, hint: 'Upload the file first; its page is File:<name>.' }));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
module.exports = {};
|