2019-07-02 21:10:10 +00:00
|
|
|
( function () {
|
2023-11-07 16:29:17 +00:00
|
|
|
const iconElement = document.createElement( 'div' ),
|
tests: Adopt private require() for skins.minerva.scripts
Added to MediaWiki core last year with I9fca9fdf9b7623b1.
This fixes a confusing assertion in page-issues/index.test.js,
where for "insertBannersOrNotice()" it was asserting that the HTML
contain "⧼skin-minerva-issue-learn-more⧽", where the ⧼ character
indicates the message is not found (i.e. an error).
The test had to be written this way in order to pass, because
the skins.minerva.scripts module was not actually loaded, and thus
its templates and messages are not present either. This lack was
filled in by index.js for mw.templates, but not mw.messages.
By adopting private require(), these workarounds can all be removed.
== Motivation ==
In change I3a4024ccf90e505581, I'm working on improving the testrunner
config to enforce uselang=qqx on all tests. This is passing except
for GrowthExperiments and Minerva, both of which have the above
workarounds in place that caused a message to be undefined, and then
kept in the assertion expectation. When using uselang=qqx, values are
returned as (key) instead of ⧼key⧽, which exposes these message
existence errors.
By removing this workaround, the test will simply import the module
in the test as normal, thus the messages will exist, and thus it
will expect (key), and thus it will continue to pass even after
enforcing uselang=qqx.
Change-Id: Ib68f45d93a7054ed8bd35fc5644e2852f2f90248
2024-08-23 04:25:52 +00:00
|
|
|
pageIssuesParser = require( 'skins.minerva.scripts/page-issues/parser.js' ),
|
2018-10-16 23:02:22 +00:00
|
|
|
extractMessage = pageIssuesParser.extract;
|
2018-07-10 20:06:51 +00:00
|
|
|
|
2023-11-07 16:29:17 +00:00
|
|
|
iconElement.classList.add( 'minerva-icon--issue-generic-defaultColor', 'minerva-ambox-icon' );
|
2018-08-16 19:00:38 +00:00
|
|
|
QUnit.module( 'Minerva pageIssuesParser' );
|
2018-07-10 20:06:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} className
|
|
|
|
* @return {Element}
|
|
|
|
*/
|
|
|
|
function newBox( className ) {
|
2024-03-24 20:53:43 +00:00
|
|
|
const box = document.createElement( 'div' );
|
2018-07-10 20:06:51 +00:00
|
|
|
box.className = className;
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'extractMessage', ( assert ) => {
|
2018-10-16 23:02:22 +00:00
|
|
|
[
|
|
|
|
[
|
2024-03-29 09:27:19 +00:00
|
|
|
$( '<div>' ).html(
|
2018-10-16 23:02:22 +00:00
|
|
|
'<div class="mbox-text">Smelly</div>'
|
|
|
|
).appendTo( '<div class="mw-collapsible-content" />' ),
|
|
|
|
{
|
|
|
|
issue: {
|
|
|
|
severity: 'DEFAULT',
|
2023-11-07 16:29:17 +00:00
|
|
|
iconElement,
|
|
|
|
grouped: true
|
2018-10-16 23:02:22 +00:00
|
|
|
},
|
|
|
|
text: '<p>Smelly</p>'
|
|
|
|
},
|
|
|
|
'When the box is a child of mw-collapsible-content it grouped'
|
|
|
|
],
|
|
|
|
[
|
2024-03-29 09:27:19 +00:00
|
|
|
$( '<div>' ).html(
|
2018-10-16 23:02:22 +00:00
|
|
|
'<div class="mbox-text">Dirty</div>'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
issue: {
|
|
|
|
severity: 'DEFAULT',
|
2023-11-07 16:29:17 +00:00
|
|
|
iconElement,
|
|
|
|
grouped: false
|
2018-10-16 23:02:22 +00:00
|
|
|
},
|
|
|
|
text: '<p>Dirty</p>'
|
|
|
|
},
|
|
|
|
'When the box is not child of mw-collapsible-content it !grouped'
|
|
|
|
]
|
2024-06-03 12:06:43 +00:00
|
|
|
].forEach( ( test ) => {
|
2023-11-07 16:29:17 +00:00
|
|
|
const msg = extractMessage( test[ 0 ] );
|
|
|
|
delete msg.$el;
|
|
|
|
assert.deepEqual(
|
|
|
|
msg,
|
2018-10-16 23:02:22 +00:00
|
|
|
test[ 1 ],
|
|
|
|
test[ 2 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'parseSeverity', ( assert ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const tests = [
|
2018-07-10 20:06:51 +00:00
|
|
|
[ '', 'DEFAULT', 'empty' ],
|
|
|
|
[ 'foo', 'DEFAULT', 'unknown' ],
|
|
|
|
[ 'ambox-style', 'LOW', 'style' ],
|
|
|
|
[ 'ambox-content', 'MEDIUM', 'content' ],
|
|
|
|
[ 'ambox-speedy', 'HIGH', 'speedy' ],
|
|
|
|
[ 'ambox-delete', 'HIGH', 'delete' ],
|
|
|
|
// Move has an "unknown" severity and falls into DEFAULT.
|
|
|
|
[ 'ambox-move', 'DEFAULT', 'move' ],
|
|
|
|
// Point of view uses ambox-content to identify correct severity.
|
|
|
|
[ 'ambox-content ambox-POV', 'MEDIUM', 'point of view' ]
|
|
|
|
// Mixed severities such as 'ambox-style ambox-content' are not prioritized.
|
|
|
|
];
|
2024-06-03 12:06:43 +00:00
|
|
|
tests.forEach( ( params, i ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const className = params[ 0 ];
|
|
|
|
const expect = params[ 1 ];
|
|
|
|
const test = params[ 2 ];
|
|
|
|
const box = newBox( className );
|
2018-07-10 20:06:51 +00:00
|
|
|
assert.strictEqual(
|
2018-08-16 19:00:38 +00:00
|
|
|
pageIssuesParser.test.parseSeverity( box ),
|
2018-07-10 20:06:51 +00:00
|
|
|
expect,
|
2018-07-11 15:16:21 +00:00
|
|
|
'Result should be the correct severity; case ' + i + ': ' + test + '.'
|
2018-07-10 20:06:51 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'parseType', ( assert ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const tests = [
|
2018-07-10 20:06:51 +00:00
|
|
|
[ '', 'DEFAULT', 'issue-generic', 'empty' ],
|
|
|
|
[ 'foo', 'DEFAULT', 'issue-generic', 'unknown' ],
|
|
|
|
[ 'ambox-move', 'DEFAULT', 'issue-type-move', 'move' ],
|
|
|
|
[ 'ambox-POV', 'MEDIUM', 'issue-type-point-of-view', 'point of view' ],
|
|
|
|
[ '', 'DEFAULT', 'issue-generic', 'Default severity' ],
|
|
|
|
[ '', 'LOW', 'issue-severity-low', 'Low severity' ],
|
|
|
|
[ '', 'MEDIUM', 'issue-severity-medium', 'Medium severity' ],
|
|
|
|
[ '', 'HIGH', 'issue-generic', 'HIGH severity' ]
|
|
|
|
];
|
2024-06-03 12:06:43 +00:00
|
|
|
tests.forEach( ( params, i ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const className = params[ 0 ];
|
|
|
|
const severity = params[ 1 ];
|
|
|
|
const expect = {
|
|
|
|
name: params[ 2 ],
|
|
|
|
severity: severity
|
|
|
|
};
|
|
|
|
const test = params[ 3 ];
|
|
|
|
const box = newBox( className );
|
2018-07-10 20:06:51 +00:00
|
|
|
assert.propEqual(
|
2018-08-16 19:00:38 +00:00
|
|
|
pageIssuesParser.test.parseType( box, severity ),
|
2018-07-10 20:06:51 +00:00
|
|
|
expect,
|
2018-07-11 15:16:21 +00:00
|
|
|
'Result should be the correct icon type; case ' + i + ': ' + test + '.'
|
2018-07-10 20:06:51 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'parseGroup', ( assert ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const tests = [
|
2018-09-06 18:39:58 +00:00
|
|
|
[ undefined, false, 'orphaned' ],
|
|
|
|
[ '', false, 'ungrouped' ],
|
|
|
|
[ 'mw-collapsible-content', true, 'grouped' ]
|
|
|
|
];
|
2024-06-03 12:06:43 +00:00
|
|
|
tests.forEach( ( params, i ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const parentClassName = params[ 0 ];
|
|
|
|
const expect = params[ 1 ];
|
|
|
|
const test = params[ 2 ];
|
|
|
|
const box = newBox( '' );
|
2018-09-06 18:39:58 +00:00
|
|
|
if ( parentClassName !== undefined ) {
|
2024-03-24 20:53:43 +00:00
|
|
|
const parent = document.createElement( 'div' );
|
2018-09-06 18:39:58 +00:00
|
|
|
parent.className = parentClassName;
|
|
|
|
parent.appendChild( box );
|
|
|
|
}
|
|
|
|
assert.strictEqual(
|
|
|
|
pageIssuesParser.test.parseGroup( box ),
|
|
|
|
expect,
|
|
|
|
'Result should be the correct grouping; case ' + i + ': ' + test + '.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'iconName', ( assert ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const tests = [
|
2018-07-10 20:06:51 +00:00
|
|
|
[ '', 'DEFAULT', 'issue-generic-defaultColor' ],
|
|
|
|
[ '', 'LOW', 'issue-severity-low-lowColor' ],
|
|
|
|
[ '', 'MEDIUM', 'issue-severity-medium-mediumColor' ],
|
|
|
|
[ '', 'HIGH', 'issue-generic-highColor' ],
|
|
|
|
[ 'ambox-move', 'DEFAULT', 'issue-type-move-defaultColor' ],
|
|
|
|
[ 'ambox-POV', 'MEDIUM', 'issue-type-point-of-view-mediumColor' ],
|
|
|
|
// ResourceLoader only supplies color variants for the generic type. Ensure impossible
|
|
|
|
// combinations are forbidden.
|
|
|
|
[ 'ambox-style ambox-POV', 'LOW', 'issue-type-point-of-view-mediumColor' ],
|
|
|
|
[ 'ambox-content ambox-move', 'MEDIUM', 'issue-type-move-defaultColor' ]
|
|
|
|
];
|
2024-06-03 12:06:43 +00:00
|
|
|
tests.forEach( ( params, i ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const className = params[ 0 ];
|
|
|
|
const severity = params[ 1 ];
|
|
|
|
const expect = params[ 2 ];
|
|
|
|
const box = newBox( className );
|
2018-07-10 20:06:51 +00:00
|
|
|
assert.strictEqual(
|
2018-08-16 19:00:38 +00:00
|
|
|
pageIssuesParser.iconName( box, severity ),
|
2018-07-10 20:06:51 +00:00
|
|
|
expect,
|
2018-07-11 15:16:21 +00:00
|
|
|
'Result should be the correct ResourceLoader icon name; case ' + i + ': ' + severity + '.'
|
2018-07-10 20:06:51 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-06-03 12:06:43 +00:00
|
|
|
QUnit.test( 'maxSeverity', ( assert ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const tests = [
|
2018-07-10 20:06:51 +00:00
|
|
|
[ [], 'DEFAULT' ],
|
|
|
|
[ [ 'DEFAULT' ], 'DEFAULT' ],
|
|
|
|
[ [ 'DEFAULT', 'LOW' ], 'LOW' ],
|
|
|
|
[ [ 'DEFAULT', 'LOW', 'MEDIUM' ], 'MEDIUM' ],
|
|
|
|
[ [ 'DEFAULT', 'LOW', 'MEDIUM', 'HIGH' ], 'HIGH' ],
|
|
|
|
[ [ 'HIGH', 'DEFAULT', 'LOW', 'MEDIUM' ], 'HIGH' ],
|
|
|
|
[ [ 'DEFAULT', 'HIGH', 'LOW', 'MEDIUM' ], 'HIGH' ]
|
|
|
|
];
|
2024-06-03 12:06:43 +00:00
|
|
|
tests.forEach( ( params, i ) => {
|
2024-03-24 20:53:43 +00:00
|
|
|
const severities = params[ 0 ];
|
|
|
|
const expect = params[ 1 ];
|
2018-07-11 15:16:21 +00:00
|
|
|
|
2018-07-10 20:06:51 +00:00
|
|
|
assert.strictEqual(
|
2018-08-16 19:00:38 +00:00
|
|
|
pageIssuesParser.maxSeverity( severities ),
|
2018-07-10 20:06:51 +00:00
|
|
|
expect,
|
2018-07-11 15:16:21 +00:00
|
|
|
'Result should be the highest severity in the array; case ' + i + '.'
|
2018-07-10 20:06:51 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2019-07-02 21:10:10 +00:00
|
|
|
}() );
|