* There's more than ok(), equal() and deepEqual(). Using the others as appropriate.
** Considered: strictEqual(a,b) tests the same as ok(a===b). But the latter doesn't include the values in the report when it fails. So strictEqual saves a lot of time in debugging (especially on TestSwarm where the report is all you have, there "not okay" or "Expected { foo: 500 }, Given: ['bar', '250']" is a big saver.
* Adding an "expect" to every test.
* Applying whitespace conventions and bringing consistency in the use of mw, mediaWiki, $, $j, jQuery. (except in the initial test where the aliases are being checked)
* Added cleanup for added CSSStyleSheet
* Making IPtest more complete (Based on IPTest.php)
window.mw.loader.testCallback = function(){
start();
- deepEqual( true, true, 'Implementing a module, is the callback timed properly ?');
+ ok( true, 'Implementing a module, is the callback timed properly ?');
};
module( 'jquery.autoEllipsis.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
expect(1);
- ok( jQuery.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
+ ok( $.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
});
function createWrappedDiv( text ) {
// Verify that, and only one, span element was created
var $span = $wrapper.find( '> span' );
- deepEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
+ strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
// Check that the text fits by turning on word wrapping
$span.css( 'whiteSpace', 'nowrap' );
- deepEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
+ strictEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" );
// Add one character using scary black magic
var spanText = $span.text();
// Put this text in the span and verify it doesn't fit
$span.text( spanText );
- deepEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
+ strictEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' );
// Clean up
$wrapper.remove();
module( 'jquery.client.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
expect(1);
ok( jQuery.client, 'jQuery.client defined' );
});
-test( 'profile', function(){
+test( 'profile', function() {
expect(7);
var p = $.client.profile();
- var unk = 'unknown';
- var unkOrType = function( val, type ) {
- return typeof val === type || val === unk;
+ var unknownOrType = function( val, type, summary ) {
+ return ok( typeof val === type || val === 'unknown', summary );
};
- equal( typeof p, 'object', 'profile() returns an object' );
- ok( unkOrType( p.layout, 'string' ), 'p.layout is a string (or "unknown")' );
- ok( unkOrType( p.layoutVersion, 'number' ), 'p.layoutVersion is a number (or "unknown")' );
- ok( unkOrType( p.platform, 'string' ), 'p.platform is a string (or "unknown")' );
- ok( unkOrType( p.version, 'string' ), 'p.version is a string (or "unknown")' );
- ok( unkOrType( p.versionBase, 'string' ), 'p.versionBase is a string (or "unknown")' );
+ equal( typeof p, 'object', 'profile returns an object' );
+ unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
+ unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
+ unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
+ unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
+ unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
});
-test( 'test', function(){
+test( 'test', function() {
expect(1);
// Example from WikiEditor
// then do a basic return value type check
var testMatch = $.client.test( testMap );
- equal( typeof testMatch, 'boolean', 'test() returns a boolean value' );
+ equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
});
module( 'jquery.colorUtil.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
expect(1);
- ok( jQuery.colorUtil, 'jQuery.colorUtil defined' );
+ ok( $.colorUtil, '$.colorUtil defined' );
});
-test( 'getRGB', function(){
+test( 'getRGB', function() {
expect(18);
- equal( typeof jQuery.colorUtil.getRGB(), 'undefined', 'No arguments' );
- equal( typeof jQuery.colorUtil.getRGB( '' ), 'undefined', 'Empty string' );
- deepEqual( jQuery.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Array' );
- deepEqual( jQuery.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple string' );
- deepEqual( jQuery.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple string (whitespace)' );
- deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse percentages string' );
- deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse percentages string (whitespace)' );
- deepEqual( jQuery.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
- deepEqual( jQuery.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
- deepEqual( jQuery.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
- deepEqual( jQuery.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
- deepEqual( jQuery.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
- deepEqual( jQuery.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
- deepEqual( jQuery.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
- // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep track
- // would that ever change
- equal( typeof jQuery.colorUtil.getRGB( 'rgba(0,0,0,0)' ), 'undefined', 'Zero rgba without whitespace' );
-
- deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
- deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
- equal( typeof jQuery.colorUtil.getRGB( 'mediaWiki' ), 'undefined', 'Inexisting color name' );
-
+ strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' );
+ strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' );
+ deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' );
+ deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' );
+ deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' );
+ deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' );
+ deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' );
+ deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
+ deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
+ deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
+ deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
+ deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
+ deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
+ deepEqual( $.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
+
+ // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep
+ // track of it, so we will know in case it would ever change.
+ strictEqual( $.colorUtil.getRGB( 'rgba(0,0,0,0)' ), undefined, 'Zero rgba without whitespace' );
+
+ deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
+ deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
+ strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
});
-test( 'rgbToHsl', function(){
- expect(4);
+test( 'rgbToHsl', function() {
+ expect(1);
+
+ var hsl = $.colorUtil.rgbToHsl( 144, 238, 144 );
- var hsl = jQuery.colorUtil.rgbToHsl( 144, 238, 144 );
+ // Cross-browser differences in decimals...
+ // Round to two decimals so they can be more reliably checked.
var dualDecimals = function(a,b){
return Math.round(a*100)/100;
};
+ // Re-create the rgbToHsl return array items, limited to two decimals.
+ var ret = [dualDecimals(hsl[0]), dualDecimals(hsl[1]), dualDecimals(hsl[2])];
- ok( hsl, 'Basic return evaluation' );
- deepEqual( dualDecimals(hsl[0]) , 0.33, 'rgb(144, 238, 144): H 0.33' );
- deepEqual( dualDecimals(hsl[1]) , 0.73, 'rgb(144, 238, 144): S 0.73' );
- deepEqual( dualDecimals(hsl[2]) , 0.75, 'rgb(144, 238, 144): L 0.75' );
-
+ deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' );
});
-test( 'hslToRgb', function(){
- expect(4);
+test( 'hslToRgb', function() {
+ expect(1);
- var rgb = jQuery.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
+ var rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
- ok( rgb, 'Basic return evaluation' );
- deepEqual( Math.round(rgb[0]) , 183, 'hsl(0.3, 0.7, 0.8): R 183' );
- deepEqual( Math.round(rgb[1]) , 240, 'hsl(0.3, 0.7, 0.8): G 240' );
- deepEqual( Math.round(rgb[2]) , 168, 'hsl(0.3, 0.7, 0.8): B 168' );
+ // Cross-browser differences in decimals...
+ // Re-create the hslToRgb return array items, rounded to whole numbers.
+ var ret = [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])];
+ deepEqual( ret ,[183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' );
});
-test( 'getColorBrightness', function(){
+test( 'getColorBrightness', function() {
expect(2);
- var a = jQuery.colorUtil.getColorBrightness( 'red', +0.1 );
-
- equal( a, 'rgb(255,50,50)', 'Start with named color, brighten 10%' );
-
- var b = jQuery.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
-
- equal( b, 'rgb(118,29,29)', 'Start with rgb string, darken 10%' );
+ var a = $.colorUtil.getColorBrightness( 'red', +0.1 );
+ equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' );
+ var b = $.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
+ equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' );
});
module( 'jquery.mwPrototypes.js' );
-test( 'String functions', function(){
+test( 'String functions', function() {
- equal( $j.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
- equal( $j.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
- equal( $j.ucFirst( 'foo'), 'Foo', 'ucFirst' );
+ equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
+ equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
+ equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
- equal( $j.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
+ equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
'<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
- equal( $j.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
+ equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
- equal( $j.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
+ equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
- equal( $j.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
-
+ equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
});
-test( 'Is functions', function(){
+test( 'Is functions', function() {
- deepEqual( $j.isDomElement( document.getElementById( 'qunit-header' ) ), true,
+ strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
'isDomElement: #qunit-header Node' );
- deepEqual( $j.isDomElement( document.getElementById( 'random-name' ) ), false,
+ strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
'isDomElement: #random-name (null)' );
- deepEqual( $j.isDomElement( document.getElementsByTagName( 'div' ) ), false,
+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
'isDomElement: getElementsByTagName Array' );
- deepEqual( $j.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
'isDomElement: getElementsByTagName(..)[0] Node' );
- deepEqual( $j.isDomElement( $j( 'div' ) ), false,
+ strictEqual( $.isDomElement( $( 'div' ) ), false,
'isDomElement: jQuery object' );
- deepEqual( $j.isDomElement( $j( 'div' ).get(0) ), true,
+ strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
'isDomElement: jQuery object > Get node' );
- deepEqual( $j.isDomElement( document.createElement( 'div' ) ), true,
+ strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
'isDomElement: createElement' );
- deepEqual( $j.isDomElement( { foo: 1 } ), false,
+ strictEqual( $.isDomElement( { foo: 1 } ), false,
'isDomElement: Object' );
- equal( $j.isEmpty( 'string' ), false, 'isEmptry: "string"' );
- equal( $j.isEmpty( '0' ), true, 'isEmptry: "0"' );
- equal( $j.isEmpty( [] ), true, 'isEmptry: []' );
- equal( $j.isEmpty( {} ), true, 'isEmptry: {}' );
- // Documented behaviour
- equal( $j.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
+ strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
+ strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
+ strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
+ strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
+ // Documented behaviour
+ strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
});
-test( 'Comparison functions', function(){
+test( 'Comparison functions', function() {
- ok( $j.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
+ ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
'compareArray: Two deep arrays that are excactly the same' );
- ok( !$j.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
+ ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
- ok( $j.compareObject( {}, {} ), 'compareObject: Two empty objects' );
- ok( $j.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
- ok( !$j.compareObject( { bar: true }, { baz: false } ),
+ ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
+ ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
+ ok( !$.compareObject( { bar: true }, { baz: false } ),
'compareObject: Two different objects (false)' );
-
-});
\ No newline at end of file
+});
module( 'jquery.tabIndex.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
expect(2);
ok( $.fn.firstTabIndex, '$.fn.firstTabIndex defined' );
ok( $.fn.lastTabIndex, '$.fn.lastTabIndex defined' );
-
});
-test( 'firstTabIndex', function(){
+test( 'firstTabIndex', function() {
expect(2);
- var testEnvironment =
+ var testEnvironment =
'<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
- var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
-
- deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
- var $testB = $( '<div />' );
+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
+ strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
- deepEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
+ var $testB = $( '<div>' );
+ strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
// Clean up
- $testA.add( $testB).remove();
+ $testA.add( $testB ).remove();
});
-test( 'lastTabIndex', function(){
+test( 'lastTabIndex', function() {
expect(2);
- var testEnvironment =
+ var testEnvironment =
'<form>' +
'<input tabindex="7" />' +
'<input tabindex="9" />' +
'<textarea tabindex="2">Foobar</textarea>' +
'<textarea tabindex="5">Foobar</textarea>' +
'</form>';
- var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' );
- deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
+ strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
- var $testB = $( '<div />' );
-
- deepEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
+ var $testB = $( '<div>' );
+ strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
// Clean up
- $testA.add( $testB).remove();
-});
\ No newline at end of file
+ $testA.add( $testB ).remove();
+});
module( 'mediawiki.util.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
+ expect(1);
ok( mw.util, 'mw.util defined' );
-
});
-test( 'rawurlencode', function(){
+test( 'rawurlencode', function() {
+ expect(1);
equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
-
});
-test( 'wikiUrlencode', function(){
+test( 'wikiUrlencode', function() {
+ expect(1);
equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
-
});
-test( 'wikiGetlink', function(){
+test( 'wikiGetlink', function() {
+ expect(2);
// Not part of startUp module
mw.config.set( 'wgArticlePath', '/wiki/$1' );
var hrefA = mw.util.wikiGetlink( 'Sandbox' );
-
equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
-
- equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
-
+ equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
+ 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
});
-test( 'wikiScript', function(){
+test( 'wikiScript', function() {
expect(2);
mw.config.set({
});
equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
- deepEqual( mw.util.wikiScript( 'api' ), '/w/api.php' );
+ equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
});
-test( 'addCSS', function(){
+test( 'addCSS', function() {
expect(3);
var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' );
- ok( a, 'function works' );
- deepEqual( a.disabled, false, 'property "disabled" is available and set to false' );
+ ok( a instanceof CSSStyleSheet, 'Object is an instance of CSSStyleSheet' );
+ strictEqual( a.disabled, false, 'property "disabled" is available and set to false' );
var $b = $('#bodyContent');
equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect' );
+ // Clean up
+ $( a.ownerNode ).remove();
});
-test( 'toggleToc', function(){
+test( 'toggleToc', function() {
expect(3);
- deepEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
+ strictEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' );
var tocHtml =
'<table id="toc" class="toc"><tr><td>' +
'<span class="toctoggle"> [<a href="#" class="internal" id="togglelink">Hide</a> ]</span>' +
'</div>' +
'<ul><li></li></ul>' +
- '</td></tr></table>';
+ '</td></tr></table>';
var $toc = $(tocHtml).appendTo( 'body' );
var $toggleLink = $( '#togglelink' );
// QUnit should not finish this test() untill they are all done
stop();
- var actionC = function(){
+ var actionC = function() {
start();
// Clean up
$toc.remove();
};
- var actionB = function(){
- deepEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
+ var actionB = function() {
+ strictEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' );
};
- var actionA = function(){
- deepEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
+ var actionA = function() {
+ strictEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' );
};
-
- actionA();
-
+ actionA();
});
-test( 'getParamValue', function(){
+test( 'getParamValue', function() {
+ expect(2);
var url = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
equal( mw.util.getParamValue( 'foo', url ), 'right', 'Use latest one, ignore hash' );
- deepEqual( mw.util.getParamValue( 'bar', url ), null, 'Return null when not found' );
-
+ strictEqual( mw.util.getParamValue( 'bar', url ), null, 'Return null when not found' );
});
-test( 'tooltipAccessKey', function(){
+test( 'tooltipAccessKey', function() {
+ expect(3);
equal( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' );
-
});
-test( '$content', function(){
+test( '$content', function() {
+ expect(2);
ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' );
- deepEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
-
+ strictEqual( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' );
});
-test( 'addPortletLink', function(){
+test( 'addPortletLink', function() {
+ expect(5);
var A = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/wiki/ResourceLoader',
'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l', '#t-specialpages' );
// Clean up
$( [A, B, C] ).remove();
-
});
-test( 'jsMessage', function(){
+test( 'jsMessage', function() {
+ expect(1);
var a = mw.util.jsMessage( "MediaWiki is <b>Awesome</b>." );
-
ok( a, 'Basic checking of return value' );
// Clean up
$( '#mw-js-message' ).remove();
-
});
-test( 'validateEmail', function(){
+test( 'validateEmail', function() {
expect(6);
- deepEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
- deepEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
+ strictEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' );
+ strictEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' );
// testEmailWithCommasAreInvalids
- deepEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
- deepEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
+ strictEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' );
+ strictEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' );
// testEmailWithHyphens
- deepEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
- deepEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
-
+ strictEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' );
+ strictEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' );
});
-test( 'isIPv6Address', function(){
- expect(6);
+test( 'isIPv6Address', function() {
+ expect(40);
+
+ // Shortcuts
+ var assertFalseIPv6 = function( addy, summary ) {
+ return strictEqual( mw.util.isIPv6Address( addy ), false, summary );
+ },
+ assertTrueIPv6 = function( addy, summary ) {
+ return strictEqual( mw.util.isIPv6Address( addy ), true, summary );
+ };
+
+ // Based on IPTest.php > testisIPv6
+ assertFalseIPv6( ':fc:100::', 'IPv6 starting with lone ":"' );
+ assertFalseIPv6( 'fc:100:::', 'IPv6 ending with a ":::"' );
+ assertFalseIPv6( 'fc:300', 'IPv6 with only 2 words' );
+ assertFalseIPv6( 'fc:100:300', 'IPv6 with only 3 words' );
+
+ $.each(
+ ['fc:100::',
+ 'fc:100:a::',
+ 'fc:100:a:d::',
+ 'fc:100:a:d:1::',
+ 'fc:100:a:d:1:e::',
+ 'fc:100:a:d:1:e:ac::'], function( i, addy ){
+ assertTrueIPv6( addy, addy + ' is a valid IP' );
+ });
- // Based on IPTest.php > IPv6
- deepEqual( mw.util.isIPv6Address( "" ), false, 'Empty string is not an IP' );
- deepEqual( mw.util.isIPv6Address( ":fc:100::" ), false, 'IPv6 starting with lone ":"' );
- deepEqual( mw.util.isIPv6Address( "fc:100::" ), true );
- deepEqual( mw.util.isIPv6Address( "fc:100:a:d:1:e:ac::" ), true );
- deepEqual( mw.util.isIPv6Address( ":::" ), false );
- deepEqual( mw.util.isIPv6Address( "::0:" ), false );
+ assertFalseIPv6( 'fc:100:a:d:1:e:ac:0::', 'IPv6 with 8 words ending with "::"' );
+ assertFalseIPv6( 'fc:100:a:d:1:e:ac:0:1::', 'IPv6 with 9 words ending with "::"' );
+
+ assertFalseIPv6( ':::' );
+ assertFalseIPv6( '::0:', 'IPv6 ending in a lone ":"' );
+
+ assertTrueIPv6( '::', 'IPv6 zero address' );
+ $.each(
+ ['::0',
+ '::fc',
+ '::fc:100',
+ '::fc:100:a',
+ '::fc:100:a:d',
+ '::fc:100:a:d:1',
+ '::fc:100:a:d:1:e',
+ '::fc:100:a:d:1:e:ac',
+
+ 'fc:100:a:d:1:e:ac:0'], function( i, addy ){
+ assertTrueIPv6( addy, addy + ' is a valid IP' );
+ });
+ assertFalseIPv6( '::fc:100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
+ assertFalseIPv6( '::fc:100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
+
+ assertFalseIPv6( ':fc::100', 'IPv6 starting with lone ":"' );
+ assertFalseIPv6( 'fc::100:', 'IPv6 ending with lone ":"' );
+ assertFalseIPv6( 'fc:::100', 'IPv6 with ":::" in the middle' );
+
+ assertTrueIPv6( 'fc::100', 'IPv6 with "::" and 2 words' );
+ assertTrueIPv6( 'fc::100:a', 'IPv6 with "::" and 3 words' );
+ assertTrueIPv6( 'fc::100:a:d', 'IPv6 with "::" and 4 words' );
+ assertTrueIPv6( 'fc::100:a:d:1', 'IPv6 with "::" and 5 words' );
+ assertTrueIPv6( 'fc::100:a:d:1:e', 'IPv6 with "::" and 6 words' );
+ assertTrueIPv6( 'fc::100:a:d:1:e:ac', 'IPv6 with "::" and 7 words' );
+ assertTrueIPv6( '2001::df', 'IPv6 with "::" and 2 words' );
+ assertTrueIPv6( '2001:5c0:1400:a::df', 'IPv6 with "::" and 5 words' );
+ assertTrueIPv6( '2001:5c0:1400:a::df:2', 'IPv6 with "::" and 6 words' );
+
+ assertFalseIPv6( 'fc::100:a:d:1:e:ac:0', 'IPv6 with "::" and 8 words' );
+ assertFalseIPv6( 'fc::100:a:d:1:e:ac:0:1', 'IPv6 with 9 words' );
});
-test( 'isIPv4Address', function(){
- expect(3);
-
- // Based on IPTest.php > IPv4
- deepEqual( mw.util.isIPv4Address( "" ), false, 'Empty string is not an IP' );
- deepEqual( mw.util.isIPv4Address( "...." ), false );
- deepEqual( mw.util.isIPv4Address( "1.24.52.13" ), true );
-
+test( 'isIPv4Address', function() {
+ expect(11);
+
+ // Shortcuts
+ var assertFalseIPv4 = function( addy, summary ) {
+ return strictEqual( mw.util.isIPv4Address( addy ), false, summary );
+ },
+ assertTrueIPv4 = function( addy, summary ) {
+ return strictEqual( mw.util.isIPv4Address( addy ), true, summary );
+ };
+
+ // Based on IPTest.php > testisIPv4
+ assertFalseIPv4( false, 'Boolean false is not an IP' );
+ assertFalseIPv4( true, 'Boolean true is not an IP' );
+ assertFalseIPv4( '', 'Empty string is not an IP' );
+ assertFalseIPv4( 'abc', '"abc" is not an IP' );
+ assertFalseIPv4( ':', 'Colon is not an IP' );
+ assertFalseIPv4( '124.24.52', 'IPv4 not enough quads' );
+ assertFalseIPv4( '24.324.52.13', 'IPv4 out of range' );
+ assertFalseIPv4( '.24.52.13', 'IPv4 starts with period' );
+
+ assertTrueIPv4( '124.24.52.13', '124.24.52.134 is a valid IP' );
+ assertTrueIPv4( '1.24.52.13', '1.24.52.13 is a valid IP' );
+ assertFalseIPv4( '74.24.52.13/20', 'IPv4 ranges are not recogzized as valid IPs' );
});
module( 'mediawiki.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
+ expect(8);
ok( window.jQuery, 'jQuery defined' );
+ ok( window.$, '$j defined' );
ok( window.$j, '$j defined' );
- equal( window.$j, window.jQuery, '$j alias to jQuery' );
+ strictEqual( window.$, window.jQuery, '$ alias to jQuery' );
+ strictEqual( window.$j, window.jQuery, '$j alias to jQuery' );
ok( window.mediaWiki, 'mediaWiki defined' );
ok( window.mw, 'mw defined' );
- equal( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
-
+ strictEqual( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
});
-test( 'mw.Map', function(){
- expect(20);
+test( 'mw.Map', function() {
+ expect(15);
ok( mw.Map, 'mw.Map defined' );
- ok( mw.Map.prototype.get, 'get prototype defined' );
- ok( mw.Map.prototype.set, 'set prototype defined' );
- ok( mw.Map.prototype.exists, 'exists prototype defined' );
-
- var conf = new mw.Map();
- var funky = function(){};
- var arry = [];
- var nummy = 7;
+ var conf = new mw.Map(),
+ funky = function() {},
+ arry = [],
+ nummy = 7;
- deepEqual( conf.get( 'inexistantKey' ), null, 'Map.get() returns null if selection was a string and the key was not found' );
- deepEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set() returns boolean true if a value was set for a valid key string' );
- deepEqual( conf.set( funky, 'Funky' ), false, 'Map.set() returns boolean false if key was invalid (Function)' );
- deepEqual( conf.set( arry, 'Arry' ), false, 'Map.set() returns boolean false if key was invalid (Array)' );
- deepEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set() returns boolean false if key was invalid (Number)' );
- equal( conf.get( 'myKey' ), 'myValue', 'Map.get() returns a single value value correctly' );
+ strictEqual( conf.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' );
+ strictEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' );
+ strictEqual( conf.set( funky, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
+ strictEqual( conf.set( arry, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
+ strictEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
+ equal( conf.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' );
var someValues = {
'foo': 'bar',
'lorem': 'ipsum',
'MediaWiki': true
};
- deepEqual( conf.set( someValues ), true, 'Map.set() returns boolean true if multiple values were set by passing an object' );
+ strictEqual( conf.set( someValues ), true, 'Map.set returns boolean true if multiple values were set by passing an object' );
deepEqual( conf.get( ['foo', 'lorem'] ), {
'foo': 'bar',
'lorem': 'ipsum'
- }, 'Map.get() returns multiple values correctly as an object' );
+ }, 'Map.get returns multiple values correctly as an object' );
deepEqual( conf.get( ['foo', 'notExist'] ), {
'foo': 'bar',
'notExist': null
- }, 'Map.get() return includes keys that were not found as null values' );
+ }, 'Map.get return includes keys that were not found as null values' );
- deepEqual( conf.exists( 'foo' ), true, 'Map.exists() returns boolean true if a key exists' );
- deepEqual( conf.exists( 'notExist' ), false, 'Map.exists() returns boolean false if a key does not exists' );
- deepEqual( conf.get() === conf.values, true, 'Map.get() returns the entire values object by reference (if called without arguments)' );
+ strictEqual( conf.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' );
+ strictEqual( conf.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' );
+ strictEqual( conf.get() === conf.values, true, 'Map.get returns the entire values object by reference (if called without arguments)' );
conf.set( 'globalMapChecker', 'Hi' );
- deepEqual( 'globalMapChecker' in window, false, 'new mw.Map() did not store its values in the global window object by default' );
- ok( !window.globalMapChecker, 'new mw.Map() did not store its values in the global window object by default' );
+ ok( false === 'globalMapChecker' in window, 'new mw.Map did not store its values in the global window object by default' );
var globalConf = new mw.Map( true );
globalConf.set( 'anotherGlobalMapChecker', 'Hello' );
- deepEqual( 'anotherGlobalMapChecker' in window, true, 'new mw.Map( true ) did store its values in the global window object' );
- ok( window.anotherGlobalMapChecker, 'new mw.Map( true ) did store its values in the global window object' );
+ ok( 'anotherGlobalMapChecker' in window, 'new mw.Map( true ) did store its values in the global window object' );
- // Whitelist this global variable for QUnit 'noglobal' mode
+ // Whitelist this global variable for QUnit's 'noglobal' mode
if ( QUnit.config.noglobals ) {
QUnit.config.pollution.push( 'anotherGlobalMapChecker' );
}
});
-test( 'mw.config', function(){
+test( 'mw.config', function() {
expect(1);
- deepEqual( mw.config instanceof mw.Map, true, 'mw.config instance of mw.Map' );
+ ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
});
-test( 'mw.messages / mw.message / mw.msg', function(){
- expect(18);
+test( 'mw.message & mw.messages', function() {
+ expect(16);
- ok( mw.message, 'mw.message defined' );
- ok( mw.msg, 'mw.msg defined' );
ok( mw.messages, 'messages defined' );
ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
var hello = mw.message( 'hello' );
equal( hello.format, 'parse', 'Message property "format" defaults to "parse"' );
- deepEqual( hello.map === mw.messages, true, 'Message property "map" defaults to the global instance in mw.messages' );
+ strictEqual( hello.map, mw.messages, 'Message property "map" defaults to the global instance in mw.messages' );
equal( hello.key, 'hello', 'Message property "key" (currect key)' );
deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' );
ok( hello.params, 'Message prototype "params"' );
hello.format = 'plain';
- equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString() returns the message as a string with the current "format"' );
+ equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' );
- equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped() returns the escaped message' );
- equal( hello.format, 'escaped', 'Message.escaped() correctly updated the "format" property' );
+ equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped returns the escaped message' );
+ equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' );
hello.parse();
- equal( hello.format, 'parse', 'Message.parse() correctly updated the "format" property' );
+ equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' );
hello.plain();
- equal( hello.format, 'plain', 'Message.plain() correctly updated the "format" property' );
+ equal( hello.format, 'plain', 'Message.plain correctly updated the "format" property' );
- deepEqual( hello.exists(), true, 'Message.exists() returns true for existing messages' );
+ strictEqual( hello.exists(), true, 'Message.exists returns true for existing messages' );
var goodbye = mw.message( 'goodbye' );
- deepEqual( goodbye.exists(), false, 'Message.exists() returns false for inexisting messages' );
+ strictEqual( goodbye.exists(), false, 'Message.exists returns false for inexisting messages' );
- equal( goodbye.toString(), '<goodbye>', 'Message.toString() returns <key> if key does not exist' );
+ equal( goodbye.toString(), '<goodbye>', 'Message.toString returns <key> if key does not exist' );
});
-test( 'mw.msg', function(){
+test( 'mw.msg', function() {
expect(2);
equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' );
});
-test( 'mw.loader', function(){
+test( 'mw.loader', function() {
expect(5);
// Regular expression to extract the path for the QUnit tests
);
// Asynchronous ahead
- stop();
+ stop(1500);
// Extract path
var tests_path = rePath.exec( location.href );
mw.loader.implement( 'is.awesome', [tests_path + 'sample/awesome.js'], {}, {} );
- mw.loader.using( 'is.awesome', function(){
+ mw.loader.using( 'is.awesome', function() {
- // awesome.js declares this function
+ // /sample/awesome.js declares the "mw.loader.testCallback" function
+ // which contains a call to start() and ok()
mw.loader.testCallback();
- }, function(){
+ }, function() {
start();
- deepEqual( true, false, 'Implementing a module, error callback fired!' );
+ ok( false, 'Error callback fired while implementing "is.awesome" module' );
});
});
test( 'mw.loader.bug29107' , function() {
- expect( 1 );
+ expect(2);
- // Async! Include a timeout, as failure on this bug lead to neither the
+ // Message doesn't exist already
+ ok( !mw.messages.exists( 'bug29107' ) );
+
+ // Async! Include a timeout, as failure in this test leads to neither the
// success nor failure callbacks getting called.
stop(1500);
mw.loader.implement( 'bug29107.messages-only', [], {}, {'bug29107': 'loaded'} );
mw.loader.using( 'bug29107.messages-only', function() {
start();
- ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should load ok' );
- }, function(){
+ ok( mw.messages.exists( 'bug29107' ), 'Bug 29107: messages-only module should implement ok' );
+ }, function() {
start();
- deepEqual( true, false, 'Implementing a module, error callback fired!' );
+ ok( false, 'Error callback fired while implementing "bug29107.messages-only" module' );
});
});
-test( 'mw.html', function(){
+test( 'mw.html', function() {
+ expect(7);
+
+ raises( function(){
+ mw.html.escape();
+ }, TypeError, 'html.escape throws a TypeError if argument given is not a string' );
equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
- '<mw awesome="awesome" value='test' />', 'html.escape()' );
+ '<mw awesome="awesome" value='test' />', 'html.escape escapes html snippet' );
+
+ equal( mw.html.element(),
+ '<undefined/>', 'html.element Always return a valid html string (even without arguments)' );
- equal( mw.html.element( 'div' ), '<div/>', 'mw.html.element() DIV (simple)' );
+ equal( mw.html.element( 'div' ), '<div/>', 'html.element DIV (simple)' );
equal( mw.html.element( 'div',
{ id: 'foobar' } ),
'<div id="foobar"/>',
- 'mw.html.element() DIV (attribs)' );
+ 'html.element DIV (attribs)' );
equal( mw.html.element( 'div',
null, 'a' ),
'<div>a</div>',
- 'mw.html.element() DIV (content)' );
+ 'html.element DIV (content)' );
equal( mw.html.element( 'a',
{ href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
'<a href="http://mediawiki.org/w/index.php?title=RL&action=history">a</a>',
- 'mw.html.element() DIV (attribs + content)' );
+ 'html.element DIV (attribs + content)' );
});
module( 'mediawiki.user.js' );
-test( '-- Initial check', function(){
+test( '-- Initial check', function() {
+ expect(1);
ok( mw.user, 'mw.user defined' );
-
});
-test( 'options', function(){
+test( 'options', function() {
+ expect(1);
ok( mw.user.options instanceof mw.Map, 'options instance of mw.Map' );
-
});
-test( 'User login status', function(){
+test( 'User login status', function() {
+ expect(5);
- deepEqual( mw.user.name(), null, 'user.name() When anonymous' );
- ok( mw.user.anonymous(), 'user.anonymous() When anonymous' );
+ strictEqual( mw.user.name(), null, 'user.name should return null when anonymous' );
+ ok( mw.user.anonymous(), 'user.anonymous should reutrn true when anonymous' );
// Not part of startUp module
mw.config.set( 'wgUserName', 'John' );
- equal( mw.user.name(), 'John', 'user.name() When logged-in as John' );
- ok( !mw.user.anonymous(), 'user.anonymous() When logged-in' );
-
- equal( mw.user.id(), 'John', 'user.id() When logged-in as John' );
+ equal( mw.user.name(), 'John', 'user.name returns username when logged-in' );
+ ok( !mw.user.anonymous(), 'user.anonymous returns false when logged-in' );
-
-});
\ No newline at end of file
+ equal( mw.user.id(), 'John', 'user.id Returns username when logged-in' );
+});