summaryrefslogtreecommitdiff
path: root/tests/qunit/suites/resources/jquery
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qunit/suites/resources/jquery')
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js25
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.byteLength.test.js37
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js397
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.client.test.js64
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js69
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js40
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js14
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.highlightText.test.js25
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.localize.test.js84
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js62
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js25
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js309
-rw-r--r--tests/qunit/suites/resources/jquery/jquery.textSelection.test.js44
13 files changed, 675 insertions, 520 deletions
diff --git a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js
index 6e371384..0dee2ef0 100644
--- a/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js
@@ -1,9 +1,6 @@
-module( 'jquery.autoEllipsis', QUnit.newMwEnvironment() );
+( function ( mw, $ ) {
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' );
-});
+QUnit.module( 'jquery.autoEllipsis', QUnit.newMwEnvironment() );
function createWrappedDiv( text, width ) {
var $wrapper = $( '<div>' ).css( 'width', width );
@@ -14,15 +11,13 @@ function createWrappedDiv( text, width ) {
function findDivergenceIndex( a, b ) {
var i = 0;
- while ( i < a.length && i < b.length && a[i] == b[i] ) {
+ while ( i < a.length && i < b.length && a[i] === b[i] ) {
i++;
}
return i;
}
-test( 'Position right', function() {
- expect(4);
-
+QUnit.test( 'Position right', 4, function ( assert ) {
// We need this thing to be visible, so append it to the DOM
var origText = 'This is a really long random string and there is no way it fits in 100 pixels.';
var $wrapper = createWrappedDiv( origText, '100px' );
@@ -31,25 +26,27 @@ test( 'Position right', function() {
// Verify that, and only one, span element was created
var $span = $wrapper.find( '> span' );
- strictEqual( $span.length, 1, 'autoEllipsis wrapped the contents in a span element' );
+ assert.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' );
- ltOrEq( $span.width(), $span.parent().width(), "Text fits (making the span 'white-space:nowrap' does not make it wider than its parent)" );
+ assert.ltOrEq( $span.width(), $span.parent().width(), "Text fits (making the span 'white-space:nowrap' does not make it wider than its parent)" );
// Add two characters using scary black magic
var spanText = $span.text();
var d = findDivergenceIndex( origText, spanText );
var spanTextNew = spanText.substr( 0, d ) + origText[d] + origText[d] + '...';
- gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' );
+ assert.gt( spanTextNew.length, spanText.length, 'Verify that the new span-length is indeed greater' );
// Put this text in the span and verify it doesn't fit
$span.text( spanTextNew );
// In IE6 width works like min-width, allow IE6's width to be "equal to"
if ( $.browser.msie && Number( $.browser.version ) === 6 ) {
- gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' );
+ assert.gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' );
} else {
- gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' );
+ assert.gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' );
}
});
+
+}( mediaWiki, jQuery ) );
diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js b/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js
index 15fac691..a6ddfca6 100644
--- a/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.byteLength.test.js
@@ -1,32 +1,23 @@
-module( 'jquery.byteLength', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.byteLength, 'jQuery.byteLength defined' );
-} );
-
-test( 'Simple text', function() {
- expect(5);
+QUnit.module( 'jquery.byteLength', QUnit.newMwEnvironment() );
+QUnit.test( 'Simple text', 5, function ( assert ) {
var azLc = 'abcdefghijklmnopqrstuvwxyz',
azUc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
num = '0123456789',
x = '*',
space = ' ';
- equal( $.byteLength( azLc ), 26, 'Lowercase a-z' );
- equal( $.byteLength( azUc ), 26, 'Uppercase A-Z' );
- equal( $.byteLength( num ), 10, 'Numbers 0-9' );
- equal( $.byteLength( x ), 1, 'An asterisk' );
- equal( $.byteLength( space ), 3, '3 spaces' );
+ assert.equal( $.byteLength( azLc ), 26, 'Lowercase a-z' );
+ assert.equal( $.byteLength( azUc ), 26, 'Uppercase A-Z' );
+ assert.equal( $.byteLength( num ), 10, 'Numbers 0-9' );
+ assert.equal( $.byteLength( x ), 1, 'An asterisk' );
+ assert.equal( $.byteLength( space ), 3, '3 spaces' );
} );
-test( 'Special text', window.foo = function() {
- expect(5);
-
+QUnit.test( 'Special text', 5, function ( assert ) {
// http://en.wikipedia.org/wiki/UTF-8
- var U_0024 = '\u0024',
+ var U_0024 = '$',
U_00A2 = '\u00A2',
U_20AC = '\u20AC',
U_024B62 = '\u024B62',
@@ -34,9 +25,9 @@ test( 'Special text', window.foo = function() {
// according to http://www.fileformat.info/info/unicode/char/24B62/index.htm
U_024B62_alt = '\uD852\uDF62';
- strictEqual( $.byteLength( U_0024 ), 1, 'U+0024: 1 byte. \u0024 (dollar sign)' );
- strictEqual( $.byteLength( U_00A2 ), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' );
- strictEqual( $.byteLength( U_20AC ), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' );
- strictEqual( $.byteLength( U_024B62 ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' );
- strictEqual( $.byteLength( U_024B62_alt ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' );
+ assert.strictEqual( $.byteLength( U_0024 ), 1, 'U+0024: 1 byte. $ (dollar sign)' );
+ assert.strictEqual( $.byteLength( U_00A2 ), 2, 'U+00A2: 2 bytes. \u00A2 (cent sign)' );
+ assert.strictEqual( $.byteLength( U_20AC ), 3, 'U+20AC: 3 bytes. \u20AC (euro sign)' );
+ assert.strictEqual( $.byteLength( U_024B62 ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character)' );
+ assert.strictEqual( $.byteLength( U_024B62_alt ), 4, 'U+024B62: 4 bytes. \uD852\uDF62 (a Han character) - alternative method' );
} );
diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
index 3346c2d5..4f86eb96 100644
--- a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
@@ -1,187 +1,234 @@
-( function () {
-
-module( 'jquery.byteLimit', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.byteLimit, 'jQuery.fn.byteLimit defined' );
-} );
-
-// Basic sendkey-implementation
-$.addChars = function( $input, charstr ) {
- var len = charstr.length;
- for ( var i = 0; i < len; i++ ) {
- // Keep track of the previous value
- var prevVal = $input.val();
-
- // Get the key code
- var code = charstr.charCodeAt(i);
-
- // Trigger event and undo if prevented
- var event = new jQuery.Event( 'keypress', { keyCode: code, which: code, charCode: code } );
- $input.trigger( event );
- if ( !event.isDefaultPrevented() ) {
- $input.val( prevVal + charstr.charAt(i) );
- }
- }
-};
-
-/**
- * Test factory for $.fn.byteLimit
- *
- * @param $input {jQuery} jQuery object in an input element
- * @param hasLimit {Boolean} Wether a limit should apply at all
- * @param limit {Number} Limit (if used) otherwise undefined
- * The limit should be less than 20 (the sample data's length)
- */
-var byteLimitTest = function( options ) {
- var opt = $.extend({
- description: '',
- $input: null,
- sample: '',
- hasLimit: false,
- expected: '',
- limit: null
- }, options);
-
- test( opt.description, function() {
-
- opt.$input.appendTo( '#qunit-fixture' );
-
- // Simulate pressing keys for each of the sample characters
- $.addChars( opt.$input, opt.sample );
- var rawVal = opt.$input.val(),
- fn = opt.$input.data( 'byteLimit-callback' ),
- newVal = $.isFunction( fn ) ? fn( rawVal ) : rawVal;
-
- if ( opt.hasLimit ) {
- expect(3);
-
- ltOrEq( $.byteLength( newVal ), opt.limit, 'Prevent keypresses after byteLimit was reached, length never exceeded the limit' );
- equal( $.byteLength( rawVal ), $.byteLength( opt.expected ), 'Not preventing keypresses too early, length has reached the expected length' );
- equal( rawVal, opt.expected, 'New value matches the expected string' );
+( function ( $, mw ) {
+ var simpleSample, U_20AC, mbSample;
- } else {
- expect(2);
- equal( newVal, opt.expected, 'New value matches the expected string' );
- equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' );
- }
- } );
-};
+ QUnit.module( 'jquery.byteLimit', QUnit.newMwEnvironment() );
-var
// Simple sample (20 chars, 20 bytes)
- simpleSample = '12345678901234567890',
+ simpleSample = '12345678901234567890';
// 3 bytes (euro-symbol)
- U_20AC = '\u20AC',
+ U_20AC = '\u20AC';
// Multi-byte sample (22 chars, 26 bytes)
mbSample = '1234567890' + U_20AC + '1234567890' + U_20AC;
-byteLimitTest({
- description: 'Plain text input',
- $input: $( '<input>' )
- .attr( 'type', 'text' ),
- sample: simpleSample,
- hasLimit: false,
- expected: simpleSample
-});
-
-byteLimitTest({
- description: 'Limit using the maxlength attribute',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .prop( 'maxLength', '10' )
- .byteLimit(),
- sample: simpleSample,
- hasLimit: true,
- limit: 10,
- expected: '1234567890'
-});
-
-byteLimitTest({
- description: 'Limit using a custom value',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .byteLimit( 10 ),
- sample: simpleSample,
- hasLimit: true,
- limit: 10,
- expected: '1234567890'
-});
-
-byteLimitTest({
- description: 'Limit using a custom value, overriding maxlength attribute',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .prop( 'maxLength', '10' )
- .byteLimit( 15 ),
- sample: simpleSample,
- hasLimit: true,
- limit: 15,
- expected: '123456789012345'
-});
-
-byteLimitTest({
- description: 'Limit using a custom value (multibyte)',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .byteLimit( 14 ),
- sample: mbSample,
- hasLimit: true,
- limit: 14,
- expected: '1234567890' + U_20AC + '1'
-});
-
-byteLimitTest({
- description: 'Limit using a custom value (multibyte) overlapping a byte',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .byteLimit( 12 ),
- sample: mbSample,
- hasLimit: true,
- limit: 12,
- expected: '1234567890' + '12'
-});
-
-byteLimitTest({
- description: 'Pass the limit and a callback as input filter',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .byteLimit( 6, function( val ) {
- // Invalid title
- if ( val == '' ) {
- return '';
- }
+ // Basic sendkey-implementation
+ function addChars( $input, charstr ) {
+ var c, len;
+ for ( c = 0, len = charstr.length; c < len; c += 1 ) {
+ $input
+ .val( function ( i, val ) {
+ // Add character to the value
+ return val + charstr.charAt( c );
+ } )
+ .trigger( 'change' );
+ }
+ }
- // Return without namespace prefix
- return new mw.Title( '' + val ).getMain();
- } ),
- sample: 'User:Sample',
- hasLimit: true,
- limit: 6, // 'Sample' length
- expected: 'User:Sample'
-});
-
-byteLimitTest({
- description: 'Limit using the maxlength attribute and pass a callback as input filter',
- $input: $( '<input>' )
- .attr( 'type', 'text' )
- .prop( 'maxLength', '6' )
- .byteLimit( function( val ) {
- // Invalid title
- if ( val === '' ) {
- return '';
+ /**
+ * Test factory for $.fn.byteLimit
+ *
+ * @param $input {jQuery} jQuery object in an input element
+ * @param hasLimit {Boolean} Wether a limit should apply at all
+ * @param limit {Number} Limit (if used) otherwise undefined
+ * The limit should be less than 20 (the sample data's length)
+ */
+ function byteLimitTest( options ) {
+ var opt = $.extend({
+ description: '',
+ $input: null,
+ sample: '',
+ hasLimit: false,
+ expected: '',
+ limit: null
+ }, options);
+
+ QUnit.asyncTest( opt.description, opt.hasLimit ? 3 : 2, function ( assert ) {
+ setTimeout( function () {
+ var rawVal, fn, effectiveVal;
+
+ opt.$input.appendTo( '#qunit-fixture' );
+
+ // Simulate pressing keys for each of the sample characters
+ addChars( opt.$input, opt.sample );
+
+ rawVal = opt.$input.val();
+ fn = opt.$input.data( 'byteLimit.callback' );
+ effectiveVal = fn ? fn( rawVal ) : rawVal;
+
+ if ( opt.hasLimit ) {
+ assert.ltOrEq(
+ $.byteLength( effectiveVal ),
+ opt.limit,
+ 'Prevent keypresses after byteLimit was reached, length never exceeded the limit'
+ );
+ assert.equal(
+ $.byteLength( rawVal ),
+ $.byteLength( opt.expected ),
+ 'Not preventing keypresses too early, length has reached the expected length'
+ );
+ assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
+
+ } else {
+ assert.equal(
+ $.byteLength( effectiveVal ),
+ $.byteLength( opt.expected ),
+ 'Unlimited scenarios are not affected, expected length reached'
+ );
+ assert.equal( rawVal, opt.expected, 'New value matches the expected string' );
}
+ QUnit.start();
+ }, 10 );
+ } );
+ }
- // Return without namespace prefix
- return new mw.Title( '' + val ).getMain();
- } ),
- sample: 'User:Sample',
- hasLimit: true,
- limit: 6, // 'Sample' length
- expected: 'User:Sample'
-});
-
-}() ); \ No newline at end of file
+ byteLimitTest({
+ description: 'Plain text input',
+ $input: $( '<input type="text"/>' ),
+ sample: simpleSample,
+ hasLimit: false,
+ expected: simpleSample
+ });
+
+ byteLimitTest({
+ description: 'Plain text input. Calling byteLimit with no parameters and no maxlength attribute (bug 36310)',
+ $input: $( '<input type="text"/>' )
+ .byteLimit(),
+ sample: simpleSample,
+ hasLimit: false,
+ expected: simpleSample
+ });
+
+ byteLimitTest({
+ description: 'Limit using the maxlength attribute',
+ $input: $( '<input type="text"/>' )
+ .attr( 'maxlength', '10' )
+ .byteLimit(),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 10,
+ expected: '1234567890'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value',
+ $input: $( '<input type="text"/>' )
+ .byteLimit( 10 ),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 10,
+ expected: '1234567890'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value, overriding maxlength attribute',
+ $input: $( '<input type="text"/>' )
+ .attr( 'maxlength', '10' )
+ .byteLimit( 15 ),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 15,
+ expected: '123456789012345'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value (multibyte)',
+ $input: $( '<input type="text"/>' )
+ .byteLimit( 14 ),
+ sample: mbSample,
+ hasLimit: true,
+ limit: 14,
+ expected: '1234567890' + U_20AC + '1'
+ });
+
+ byteLimitTest({
+ description: 'Limit using a custom value (multibyte) overlapping a byte',
+ $input: $( '<input type="text"/>' )
+ .byteLimit( 12 ),
+ sample: mbSample,
+ hasLimit: true,
+ limit: 12,
+ expected: '1234567890' + '12'
+ });
+
+ byteLimitTest({
+ description: 'Pass the limit and a callback as input filter',
+ $input: $( '<input type="text"/>' )
+ .byteLimit( 6, function ( val ) {
+ // Invalid title
+ if ( val === '' ) {
+ return '';
+ }
+
+ // Return without namespace prefix
+ return new mw.Title( String( val ) ).getMain();
+ } ),
+ sample: 'User:Sample',
+ hasLimit: true,
+ limit: 6, // 'Sample' length
+ expected: 'User:Sample'
+ });
+
+ byteLimitTest({
+ description: 'Limit using the maxlength attribute and pass a callback as input filter',
+ $input: $( '<input type="text"/>' )
+ .attr( 'maxlength', '6' )
+ .byteLimit( function ( val ) {
+ // Invalid title
+ if ( val === '' ) {
+ return '';
+ }
+
+ // Return without namespace prefix
+ return new mw.Title( String( val ) ).getMain();
+ } ),
+ sample: 'User:Sample',
+ hasLimit: true,
+ limit: 6, // 'Sample' length
+ expected: 'User:Sample'
+ });
+
+ QUnit.test( 'Confirm properties and attributes set', 4, function ( assert ) {
+ var $el, $elA, $elB;
+
+ $el = $( '<input type="text"/>' )
+ .attr( 'maxlength', '7' )
+ .appendTo( '#qunit-fixture' )
+ .byteLimit();
+
+ assert.strictEqual( $el.attr( 'maxlength' ), '7', 'maxlength attribute unchanged for simple limit' );
+
+ $el = $( '<input type="text"/>' )
+ .attr( 'maxlength', '7' )
+ .appendTo( '#qunit-fixture' )
+ .byteLimit( 12 );
+
+ assert.strictEqual( $el.attr( 'maxlength' ), '12', 'maxlength attribute updated for custom limit' );
+
+ $el = $( '<input type="text"/>' )
+ .attr( 'maxlength', '7' )
+ .appendTo( '#qunit-fixture' )
+ .byteLimit( 12, function ( val ) {
+ return val;
+ } );
+
+ assert.strictEqual( $el.attr( 'maxlength' ), undefined, 'maxlength attribute removed for limit with callback' );
+
+ $elA = $( '<input type="text"/>' )
+ .addClass( 'mw-test-byteLimit-foo' )
+ .attr( 'maxlength', '7' )
+ .appendTo( '#qunit-fixture' );
+
+ $elB = $( '<input type="text"/>' )
+ .addClass( 'mw-test-byteLimit-foo' )
+ .attr( 'maxlength', '12' )
+ .appendTo( '#qunit-fixture' );
+
+ $el = $( '.mw-test-byteLimit-foo' );
+
+ assert.strictEqual( $el.length, 2, 'Verify that there are no other elements clashing with this test suite' );
+
+ $el.byteLimit();
+ });
+
+}( jQuery, mediaWiki ) );
diff --git a/tests/qunit/suites/resources/jquery/jquery.client.test.js b/tests/qunit/suites/resources/jquery/jquery.client.test.js
index 7be41971..bf62b39a 100644
--- a/tests/qunit/suites/resources/jquery/jquery.client.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.client.test.js
@@ -1,14 +1,9 @@
-module( 'jquery.client', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( jQuery.client, 'jQuery.client defined' );
-});
+QUnit.module( 'jquery.client', QUnit.newMwEnvironment() );
/** Number of user-agent defined */
var uacount = 0;
-var uas = (function() {
+var uas = (function () {
// Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
// Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
@@ -205,42 +200,59 @@ var uas = (function() {
ltr: true,
rtl: true
}
+ },
+ // Bug #34924
+ 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
+ title: 'Rekonq',
+ platform: 'Linux i686',
+ profile: {
+ "name": "rekonq",
+ "layout": "webkit",
+ "layoutVersion": 534,
+ "platform": "linux",
+ "version": "534.34",
+ "versionBase": "534",
+ "versionNumber": 534.34
+ },
+ wikiEditor: {
+ ltr: true,
+ rtl: true
+ }
}
};
- $.each( uas, function() { uacount++ });
+ $.each( uas, function () {
+ uacount++;
+ });
return uas;
-})();
-
-test( 'profile userAgent support', function() {
- expect(uacount);
+}());
+QUnit.test( 'profile userAgent support', uacount, function ( assert ) {
// Generate a client profile object and compare recursively
var uaTest = function( rawUserAgent, data ) {
var ret = $.client.profile( {
userAgent: rawUserAgent,
platform: data.platform
} );
- deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
+ assert.deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
};
// Loop through and run tests
$.each( uas, uaTest );
} );
-test( 'profile return validation for current user agent', function() {
- expect(7);
+QUnit.test( 'profile return validation for current user agent', 7, function ( assert ) {
var p = $.client.profile();
- var unknownOrType = function( val, type, summary ) {
- return ok( typeof val === type || val === 'unknown', summary );
- };
+ function unknownOrType( val, type, summary ) {
+ assert.ok( typeof val === type || val === 'unknown', summary );
+ }
- equal( typeof p, 'object', 'profile returns an object' );
+ assert.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' );
+ assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
});
// Example from WikiEditor
@@ -271,20 +283,16 @@ var testMap = {
}
};
-test( 'test', function() {
- expect(1);
-
+QUnit.test( 'test', 1, function ( assert ) {
// .test() uses eval, make sure no exceptions are thrown
// then do a basic return value type check
var testMatch = $.client.test( testMap );
- equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
+ assert.equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
});
-test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
- expect( uacount * 2 ); // double since we test both LTR and RTL
-
+QUnit.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount * 2, function ( assert ) {
var $body = $( 'body' ),
bodyClasses = $body.attr( 'class' );
@@ -299,7 +307,7 @@ test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
var testMatch = $.client.test( testMap, profile );
$body.removeClass( dir );
- equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
+ assert.equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
});
});
diff --git a/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js b/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js
index 655ee564..7b37f5a0 100644
--- a/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js
@@ -1,40 +1,31 @@
-module( 'jquery.colorUtil', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.colorUtil, '$.colorUtil defined' );
-});
-
-test( 'getRGB', function() {
- expect(18);
-
- 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)' );
+QUnit.module( 'jquery.colorUtil', QUnit.newMwEnvironment() );
+
+QUnit.test( 'getRGB', 18, function ( assert ) {
+ assert.strictEqual( $.colorUtil.getRGB(), undefined, 'No arguments' );
+ assert.strictEqual( $.colorUtil.getRGB( '' ), undefined, 'Empty string' );
+ assert.deepEqual( $.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Parse array of rgb values' );
+ assert.deepEqual( $.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple rgb string' );
+ assert.deepEqual( $.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple rgb string with spaces' );
+ assert.deepEqual( $.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse rgb string with percentages' );
+ assert.deepEqual( $.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse rgb string with percentages and spaces' );
+ assert.deepEqual( $.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
+ assert.deepEqual( $.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
+ assert.deepEqual( $.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
+ assert.deepEqual( $.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
+ assert.deepEqual( $.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
+ assert.deepEqual( $.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
+ assert.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' );
+ assert.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( 'transparent' ), [255, 255, 255], 'Color names (transparent)' );
- strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
+ assert.deepEqual( $.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
+ assert.deepEqual( $.colorUtil.getRGB( 'transparent' ), [255, 255, 255], 'Color names (transparent)' );
+ assert.strictEqual( $.colorUtil.getRGB( 'mediaWiki' ), undefined, 'Inexisting color name' );
});
-test( 'rgbToHsl', function() {
- expect(1);
-
+QUnit.test( 'rgbToHsl', 1, function ( assert ) {
var hsl = $.colorUtil.rgbToHsl( 144, 238, 144 );
// Cross-browser differences in decimals...
@@ -45,27 +36,23 @@ test( 'rgbToHsl', function() {
// Re-create the rgbToHsl return array items, limited to two decimals.
var ret = [dualDecimals(hsl[0]), dualDecimals(hsl[1]), dualDecimals(hsl[2])];
- deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' );
+ assert.deepEqual( ret, [0.33, 0.73, 0.75], 'rgb(144, 238, 144): hsl(0.33, 0.73, 0.75)' );
});
-test( 'hslToRgb', function() {
- expect(1);
-
+QUnit.test( 'hslToRgb', 1, function ( assert ) {
var rgb = $.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
// 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)' );
+ assert.deepEqual( ret ,[183, 240, 168], 'hsl(0.3, 0.7, 0.8): rgb(183, 240, 168)' );
});
-test( 'getColorBrightness', function() {
- expect(2);
-
+QUnit.test( 'getColorBrightness', 2, function ( assert ) {
var a = $.colorUtil.getColorBrightness( 'red', +0.1 );
- equal( a, 'rgb(255,50,50)', 'Start with named color "red", brighten 10%' );
+ assert.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%' );
+ assert.equal( b, 'rgb(118,29,29)', 'Start with rgb string "rgb(200,50,50)", darken 20%' );
});
diff --git a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
index 6489a1f1..a3079835 100644
--- a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
@@ -1,41 +1,35 @@
-test('jquery.delayedBind with data option', function() {
+QUnit.asyncTest('jquery.delayedBind with data option', 2, function ( assert ) {
var $fixture = $('<div>').appendTo('#qunit-fixture'),
data = { magic: "beeswax" },
delay = 50;
- $fixture.delayedBind(delay, 'testevent', data, function(event) {
- start(); // continue!
- ok(true, 'testevent fired');
- ok(event.data === data, 'data is passed through delayedBind');
+ $fixture.delayedBind(delay, 'testevent', data, function ( e ) {
+ QUnit.start(); // continue!
+ assert.ok( true, 'testevent fired');
+ assert.ok( e.data === data, 'data is passed through delayedBind');
});
- expect(2);
- stop(); // async!
-
// We'll trigger it thrice, but it should only happen once.
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
});
-test('jquery.delayedBind without data option', function() {
+QUnit.asyncTest('jquery.delayedBind without data option', 1, function ( assert ) {
var $fixture = $('<div>').appendTo('#qunit-fixture'),
data = { magic: "beeswax" },
delay = 50;
- $fixture.delayedBind(delay, 'testevent', function(event) {
- start(); // continue!
- ok(true, 'testevent fired');
+ $fixture.delayedBind(delay, 'testevent', function ( e ) {
+ QUnit.start(); // continue!
+ assert.ok(true, 'testevent fired');
});
- expect(1);
- stop(); // async!
-
// We'll trigger it thrice, but it should only happen once.
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
- $fixture.trigger('testevent', {});
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
+ $fixture.trigger( 'testevent', {} );
});
diff --git a/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js b/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js
index 9377a2f6..6eef1abb 100644
--- a/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js
@@ -1,17 +1,11 @@
-module( 'jquery.getAttrs', QUnit.newMwEnvironment() );
+QUnit.module( 'jquery.getAttrs', QUnit.newMwEnvironment() );
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.getAttrs, 'jQuery.fn.getAttrs defined' );
-} );
-
-test( 'Check', function() {
- expect(1);
+QUnit.test( 'Check', 1, function ( assert ) {
var attrs = {
foo: 'bar',
'class': 'lorem'
},
- $el = $( '<div>', attrs );
+ $el = jQuery( '<div>', attrs );
- deepEqual( $el.getAttrs(), attrs, 'getAttrs() return object should match the attributes set, no more, no less' );
+ assert.deepEqual( $el.getAttrs(), attrs, 'getAttrs() return object should match the attributes set, no more, no less' );
} );
diff --git a/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
index 4750d2b8..a94dca31 100644
--- a/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.highlightText.test.js
@@ -1,12 +1,7 @@
-module( 'jquery.highlightText', QUnit.newMwEnvironment() );
+QUnit.module( 'jquery.highlightText', QUnit.newMwEnvironment() );
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.highlightText, 'jQuery.fn.highlightText defined' );
-} );
-
-test( 'Check', function() {
- var cases = [
+QUnit.test( 'Check', function ( assert ) {
+ var $fixture, cases = [
{
desc: 'Test 001',
text: 'Blue Öyster Cult',
@@ -224,16 +219,14 @@ test( 'Check', function() {
expected: '<span class="highlight">بو</span>ل إيردوس'
}
];
- expect(cases.length);
- var $fixture;
+ QUnit.expect( cases.length );
- $.each(cases, function( i, item ) {
- $fixture = $( '<p></p>' ).text( item.text );
- $fixture.highlightText( item.highlight );
- equals(
+ $.each( cases, function ( i, item ) {
+ $fixture = $( '<p>' ).text( item.text ).highlightText( item.highlight );
+ assert.equal(
$fixture.html(),
- $('<p>' + item.expected + '</p>').html(), // re-parse to normalize!
+ $( '<p>' ).html( item.expected ).html(), // re-parse to normalize!
item.desc || undefined
- );
+ );
} );
} );
diff --git a/tests/qunit/suites/resources/jquery/jquery.localize.test.js b/tests/qunit/suites/resources/jquery/jquery.localize.test.js
index cd828634..c8e1d9f9 100644
--- a/tests/qunit/suites/resources/jquery/jquery.localize.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.localize.test.js
@@ -1,13 +1,6 @@
-module( 'jquery.localize', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.localize, 'jQuery.fn.localize defined' );
-} );
-
-test( 'Handle basic replacements', function() {
- expect(3);
+QUnit.module( 'jquery.localize', QUnit.newMwEnvironment() );
+QUnit.test( 'Handle basic replacements', 4, function ( assert ) {
var html, $lc;
mw.messages.set( 'basic', 'Basic stuff' );
@@ -15,24 +8,28 @@ test( 'Handle basic replacements', function() {
html = '<div><span><html:msg key="basic" /></span></div>';
$lc = $( html ).localize().find( 'span' );
- strictEqual( $lc.text(), 'Basic stuff', 'Tag: html:msg' );
+ assert.strictEqual( $lc.text(), 'Basic stuff', 'Tag: html:msg' );
// Attribute: title-msg
- html = '<div><span title-msg="basic" /></span></div>';
+ html = '<div><span title-msg="basic"></span></div>';
$lc = $( html ).localize().find( 'span' );
- strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' );
+ assert.strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' );
// Attribute: alt-msg
- html = '<div><span alt-msg="basic" /></span></div>';
+ html = '<div><span alt-msg="basic"></span></div>';
$lc = $( html ).localize().find( 'span' );
- strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' );
-} );
+ assert.strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' );
-test( 'Proper escaping', function() {
- expect(2);
+ // Attribute: placeholder-msg
+ html = '<div><input placeholder-msg="basic" /></div>';
+ $lc = $( html ).localize().find( 'input' );
+ assert.strictEqual( $lc.attr( 'placeholder' ), 'Basic stuff', 'Attribute: placeholder-msg' );
+} );
+
+QUnit.test( 'Proper escaping', 2, function ( assert ) {
var html, $lc;
mw.messages.set( 'properfoo', '<proper esc="test">' );
@@ -40,21 +37,19 @@ test( 'Proper escaping', function() {
// making sure it is actually using text() and attr() (or something with the same effect)
// Text escaping
- html = '<div><span><html:msg key="properfoo" /></span></div>';
+ html = '<div><span><html:msg key="properfoo"></span></div>';
$lc = $( html ).localize().find( 'span' );
- strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' );
+ assert.strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' );
// Attribute escaping
- html = '<div><span title-msg="properfoo" /></span></div>';
+ html = '<div><span title-msg="properfoo"></span></div>';
$lc = $( html ).localize().find( 'span' );
- strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' );
+ assert.strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' );
} );
-test( 'Options', function() {
- expect(7);
-
+QUnit.test( 'Options', 7, function ( assert ) {
mw.messages.set( {
'foo-lorem': 'Lorem',
'foo-ipsum': 'Ipsum',
@@ -67,17 +62,17 @@ test( 'Options', function() {
var html, $lc, attrs, x, sitename = 'Wikipedia';
// Message key prefix
- html = '<div><span title-msg="lorem"><html:msg key="ipsum" /></span></div>';
+ html = '<div><span title-msg="lorem"><html:msg key="ipsum"></span></div>';
$lc = $( html ).localize( {
prefix: 'foo-'
} ).find( 'span' );
- strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' );
- strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' );
+ assert.strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' );
+ assert.strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' );
// Variable keys mapping
x = 'bar';
- html = '<div><span title-msg="title"><html:msg key="label" /></span></div>';
+ html = '<div><span title-msg="title"><html:msg key="label"></span></div>';
$lc = $( html ).localize( {
keys: {
'title': 'foo-' + x + '-title',
@@ -85,22 +80,22 @@ test( 'Options', function() {
}
} ).find( 'span' );
- strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' );
- strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' );
+ assert.strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' );
+ assert.strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' );
// Passing parameteters to mw.msg
- html = '<div><span><html:msg key="foo-welcome" /></span></div>';
+ html = '<div><span><html:msg key="foo-welcome"></span></div>';
$lc = $( html ).localize( {
params: {
'foo-welcome': [sitename, 'yesterday']
}
} ).find( 'span' );
- strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' );
+ assert.strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' );
// Combination of options prefix, params and keys
x = 'bazz';
- html = '<div><span title-msg="title"><html:msg key="label" /></span></div>';
+ html = '<div><span title-msg="title"><html:msg key="label"></span></div>';
$lc = $( html ).localize( {
prefix: 'foo-',
keys: {
@@ -114,6 +109,25 @@ test( 'Options', function() {
}
} ).find( 'span' );
- strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' );
- strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' );
+ assert.strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' );
+ assert.strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' );
+} );
+
+QUnit.test( 'Handle data text', 2, function ( assert ) {
+ var html, $lc;
+ mw.messages.set( 'option-one', 'Item 1' );
+ mw.messages.set( 'option-two', 'Item 2' );
+ html = '<select><option data-msg-text="option-one"></option><option data-msg-text="option-two"></option></select>';
+ $lc = $( html ).localize().find( 'option' );
+ assert.strictEqual( $lc.eq( 0 ).text(), mw.msg( 'option-one' ), 'data-msg-text becomes text of options' );
+ assert.strictEqual( $lc.eq( 1 ).text(), mw.msg( 'option-two' ), 'data-msg-text becomes text of options' );
+} );
+
+QUnit.test( 'Handle data html', 2, function ( assert ) {
+ var html, $lc;
+ mw.messages.set( 'html', 'behold... there is a <a>link</a> here!!' );
+ html = '<div><div data-msg-html="html"></div></div>';
+ $lc = $( html ).localize().find( 'a' );
+ assert.strictEqual( $lc.length, 1, 'link is created' );
+ assert.strictEqual( $lc.text(), 'link', 'the link text got added' );
} );
diff --git a/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js b/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js
index 3a2d0d83..5b566ae0 100644
--- a/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js
@@ -1,58 +1,58 @@
-module( 'jquery.mwExtension', QUnit.newMwEnvironment() );
+QUnit.module( 'jquery.mwExtension', QUnit.newMwEnvironment() );
-test( 'String functions', function() {
+QUnit.test( 'String functions', function ( assert ) {
- equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
- equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
- equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' );
+ assert.equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
+ assert.equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
+ assert.equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' );
- equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
+ assert.equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
'<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
- equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
+ assert.equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
- equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
+ assert.equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
- equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
+ assert.equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
});
-test( 'Is functions', function() {
+QUnit.test( 'Is functions', function ( assert ) {
- strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
+ assert.strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
'isDomElement: #qunit-header Node' );
- strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
+ assert.strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
'isDomElement: #random-name (null)' );
- strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
+ assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
'isDomElement: getElementsByTagName Array' );
- strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
+ assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
'isDomElement: getElementsByTagName(..)[0] Node' );
- strictEqual( $.isDomElement( $( 'div' ) ), false,
+ assert.strictEqual( $.isDomElement( $( 'div' ) ), false,
'isDomElement: jQuery object' );
- strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
+ assert.strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
'isDomElement: jQuery object > Get node' );
- strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
+ assert.strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
'isDomElement: createElement' );
- strictEqual( $.isDomElement( { foo: 1 } ), false,
+ assert.strictEqual( $.isDomElement( { foo: 1 } ), false,
'isDomElement: Object' );
- strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
- strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
- strictEqual( $.isEmpty( '' ), true, 'isEmptry: ""' );
- strictEqual( $.isEmpty( 1 ), false, 'isEmptry: 1' );
- strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
- strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
+ assert.strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
+ assert.strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
+ assert.strictEqual( $.isEmpty( '' ), true, 'isEmptry: ""' );
+ assert.strictEqual( $.isEmpty( 1 ), false, 'isEmptry: 1' );
+ assert.strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
+ assert.strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
// Documented behaviour
- strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
+ assert.strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
});
-test( 'Comparison functions', function() {
+QUnit.test( 'Comparison functions', function ( assert ) {
- ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
+ assert.ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
'compareArray: Two deep arrays that are excactly the same' );
- ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
+ assert.ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
- ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
- ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
- ok( !$.compareObject( { bar: true }, { baz: false } ),
+ assert.ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
+ assert.ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
+ assert.ok( !$.compareObject( { bar: true }, { baz: false } ),
'compareObject: Two different objects (false)' );
});
diff --git a/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js b/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js
index 98ff5508..161f0cd1 100644
--- a/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js
@@ -1,15 +1,6 @@
-module( 'jquery.tabIndex', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(2);
-
- ok( $.fn.firstTabIndex, '$.fn.firstTabIndex defined' );
- ok( $.fn.lastTabIndex, '$.fn.lastTabIndex defined' );
-});
-
-test( 'firstTabIndex', function() {
- expect(2);
+QUnit.module( 'jquery.tabIndex', QUnit.newMwEnvironment() );
+QUnit.test( 'firstTabIndex', 2, function ( assert ) {
var testEnvironment =
'<form>' +
'<input tabindex="7" />' +
@@ -19,15 +10,13 @@ test( 'firstTabIndex', function() {
'</form>';
var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
- strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
+ assert.strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
var $testB = $( '<div>' );
- strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
+ assert.strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
});
-test( 'lastTabIndex', function() {
- expect(2);
-
+QUnit.test( 'lastTabIndex', 2, function ( assert ) {
var testEnvironment =
'<form>' +
'<input tabindex="7" />' +
@@ -37,8 +26,8 @@ test( 'lastTabIndex', function() {
'</form>';
var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
- strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
+ assert.strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
var $testB = $( '<div>' );
- strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
+ assert.strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
});
diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
index 7ecdc4b1..16d81707 100644
--- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
@@ -1,4 +1,4 @@
-( function () {
+( function ( $, mw ) {
var config = {
wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
@@ -7,12 +7,7 @@ var config = {
wgContentLanguage: 'en'
};
-module( 'jquery.tablesorter', QUnit.newMwEnvironment( config ) );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.tablesorter, '$.tablesorter defined' );
-});
+QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment({ config: config }) );
/**
* Create an HTML table from an array of row arrays containing text strings.
@@ -22,28 +17,29 @@ test( '-- Initial check', function() {
* @param {String[][]} data
* @return jQuery
*/
-var tableCreate = function( header, data ) {
- var $table = $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
+function tableCreate( header, data ) {
+ var i,
+ $table = $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
$thead = $table.find( 'thead' ),
$tbody = $table.find( 'tbody' ),
$tr = $( '<tr>' );
- $.each( header, function( i, str ) {
+ $.each( header, function ( i, str ) {
var $th = $( '<th>' );
$th.text( str ).appendTo( $tr );
});
$tr.appendTo( $thead );
- for (var i = 0; i < data.length; i++) {
+ for ( i = 0; i < data.length; i++ ) {
$tr = $( '<tr>' );
- $.each( data[i], function( j, str ) {
+ $.each( data[i], function ( j, str ) {
var $td = $( '<td>' );
$td.text( str ).appendTo( $tr );
});
$tr.appendTo( $tbody );
}
return $table;
-};
+}
/**
* Extract text from table.
@@ -51,7 +47,7 @@ var tableCreate = function( header, data ) {
* @param {jQuery} $table
* @return String[][]
*/
-var tableExtract = function( $table ) {
+function tableExtract( $table ) {
var data = [];
$table.find( 'tbody' ).find( 'tr' ).each( function( i, tr ) {
@@ -62,7 +58,7 @@ var tableExtract = function( $table ) {
data.push( row );
});
return data;
-};
+}
/**
* Run a table test by building a table with the given data,
@@ -74,10 +70,8 @@ var tableExtract = function( $table ) {
* @param {String[][]} expected rows/cols to compare against at end
* @param {function($table)} callback something to do with the table before we compare
*/
-var tableTest = function( msg, header, data, expected, callback ) {
- test( msg, function() {
- expect(1);
-
+function tableTest( msg, header, data, expected, callback ) {
+ QUnit.test( msg, 1, function ( assert ) {
var $table = tableCreate( header, data );
// Give caller a chance to set up sorting and manipulate the table.
@@ -86,15 +80,18 @@ var tableTest = function( msg, header, data, expected, callback ) {
// Table sorting is done synchronously; if it ever needs to change back
// to asynchronous, we'll need a timeout or a callback here.
var extracted = tableExtract( $table );
- deepEqual( extracted, expected, msg );
+ assert.deepEqual( extracted, expected, msg );
});
-};
+}
-var reversed = function(arr) {
+function reversed(arr) {
+ // Clone array
var arr2 = arr.slice(0);
+
arr2.reverse();
+
return arr2;
-};
+}
// Sample data set using planets named and their radius
var header = [ 'Planet' , 'Radius (km)'],
@@ -115,7 +112,7 @@ tableTest(
header,
planets,
ascendingName,
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
}
@@ -125,7 +122,7 @@ tableTest(
header,
planets,
ascendingName,
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
}
@@ -135,7 +132,7 @@ tableTest(
header,
planets,
reversed(ascendingName),
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click().click();
}
@@ -145,7 +142,7 @@ tableTest(
header,
planets,
ascendingRadius,
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(1)' ).click();
}
@@ -155,7 +152,7 @@ tableTest(
header,
planets,
reversed(ascendingRadius),
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(1)' ).click().click();
}
@@ -180,7 +177,7 @@ tableTest(
['09.11.2011'],
['11.11.2011']
],
- function( $table ) {
+ function ( $table ) {
mw.config.set( 'wgDefaultDateFormat', 'dmy' );
mw.config.set( 'wgContentLanguage', 'de' );
@@ -206,7 +203,7 @@ tableTest(
['09.11.2011'],
['11.11.2011']
],
- function( $table ) {
+ function ( $table ) {
mw.config.set( 'wgDefaultDateFormat', 'mdy' );
$table.tablesorter();
@@ -242,7 +239,7 @@ tableTest(
['IP'],
ipv4,
ipv4Sorted,
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click();
}
@@ -252,7 +249,7 @@ tableTest(
['IP'],
ipv4,
reversed(ipv4Sorted),
- function( $table ) {
+ function ( $table ) {
$table.tablesorter();
$table.find( '.headerSort:eq(0)' ).click().click();
}
@@ -287,7 +284,7 @@ tableTest(
['Name'],
umlautWords,
umlautWordsSorted,
- function( $table ) {
+ function ( $table ) {
mw.config.set( 'tableSorterCollation', {
'ä': 'ae',
'ö': 'oe',
@@ -301,14 +298,14 @@ tableTest(
);
var planetsRowspan = [["Earth","6051.8"], jupiter, ["Mars","6051.8"], mercury, saturn, venus];
-var planetsRowspanII = [jupiter, mercury, saturn, ['Venus', '6371.0'], venus, ['Venus', '3390.0']];
+var planetsRowspanII = [jupiter, mercury, saturn, venus, ['Venus', '6371.0'], ['Venus', '3390.0']];
tableTest(
'Basic planet table: same value for multiple rows via rowspan',
header,
planets,
planetsRowspan,
- function( $table ) {
+ function ( $table ) {
// Modify the table to have a multiuple-row-spanning cell:
// - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
$table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
@@ -325,7 +322,7 @@ tableTest(
header,
planets,
planetsRowspanII,
- function( $table ) {
+ function ( $table ) {
// Modify the table to have a multiuple-row-spanning cell:
// - Remove 1st cell of 4th row, and, 1st cell or 5th row.
$table.find( 'tr:eq(3) td:eq(0), tr:eq(4) td:eq(0)' ).remove();
@@ -348,11 +345,11 @@ var complexMDYDates = [
];
var complexMDYSorted = [
- ["5.12.1990"],
- ["April 21 1991"],
- ["04 22 1991"],
- ["January, 19 2010"],
- ["December 12 '10"]
+ ['5.12.1990'],
+ ['April 21 1991'],
+ ['04 22 1991'],
+ ['January, 19 2010'],
+ ['December 12 \'10']
];
tableTest(
@@ -360,7 +357,7 @@ tableTest(
['date'],
complexMDYDates,
complexMDYSorted,
- function( $table ) {
+ function ( $table ) {
mw.config.set( 'wgDefaultDateFormat', 'mdy' );
$table.tablesorter();
@@ -368,6 +365,39 @@ tableTest(
}
);
+var currencyUnsorted = [
+ ['1.02 $'],
+ ['$ 3.00'],
+ ['€ 2,99'],
+ ['$ 1.00'],
+ ['$3.50'],
+ ['$ 1.50'],
+ ['€ 0.99']
+];
+
+var currencySorted = [
+ ['€ 0.99'],
+ ['$ 1.00'],
+ ['1.02 $'],
+ ['$ 1.50'],
+ ['$ 3.00'],
+ ['$3.50'],
+ // Comma's sort after dots
+ // Not intentional but test to detect changes
+ ['€ 2,99']
+];
+
+tableTest(
+ 'Currency parsing I',
+ ['currency'],
+ currencyUnsorted,
+ currencySorted,
+ function ( $table ) {
+ $table.tablesorter();
+ $table.find( '.headerSort:eq(0)' ).click();
+ }
+);
+
var ascendingNameLegacy = ascendingName.slice(0);
ascendingNameLegacy[4] = ascendingNameLegacy[5];
ascendingNameLegacy.pop();
@@ -384,8 +414,9 @@ tableTest(
}
);
+
/** FIXME: the diff output is not very readeable. */
-test( 'bug 32047 - caption must be before thead', function() {
+QUnit.test( 'bug 32047 - caption must be before thead', function ( assert ) {
var $table;
$table = $(
'<table class="sortable">' +
@@ -398,17 +429,18 @@ test( 'bug 32047 - caption must be before thead', function() {
);
$table.tablesorter();
- equals(
+ assert.equal(
$table.children( ).get( 0 ).nodeName,
'CAPTION',
'First element after <thead> must be <caption> (bug 32047)'
);
});
-test( 'data-sort-value attribute, when available, should override sorting position', function() {
+QUnit.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert ) {
var $table, data;
- // Simple example, one without data-sort-value which should be sorted at it's text.
+ // Example 1: All cells except one cell without data-sort-value,
+ // which should be sorted at it's text content value.
$table = $(
'<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
'<tbody>' +
@@ -424,30 +456,33 @@ test( 'data-sort-value attribute, when available, should override sorting positi
data = [];
$table.find( 'tbody > tr' ).each( function( i, tr ) {
$( tr ).find( 'td' ).each( function( i, td ) {
- data.push( { data: $( td ).data( 'sort-value' ), text: $( td ).text() } );
+ data.push( {
+ data: $( td ).data( 'sortValue' ),
+ text: $( td ).text()
+ } );
});
});
- deepEqual( data, [
+ assert.deepEqual( data, [
{
- "data": "Apple",
- "text": "Bird"
+ data: 'Apple',
+ text: 'Bird'
}, {
- "data": "Bananna",
- "text": "Ferret"
+ data: 'Bananna',
+ text: 'Ferret'
}, {
- "data": undefined,
- "text": "Cheetah"
+ data: undefined,
+ text: 'Cheetah'
}, {
- "data": "Cherry",
- "text": "Dolphin"
+ data: 'Cherry',
+ text: 'Dolphin'
}, {
- "data": "Drupe",
- "text": "Elephant"
+ data: 'Drupe',
+ text: 'Elephant'
}
- ] );
+ ], 'Order matches expected order (based on data-sort-value attribute values)' );
- // Another example
+ // Example 2
$table = $(
'<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
'<tbody>' +
@@ -461,30 +496,91 @@ test( 'data-sort-value attribute, when available, should override sorting positi
$table.tablesorter().find( '.headerSort:eq(0)' ).click();
data = [];
+ $table.find( 'tbody > tr' ).each( function ( i, tr ) {
+ $( tr ).find( 'td' ).each( function ( i, td ) {
+ data.push( {
+ data: $( td ).data( 'sortValue' ),
+ text: $( td ).text()
+ } );
+ });
+ });
+
+ assert.deepEqual( data, [
+ {
+ data: undefined,
+ text: 'B'
+ }, {
+ data: undefined,
+ text: 'D'
+ }, {
+ data: 'E',
+ text: 'A'
+ }, {
+ data: 'F',
+ text: 'C'
+ }, {
+ data: undefined,
+ text: 'G'
+ }
+ ], 'Order matches expected order (based on data-sort-value attribute values)' );
+
+ // Example 3: Test that live changes are used from data-sort-value,
+ // even if they change after the tablesorter is constructed (bug 38152).
+ $table = $(
+ '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
+ '<tbody>' +
+ '<tr><td>D</td></tr>' +
+ '<tr><td data-sort-value="1">A</td></tr>' +
+ '<tr><td>B</td></tr>' +
+ '<tr><td data-sort-value="2">G</td></tr>' +
+ '<tr><td>C</td></tr>' +
+ '</tbody></table>'
+ );
+ // initialize table sorter and sort once
+ $table
+ .tablesorter()
+ .find( '.headerSort:eq(0)' ).click();
+
+ // Change the sortValue data properties (bug 38152)
+ // - change data
+ $table.find( 'td:contains(A)' ).data( 'sortValue', 3 );
+ // - add data
+ $table.find( 'td:contains(B)' ).data( 'sortValue', 1 );
+ // - remove data, bring back attribute: 2
+ $table.find( 'td:contains(G)' ).removeData( 'sortValue' );
+
+ // Now sort again (twice, so it is back at Ascending)
+ $table.find( '.headerSort:eq(0)' ).click();
+ $table.find( '.headerSort:eq(0)' ).click();
+
+ data = [];
$table.find( 'tbody > tr' ).each( function( i, tr ) {
$( tr ).find( 'td' ).each( function( i, td ) {
- data.push( { data: $( td ).data( 'sort-value' ), text: $( td ).text() } );
+ data.push( {
+ data: $( td ).data( 'sortValue' ),
+ text: $( td ).text()
+ } );
});
});
- deepEqual( data, [
+ assert.deepEqual( data, [
{
- "data": undefined,
- "text": "B"
+ data: 1,
+ text: "B"
}, {
- "data": undefined,
- "text": "D"
+ data: 2,
+ text: "G"
}, {
- "data": "E",
- "text": "A"
+ data: 3,
+ text: "A"
}, {
- "data": "F",
- "text": "C"
+ data: undefined,
+ text: "C"
}, {
- "data": undefined,
- "text": "G"
+ data: undefined,
+ text: "D"
}
- ] );
+ ], 'Order matches expected order, using the current sortValue in $.data()' );
});
@@ -522,13 +618,11 @@ tableTest( 'bug 8115: sort numbers with commas (descending)',
);
// TODO add numbers sorting tests for bug 8115 with a different language
-test( 'bug 32888 - Tables inside a tableheader cell', function() {
- expect(2);
-
+QUnit.test( 'bug 32888 - Tables inside a tableheader cell', 2, function ( assert ) {
var $table;
$table = $(
- '<table class="sortable" id="32888">' +
- '<tr><th>header<table id="32888-2">'+
+ '<table class="sortable" id="mw-bug-32888">' +
+ '<tr><th>header<table id="mw-bug-32888-2">'+
'<tr><th>1</th><th>2</th></tr>' +
'</table></th></tr>' +
'<tr><td>A</td></tr>' +
@@ -537,16 +631,67 @@ test( 'bug 32888 - Tables inside a tableheader cell', function() {
);
$table.tablesorter();
- equals(
+ assert.equal(
$table.find('> thead:eq(0) > tr > th.headerSort').length,
1,
'Child tables inside a headercell should not interfere with sortable headers (bug 32888)'
);
- equals(
- $('#32888-2').find('th.headerSort').length,
+ assert.equal(
+ $( '#mw-bug-32888-2' ).find('th.headerSort').length,
0,
'The headers of child tables inside a headercell should not be sortable themselves (bug 32888)'
);
});
-})();
+
+var correctDateSorting1 = [
+ ['01 January 2010'],
+ ['05 February 2010'],
+ ['16 January 2010']
+];
+
+var correctDateSortingSorted1 = [
+ ['01 January 2010'],
+ ['16 January 2010'],
+ ['05 February 2010']
+];
+
+tableTest(
+ 'Correct date sorting I',
+ ['date'],
+ correctDateSorting1,
+ correctDateSortingSorted1,
+ function ( $table ) {
+ mw.config.set( 'wgDefaultDateFormat', 'mdy' );
+
+ $table.tablesorter();
+ $table.find( '.headerSort:eq(0)' ).click();
+ }
+);
+
+var correctDateSorting2 = [
+ ['January 01 2010'],
+ ['February 05 2010'],
+ ['January 16 2010']
+];
+
+var correctDateSortingSorted2 = [
+ ['January 01 2010'],
+ ['January 16 2010'],
+ ['February 05 2010']
+];
+
+tableTest(
+ 'Correct date sorting II',
+ ['date'],
+ correctDateSorting2,
+ correctDateSortingSorted2,
+ function ( $table ) {
+ mw.config.set( 'wgDefaultDateFormat', 'dmy' );
+
+ $table.tablesorter();
+ $table.find( '.headerSort:eq(0)' ).click();
+ }
+);
+
+}( jQuery, mediaWiki ) );
diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
index 1b2f3024..f0a210f5 100644
--- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
@@ -1,9 +1,4 @@
-module( 'jquery.textSelection', QUnit.newMwEnvironment() );
-
-test( '-- Initial check', function() {
- expect(1);
- ok( $.fn.textSelection, 'jQuery.fn.textSelection defined' );
-} );
+QUnit.module( 'jquery.textSelection', QUnit.newMwEnvironment() );
/**
* Test factory for $.fn.textSelection( 'encapsulateText' )
@@ -16,7 +11,7 @@ test( '-- Initial check', function() {
* end {int} ending char for selection
* params {object} add'l parameters for $().textSelection( 'encapsulateText' )
*/
-var encapsulateTest = function( options ) {
+function encapsulateTest( options ) {
var opt = $.extend({
description: '',
before: {},
@@ -34,12 +29,12 @@ var encapsulateTest = function( options ) {
selected: null
}, opt.after);
- test( opt.description, function() {
+ QUnit.test( opt.description, function ( assert ) {
var tests = 1;
if ( opt.after.selected !== null ) {
tests++;
}
- expect( tests );
+ QUnit.expect( tests );
var $textarea = $( '<textarea>' );
@@ -65,15 +60,15 @@ var encapsulateTest = function( options ) {
var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" );
- equal( text, opt.after.text, 'Checking full text after encapsulation' );
+ assert.equal( text, opt.after.text, 'Checking full text after encapsulation' );
if (opt.after.selected !== null) {
var selected = $textarea.textSelection( 'getSelection' );
- equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' );
+ assert.equal( selected, opt.after.selected, 'Checking selected text after encapsulation.' );
}
} );
-};
+}
var sig = {
'pre': "--~~~~"
@@ -86,7 +81,7 @@ var sig = {
'peri': 'Heading 2',
'post': ' ==',
'regex': /^(\s*)(={1,6})(.*?)\2(\s*)$/,
- 'regexReplace': "\$1==\$3==\$4",
+ 'regexReplace': "$1==$3==$4",
'ownline': true
}, ulist = {
'pre': "* ",
@@ -222,28 +217,26 @@ encapsulateTest({
});
-var caretTest = function(options) {
- test(options.description, function() {
- expect(2);
-
- var $textarea = $( '<textarea>' ).text(options.text);
+function caretTest( options ) {
+ QUnit.test( options.description, 2, function ( assert ) {
+ var $textarea = $( '<textarea>' ).text( options.text );
$( '#qunit-fixture' ).append( $textarea );
- if (options.mode == 'set') {
+ if ( options.mode === 'set' ) {
$textarea.textSelection('setSelection', {
start: options.start,
end: options.end
});
}
- var among = function(actual, expected, message) {
- if ($.isArray(expected)) {
- ok($.inArray(actual, expected) !== -1 , message + ' (got ' + actual + '; expected one of ' + expected.join(', ') + ')');
+ function among( actual, expected, message ) {
+ if ( $.isArray( expected ) ) {
+ assert.ok( $.inArray( actual, expected ) !== -1 , message + ' (got ' + actual + '; expected one of ' + expected.join(', ') + ')' );
} else {
- equal(actual, expected, message);
+ assert.equal( actual, expected, message );
}
- };
+ }
var pos = $textarea.textSelection('getCaretPosition', {startAndEnd: true});
among(pos[0], options.start, 'Caret start should be where we set it.');
@@ -253,6 +246,8 @@ var caretTest = function(options) {
var caretSample = "Some big text that we like to work with. Nothing fancy... you know what I mean?";
+/*
+ // @broken: Disabled per bug 34820
caretTest({
description: 'getCaretPosition with original/empty selection - bug 31847 with IE 6/7/8',
text: caretSample,
@@ -260,6 +255,7 @@ caretTest({
end: [0, caretSample.length], // Other browsers default it to the beginning (0), so check both.
mode: 'get'
});
+*/
caretTest({
description: 'set/getCaretPosition with forced empty selection',