mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-18 11:35:54 +00:00
5a65bd5200
* Declare variables inline, as per the current code conventions. * Use built-in assert.true() and assert.false() in a few places. * Use built-in QUnit.test.each() to remove need for ad-hoc loops and inline composing of assertion messages with common prefixes. This also creates clearer and more detailed test reports, and more granular ability to re-run specific test cases. * Remove unneeded use of `QUnit.newMwEnvironment()`. * Simplify restoring of mw.Uri by storing the original reference once outside the test, and then re-using that each time. * Use mw.config.set() for improved familiarity and rely on natural restoration instead of the extra 'config' key abstraction which is another thing to learn and understand. Change-Id: I796e034854203d2e0e78e510458f4b34603e9901
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
( function () {
|
|
var UriUtil = require( '../../../resources/skins.minerva.scripts/UriUtil.js' );
|
|
var mwUriOrg = mw.Uri;
|
|
|
|
QUnit.module( 'Minerva UriUtil', {
|
|
beforeEach: function () {
|
|
mw.Uri = mw.UriRelative( 'https://meta.wikimedia.org/w/index.php' );
|
|
},
|
|
afterEach: function () {
|
|
mw.Uri = mwUriOrg;
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '.isInternal()', function ( assert ) {
|
|
assert.true(
|
|
UriUtil.isInternal( new mw.Uri( '/relative' ) ),
|
|
'relative URLs are internal'
|
|
);
|
|
assert.true(
|
|
UriUtil.isInternal( new mw.Uri( 'http://meta.wikimedia.org/' ) ),
|
|
'matching hosts are internal'
|
|
);
|
|
assert.true(
|
|
UriUtil.isInternal( new mw.Uri( 'https:/meta.wikimedia.org/' ) ),
|
|
'protocol is irrelevant'
|
|
);
|
|
assert.true(
|
|
UriUtil.isInternal( new mw.Uri( 'https://meta.wikimedia.org/path' ) ),
|
|
'path is irrelevant'
|
|
);
|
|
assert.false(
|
|
UriUtil.isInternal( new mw.Uri( 'https://archive.org/' ) ),
|
|
'external links are not internal'
|
|
);
|
|
assert.false(
|
|
UriUtil.isInternal( new mw.Uri( 'https://www.meta.wikimedia.org/' ) ),
|
|
'differing subdomains are not internal'
|
|
);
|
|
} );
|
|
}() );
|