( function ( mw, $ ) {
QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
setup: function () {
- this.taPrefix = mw.util.tooltipAccessKeyPrefix;
- mw.util.tooltipAccessKeyPrefix = 'ctrl-alt-';
+ $.fn.updateTooltipAccessKeys.setTestMode( true );
},
teardown: function () {
- mw.util.tooltipAccessKeyPrefix = this.taPrefix;
+ $.fn.updateTooltipAccessKeys.setTestMode( false );
+ },
+ messages: {
+ // Used by accessKeyLabel in test for addPortletLink
+ 'brackets': '[$1]',
+ 'word-separator': ' '
}
} ) );
$( style.ownerNode ).remove();
} );
- QUnit.asyncTest( 'toggleToc', 4, function ( assert ) {
- var tocHtml, $toggleLink;
-
- function actionC() {
- QUnit.start();
- }
-
- function actionB() {
- assert.strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
- }
-
- function actionA() {
- assert.strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
- }
-
- assert.strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
-
- tocHtml = '<div id="toc" class="toc">' +
- '<div id="toctitle">' +
- '<h2>Contents</h2>' +
- '<span class="toctoggle"> [<a href="#" class="internal" id="togglelink">Hide</a> ]</span>' +
- '</div>' +
- '<ul><li></li></ul>' +
- '</div>';
- $( tocHtml ).appendTo( '#qunit-fixture' );
- $toggleLink = $( '#togglelink' );
-
- assert.strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
-
- actionA();
- } );
-
QUnit.test( 'getParamValue', 5, function ( assert ) {
var url;
} );
QUnit.test( 'tooltipAccessKey', 4, function ( assert ) {
+ this.suppressWarnings();
+
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' );
} );
+
+ this.restoreWarnings();
} );
QUnit.test( '$content', 2, function ( assert ) {
assert.ok( $.isDomElement( tbRL ), 'addPortletLink returns a valid DOM Element according to $.isDomElement' );
tbMW = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/',
- 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', tbRL );
+ 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org', 'm', tbRL );
$tbMW = $( tbMW );
assert.propEqual(
$tbMW.find( 'a' ).getAttrs(),
{
href: '//mediawiki.org/',
- title: 'Go to MediaWiki.org [ctrl-alt-m]',
+ title: 'Go to MediaWiki.org [test-m]',
accesskey: 'm'
},
'Validate attributes of anchor tag in created element'
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( $cuQuux.find( 'a' ).attr( 'title' ), 'Example [test-q]', 'Existing accesskey is stripped and updated' );
assert.equal(
$( '#p-test-custom #c-barmenu ul li' ).length,
} );
QUnit.test( 'jsMessage', 1, function ( assert ) {
+ this.suppressWarnings();
var a = mw.util.jsMessage( 'MediaWiki is <b>Awesome</b>.' );
+ this.restoreWarnings();
assert.ok( a, 'Basic checking of return value' );
// Clean up