summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js')
-rw-r--r--tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js91
1 files changed, 71 insertions, 20 deletions
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
index 6fc0731c..9216f0af 100644
--- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -1,5 +1,13 @@
( function ( mw, $ ) {
- QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment() );
+ QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
+ setup: function () {
+ this.taPrefix = mw.util.tooltipAccessKeyPrefix;
+ mw.util.tooltipAccessKeyPrefix = 'ctrl-alt-';
+ },
+ teardown: function () {
+ mw.util.tooltipAccessKeyPrefix = this.taPrefix;
+ }
+ } ) );
QUnit.test( 'rawurlencode', 1, function ( assert ) {
assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
@@ -9,20 +17,24 @@
assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
} );
- QUnit.test( 'wikiGetlink', 3, function ( assert ) {
+ QUnit.test( 'getUrl', 4, function ( assert ) {
// Not part of startUp module
mw.config.set( 'wgArticlePath', '/wiki/$1' );
mw.config.set( 'wgPageName', 'Foobar' );
- var href = mw.util.wikiGetlink( 'Sandbox' );
+ var href = mw.util.getUrl( 'Sandbox' );
assert.equal( href, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
- href = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
+ href = mw.util.getUrl( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
assert.equal( href, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
- href = mw.util.wikiGetlink();
+ href = mw.util.getUrl();
assert.equal( href, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
+
+ href = mw.util.getUrl( 'Sandbox', { action: 'edit' } );
+ assert.equal( href, '/wiki/Sandbox?action=edit',
+ 'Simple title with query string; Get link for "Sandbox" with action=edit' );
} );
QUnit.test( 'wikiScript', 4, function ( assert ) {
@@ -76,13 +88,13 @@
assert.strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
- tocHtml = '<table id="toc" class="toc"><tr><td>' +
+ tocHtml = '<div id="toc" class="toc">' +
'<div id="toctitle">' +
'<h2>Contents</h2>' +
'<span class="toctoggle">&nbsp;[<a href="#" class="internal" id="togglelink">Hide</a>&nbsp;]</span>' +
'</div>' +
'<ul><li></li></ul>' +
- '</td></tr></table>';
+ '</div>';
$( tocHtml ).appendTo( '#qunit-fixture' );
$toggleLink = $( '#togglelink' );
@@ -108,10 +120,14 @@
assert.strictEqual( mw.util.getParamValue( 'TEST', url ), 'a b+c d', 'Bug 30441: getParamValue must understand "+" encoding of space (multiple spaces)' );
} );
- QUnit.test( 'tooltipAccessKey', 3, function ( assert ) {
- assert.equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
- assert.ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
- assert.ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' );
+ QUnit.test( 'tooltipAccessKey', 4, function ( assert ) {
+ assert.equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'tooltipAccessKeyPrefix must be a string' );
+ assert.equal( $.type( mw.util.tooltipAccessKeyRegexp ), 'regexp', 'tooltipAccessKeyRegexp is a regexp' );
+ assert.ok( mw.util.updateTooltipAccessKeys, 'updateTooltipAccessKeys is non-empty' );
+
+ 'Example [a]'.replace( mw.util.tooltipAccessKeyRegexp, function ( sub, m1, m2, m3, m4, m5, m6 ) {
+ assert.equal( m6, 'a', 'tooltipAccessKeyRegexp finds the accesskey hint' );
+ } );
} );
QUnit.test( '$content', 2, function ( assert ) {
@@ -125,17 +141,18 @@
* Previously, test elements where invisible to the selector since only
* one element can have a given id.
*/
- QUnit.test( 'addPortletLink', 8, function ( assert ) {
- var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo;
+ QUnit.test( 'addPortletLink', 13, function ( assert ) {
+ var pTestTb, pCustom, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo,
+ addedAfter, tbRLDMnonexistentid, tbRLDMemptyjquery;
pTestTb = '\
<div class="portlet" id="p-test-tb">\
- <h5>Toolbox</h5>\
+ <h3>Toolbox</h3>\
<ul class="body"></ul>\
</div>';
pCustom = '\
<div class="portlet" id="p-test-custom">\
- <h5>Views</h5>\
+ <h3>Views</h3>\
<ul class="body">\
<li id="c-foo"><a href="#">Foo</a></li>\
<li id="c-barmenu">\
@@ -147,14 +164,15 @@
</div>';
vectorTabs = '\
<div id="p-test-views" class="vectorTabs">\
- <h5>Views</h5>\
+ <h3>Views</h3>\
<ul></ul>\
</div>';
$( '#qunit-fixture' ).append( pTestTb, pCustom, vectorTabs );
tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
- 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' );
+ 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l'
+ );
assert.ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' );
@@ -162,14 +180,32 @@
'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL );
$tbMW = $( tbMW );
+ assert.propEqual(
+ $tbMW.getAttrs(),
+ {
+ id: 't-mworg'
+ },
+ 'Validate attributes of created element'
+ );
+
+ assert.propEqual(
+ $tbMW.find( 'a' ).getAttrs(),
+ {
+ href: '//mediawiki.org/',
+ title: 'Go to MediaWiki.org [ctrl-alt-m]',
+ accesskey: 'm'
+ },
+ 'Validate attributes of anchor tag in created element'
+ );
- assert.equal( $tbMW.attr( 'id' ), 't-mworg', 'Link has correct ID set' );
assert.equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' );
- assert.equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
+ assert.strictEqual( $tbMW.next()[0], tbRL, 'Link is in the correct position (by passing nextnode)' );
- cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux' );
+ cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux', null, 'Example [shift-x]', 'q' );
$cuQuux = $( cuQuux );
+ assert.equal( $cuQuux.find( 'a' ).attr( 'title' ), 'Example [ctrl-alt-q]', 'Existing accesskey is stripped and updated' );
+
assert.equal(
$( '#p-test-custom #c-barmenu ul li' ).length,
1,
@@ -185,6 +221,21 @@
assert.strictEqual( $tbMW.find( 'span' ).length, 0, 'No <span> element should be added for porlets without vectorTabs class.' );
assert.strictEqual( $( caFoo ).find( 'span' ).length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
+
+ addedAfter = mw.util.addPortletLink( 'p-test-tb', '#', 'After foo', 'post-foo', 'After foo', null, $( tbRL ) );
+ assert.strictEqual( $( addedAfter ).next()[0], tbRL, 'Link is in the correct position (by passing a jQuery object as nextnode)' );
+
+ // test case - nonexistent id as next node
+ tbRLDMnonexistentid = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM',
+ 'Default modules', 't-rldm-nonexistent', 'List of all default modules ', 'd', '#t-rl-nonexistent' );
+
+ assert.equal( tbRLDMnonexistentid, $( '#p-test-tb li:last' )[0], 'Nonexistent id as nextnode adds the portlet at end' );
+
+ // test case - empty jquery object as next node
+ tbRLDMemptyjquery = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM',
+ 'Default modules', 't-rldm-empty-jquery', 'List of all default modules ', 'd', $( '#t-rl-nonexistent' ) );
+
+ assert.equal( tbRLDMemptyjquery, $( '#p-test-tb li:last' )[0], 'Empty jquery as nextnode adds the portlet at end' );
} );
QUnit.test( 'jsMessage', 1, function ( assert ) {