2 var header
= [ 'Planet', 'Radius (km)' ],
5 mercury
= [ 'Mercury', '2439.7' ],
6 venus
= [ 'Venus', '6051.8' ],
7 earth
= [ 'Earth', '6371.0' ],
8 mars
= [ 'Mars', '3390.0' ],
9 jupiter
= [ 'Jupiter', '69911' ],
10 saturn
= [ 'Saturn', '58232' ],
11 planets
= [ mercury
, venus
, earth
, mars
, jupiter
, saturn
],
12 planetsAscName
= [ earth
, jupiter
, mars
, mercury
, saturn
, venus
],
13 planetsAscRadius
= [ mercury
, mars
, venus
, earth
, saturn
, jupiter
],
25 simple
= [ a2
, b3
, a1
, a3
, b2
, b1
],
26 simpleAsc
= [ a1
, a2
, a3
, b1
, b2
, b3
],
27 simpleDescasc
= [ b1
, b2
, b3
, a1
, a2
, a3
],
30 header4
= [ 'column1a', 'column1b', 'column1c', 'column2' ],
31 aaa1
= [ 'A', 'A', 'A', '1' ],
32 aab5
= [ 'A', 'A', 'B', '5' ],
33 abc3
= [ 'A', 'B', 'C', '3' ],
34 bbc2
= [ 'B', 'B', 'C', '2' ],
35 caa4
= [ 'C', 'A', 'A', '4' ],
36 colspanInitial
= [ aab5
, aaa1
, abc3
, bbc2
, caa4
],
40 // Some randomly generated fake IPs
44 [ '204.204.132.158' ],
51 // Sort order should go octet by octet
58 [ '204.204.132.158' ],
93 digraphWordsSorted
= [
103 [ 'January, 19 2010' ],
107 [ 'December 12 \'10' ]
113 [ 'January, 19 2010' ],
114 [ 'December 12 \'10' ]
133 // Comma's sort after dots
134 // Not intentional but test to detect changes
155 correctDateSorting1
= [
156 [ '01 January 2010' ],
157 [ '05 February 2010' ],
158 [ '16 January 2010' ]
160 correctDateSortingSorted1
= [
161 [ '01 January 2010' ],
162 [ '16 January 2010' ],
163 [ '05 February 2010' ]
166 correctDateSorting2
= [
167 [ 'January 01 2010' ],
168 [ 'February 05 2010' ],
169 [ 'January 16 2010' ]
171 correctDateSortingSorted2
= [
172 [ 'January 01 2010' ],
173 [ 'January 16 2010' ],
174 [ 'February 05 2010' ]
178 [ '2009-12-25T12:30:45.001Z' ],
181 [ '2009-12-25T12:30:45' ],
182 [ '2009-12-25T12:30:45.111' ],
183 [ '2009-12-25T12:30:45+01:00' ]
185 isoDateSortingSorted
= [
187 [ '2009-12-25T12:30:45+01:00' ],
188 [ '2009-12-25T12:30:45' ],
189 [ '2009-12-25T12:30:45.001Z' ],
190 [ '2009-12-25T12:30:45.111' ],
195 QUnit
.module( 'jquery.tablesorter', QUnit
.newMwEnvironment( {
197 this.liveMonths
= mw
.language
.months
;
198 mw
.language
.months
= {
200 names
: [ 'january', 'february', 'march', 'april', 'may_long', 'june',
201 'july', 'august', 'september', 'october', 'november', 'december' ],
202 genitive
: [ 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
203 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen', 'december-gen' ],
204 abbrev
: [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun',
205 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ]
207 names
: [ 'January', 'February', 'March', 'April', 'May', 'June',
208 'July', 'August', 'September', 'October', 'November', 'December' ],
209 genitive
: [ 'January', 'February', 'March', 'April', 'May', 'June',
210 'July', 'August', 'September', 'October', 'November', 'December' ],
211 abbrev
: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
212 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
215 teardown: function () {
216 mw
.language
.months
= this.liveMonths
;
219 wgDefaultDateFormat
: 'dmy',
220 wgSeparatorTransformTable
: [ '', '' ],
221 wgDigitTransformTable
: [ '', '' ],
222 wgPageContentLanguage
: 'en'
227 * Create an HTML table from an array of row arrays containing text strings.
228 * First row will be header row. No fancy rowspan/colspan stuff.
230 * @param {string[]} header
231 * @param {string[][]} data
234 function tableCreate( header
, data
) {
236 $table
= $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
237 $thead
= $table
.find( 'thead' ),
238 $tbody
= $table
.find( 'tbody' ),
241 $.each( header
, function ( i
, str
) {
242 var $th
= $( '<th>' );
243 $th
.text( str
).appendTo( $tr
);
245 $tr
.appendTo( $thead
);
247 for ( i
= 0; i
< data
.length
; i
++ ) {
249 // eslint-disable-next-line no-loop-func
250 $.each( data
[ i
], function ( j
, str
) {
251 var $td
= $( '<td>' );
252 $td
.text( str
).appendTo( $tr
);
254 $tr
.appendTo( $tbody
);
260 * Extract text from table.
262 * @param {jQuery} $table
263 * @return {string[][]}
265 function tableExtract( $table
) {
268 $table
.find( 'tbody' ).find( 'tr' ).each( function ( i
, tr
) {
270 $( tr
).find( 'td,th' ).each( function ( i
, td
) {
271 row
.push( $( td
).text() );
279 * Run a table test by building a table with the given data,
280 * running some callback on it, then checking the results.
282 * @param {string} msg text to pass on to qunit for the comparison
283 * @param {string[]} header cols to make the table
284 * @param {string[][]} data rows/cols to make the table
285 * @param {string[][]} expected rows/cols to compare against at end
286 * @param {function($table)} callback something to do with the table before we compare
288 function tableTest( msg
, header
, data
, expected
, callback
) {
289 QUnit
.test( msg
, function ( assert
) {
291 $table
= tableCreate( header
, data
);
293 // Give caller a chance to set up sorting and manipulate the table.
296 // Table sorting is done synchronously; if it ever needs to change back
297 // to asynchronous, we'll need a timeout or a callback here.
298 extracted
= tableExtract( $table
);
299 assert
.deepEqual( extracted
, expected
, msg
);
304 * Run a table test by building a table with the given HTML,
305 * running some callback on it, then checking the results.
307 * @param {string} msg text to pass on to qunit for the comparison
308 * @param {string} html HTML to make the table
309 * @param {string[][]} expected Rows/cols to compare against at end
310 * @param {function($table)} callback Something to do with the table before we compare
312 function tableTestHTML( msg
, html
, expected
, callback
) {
313 QUnit
.test( msg
, function ( assert
) {
317 // Give caller a chance to set up sorting and manipulate the table.
321 $table
.tablesorter();
322 $table
.find( '#sortme' ).click();
325 // Table sorting is done synchronously; if it ever needs to change back
326 // to asynchronous, we'll need a timeout or a callback here.
327 extracted
= tableExtract( $table
);
328 assert
.deepEqual( extracted
, expected
, msg
);
332 function reversed( arr
) {
334 var arr2
= arr
.slice( 0 );
341 // Sample data set using planets named and their radius
344 'Basic planet table: sorting initially - ascending by name',
348 function ( $table
) {
349 $table
.tablesorter( { sortList
: [
355 'Basic planet table: sorting initially - descending by radius',
358 reversed( planetsAscRadius
),
359 function ( $table
) {
360 $table
.tablesorter( { sortList
: [
366 'Basic planet table: ascending by name',
370 function ( $table
) {
371 $table
.tablesorter();
372 $table
.find( '.headerSort:eq(0)' ).click();
376 'Basic planet table: ascending by name a second time',
380 function ( $table
) {
381 $table
.tablesorter();
382 $table
.find( '.headerSort:eq(0)' ).click();
386 'Basic planet table: ascending by name (multiple clicks)',
390 function ( $table
) {
391 $table
.tablesorter();
392 $table
.find( '.headerSort:eq(0)' ).click();
393 $table
.find( '.headerSort:eq(1)' ).click();
394 $table
.find( '.headerSort:eq(0)' ).click();
398 'Basic planet table: descending by name',
401 reversed( planetsAscName
),
402 function ( $table
) {
403 $table
.tablesorter();
404 $table
.find( '.headerSort:eq(0)' ).click().click();
408 'Basic planet table: ascending radius',
412 function ( $table
) {
413 $table
.tablesorter();
414 $table
.find( '.headerSort:eq(1)' ).click();
418 'Basic planet table: descending radius',
421 reversed( planetsAscRadius
),
422 function ( $table
) {
423 $table
.tablesorter();
424 $table
.find( '.headerSort:eq(1)' ).click().click();
428 'Sorting multiple columns by passing sort list',
432 function ( $table
) {
442 'Sorting multiple columns by programmatically triggering sort()',
446 function ( $table
) {
447 $table
.tablesorter();
448 $table
.data( 'tablesorter' ).sort(
457 'Reset to initial sorting by triggering sort() without any parameters',
461 function ( $table
) {
468 $table
.data( 'tablesorter' ).sort(
474 $table
.data( 'tablesorter' ).sort();
478 'Sort via click event after having initialized the tablesorter with initial sorting',
482 function ( $table
) {
484 { sortList
: [ { 0: 'asc' }, { 1: 'asc' } ] }
486 $table
.find( '.headerSort:eq(0)' ).click();
490 'Multi-sort via click event after having initialized the tablesorter with initial sorting',
494 function ( $table
) {
497 { sortList
: [ { 0: 'desc' }, { 1: 'desc' } ] }
499 $table
.find( '.headerSort:eq(0)' ).click();
501 // Pretend to click while pressing the multi-sort key
502 event
= $.Event( 'click' );
503 event
[ $table
.data( 'tablesorter' ).config
.sortMultiSortKey
] = true;
504 $table
.find( '.headerSort:eq(1)' ).trigger( event
);
507 QUnit
.test( 'Reset sorting making table appear unsorted', function ( assert
) {
508 var $table
= tableCreate( header
, simple
);
515 $table
.data( 'tablesorter' ).sort( [] );
518 $table
.find( 'th.headerSortUp' ).length
+ $table
.find( 'th.headerSortDown' ).length
,
520 'No sort specific sort classes addign to header cells'
524 $table
.find( 'th' ).first().attr( 'title' ),
525 mw
.msg( 'sort-ascending' ),
526 'First header cell has default title'
530 $table
.find( 'th' ).first().attr( 'title' ),
531 $table
.find( 'th' ).last().attr( 'title' ),
532 'Both header cells\' titles match'
536 // Sorting with colspans
538 tableTest( 'Sorting with colspanned headers: spanned column',
541 [ aaa1
, aab5
, abc3
, bbc2
, caa4
],
542 function ( $table
) {
543 // Make colspanned header for test
544 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
545 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
547 $table
.tablesorter();
548 $table
.find( '.headerSort:eq(0)' ).click();
551 tableTest( 'Sorting with colspanned headers: sort spanned column twice',
554 [ caa4
, bbc2
, abc3
, aab5
, aaa1
],
555 function ( $table
) {
556 // Make colspanned header for test
557 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
558 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
560 $table
.tablesorter();
561 $table
.find( '.headerSort:eq(0)' ).click();
562 $table
.find( '.headerSort:eq(0)' ).click();
565 tableTest( 'Sorting with colspanned headers: subsequent column',
568 [ aaa1
, bbc2
, abc3
, caa4
, aab5
],
569 function ( $table
) {
570 // Make colspanned header for test
571 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
572 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
574 $table
.tablesorter();
575 $table
.find( '.headerSort:eq(1)' ).click();
578 tableTest( 'Sorting with colspanned headers: sort subsequent column twice',
581 [ aab5
, caa4
, abc3
, bbc2
, aaa1
],
582 function ( $table
) {
583 // Make colspanned header for test
584 $table
.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
585 $table
.find( 'tr:eq(0) th:eq(0)' ).attr( 'colspan', '3' );
587 $table
.tablesorter();
588 $table
.find( '.headerSort:eq(1)' ).click();
589 $table
.find( '.headerSort:eq(1)' ).click();
593 QUnit
.test( 'Basic planet table: one unsortable column', function ( assert
) {
594 var $table
= tableCreate( header
, planets
),
596 $table
.find( 'tr:eq(0) > th:eq(0)' ).addClass( 'unsortable' );
598 $table
.tablesorter();
599 $table
.find( 'tr:eq(0) > th:eq(0)' ).click();
602 tableExtract( $table
),
607 $cell
= $table
.find( 'tr:eq(0) > th:eq(0)' );
608 $table
.find( 'tr:eq(0) > th:eq(1)' ).click();
611 $cell
.hasClass( 'headerSortUp' ) || $cell
.hasClass( 'headerSortDown' ),
613 'after sort: no class headerSortUp or headerSortDown'
617 $cell
.attr( 'title' ),
619 'after sort: no title tag added'
626 'T30775: German-style (dmy) short numeric dates',
629 // German-style dates are day-month-year
637 // Sorted by ascending date
644 function ( $table
) {
645 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
646 mw
.config
.set( 'wgPageContentLanguage', 'de' );
648 $table
.tablesorter();
649 $table
.find( '.headerSort:eq(0)' ).click();
654 'T30775: American-style (mdy) short numeric dates',
657 // American-style dates are month-day-year
665 // Sorted by ascending date
672 function ( $table
) {
673 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
675 $table
.tablesorter();
676 $table
.find( '.headerSort:eq(0)' ).click();
681 'T19141: IPv4 address sorting',
685 function ( $table
) {
686 $table
.tablesorter();
687 $table
.find( '.headerSort:eq(0)' ).click();
691 'T19141: IPv4 address sorting (reverse)',
694 reversed( ipv4Sorted
),
695 function ( $table
) {
696 $table
.tablesorter();
697 $table
.find( '.headerSort:eq(0)' ).click().click();
702 'Accented Characters with custom collation',
706 function ( $table
) {
707 mw
.config
.set( 'tableSorterCollation', {
714 $table
.tablesorter();
715 $table
.find( '.headerSort:eq(0)' ).click();
720 'Digraphs with custom collation',
724 function ( $table
) {
725 mw
.config
.set( 'tableSorterCollation', {
730 $table
.tablesorter();
731 $table
.find( '.headerSort:eq(0)' ).click();
735 QUnit
.test( 'Rowspan not exploded on init', function ( assert
) {
736 var $table
= tableCreate( header
, planets
);
738 // Modify the table to have a multiple-row-spanning cell:
739 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
740 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
741 // - Set rowspan for 2nd cell of 3rd row to 3.
742 // This covers the removed cell in the 4th and 5th row.
743 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
745 $table
.tablesorter();
748 $table
.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowSpan' ),
750 'Rowspan not exploded'
755 [ 'Earth', '6051.8' ],
757 [ 'Mars', '6051.8' ],
762 planetsRowspanII
= [ jupiter
, mercury
, saturn
, venus
, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ];
765 'Basic planet table: same value for multiple rows via rowspan',
769 function ( $table
) {
770 // Modify the table to have a multiple-row-spanning cell:
771 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
772 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
773 // - Set rowspan for 2nd cell of 3rd row to 3.
774 // This covers the removed cell in the 4th and 5th row.
775 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
777 $table
.tablesorter();
778 $table
.find( '.headerSort:eq(0)' ).click();
782 'Basic planet table: same value for multiple rows via rowspan (sorting initially)',
786 function ( $table
) {
787 // Modify the table to have a multiple-row-spanning cell:
788 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
789 $table
.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
790 // - Set rowspan for 2nd cell of 3rd row to 3.
791 // This covers the removed cell in the 4th and 5th row.
792 $table
.find( 'tr:eq(2) td:eq(1)' ).attr( 'rowspan', '3' );
794 $table
.tablesorter( { sortList
: [
800 'Basic planet table: Same value for multiple rows via rowspan II',
804 function ( $table
) {
805 // Modify the table to have a multiple-row-spanning cell:
806 // - Remove 1st cell of 4th row, and, 1st cell or 5th row.
807 $table
.find( 'tr:eq(3) td:eq(0), tr:eq(4) td:eq(0)' ).remove();
808 // - Set rowspan for 1st cell of 3rd row to 3.
809 // This covers the removed cell in the 4th and 5th row.
810 $table
.find( 'tr:eq(2) td:eq(0)' ).attr( 'rowspan', '3' );
812 $table
.tablesorter();
813 $table
.find( '.headerSort:eq(0)' ).click();
818 'Complex date parsing I',
822 function ( $table
) {
823 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
825 $table
.tablesorter();
826 $table
.find( '.headerSort:eq(0)' ).click();
831 'Currency parsing I',
835 function ( $table
) {
836 $table
.tablesorter();
837 $table
.find( '.headerSort:eq(0)' ).click();
841 planetsAscNameLegacy
= planetsAscName
.slice( 0 );
842 planetsAscNameLegacy
[ 4 ] = planetsAscNameLegacy
[ 5 ];
843 planetsAscNameLegacy
.pop();
846 'Legacy compat with .sortbottom',
849 planetsAscNameLegacy
,
850 function ( $table
) {
851 $table
.find( 'tr:last' ).addClass( 'sortbottom' );
852 $table
.tablesorter();
853 $table
.find( '.headerSort:eq(0)' ).click();
857 QUnit
.test( 'Test detection routine', function ( assert
) {
860 '<table class="sortable">' +
861 '<caption>CAPTION</caption>' +
862 '<tr><th>THEAD</th></tr>' +
863 '<tr><td>1</td></tr>' +
864 '<tr class="sortbottom"><td>text</td></tr>' +
867 $table
.tablesorter();
868 $table
.find( '.headerSort:eq(0)' ).click();
871 $table
.data( 'tablesorter' ).config
.parsers
[ 0 ].id
,
873 'Correctly detected column content skipping sortbottom'
877 /** FIXME: the diff output is not very readeable. */
878 QUnit
.test( 'T34047 - caption must be before thead', function ( assert
) {
881 '<table class="sortable">' +
882 '<caption>CAPTION</caption>' +
883 '<tr><th>THEAD</th></tr>' +
884 '<tr><td>A</td></tr>' +
885 '<tr><td>B</td></tr>' +
886 '<tr class="sortbottom"><td>TFOOT</td></tr>' +
889 $table
.tablesorter();
892 $table
.children().get( 0 ).nodeName
,
894 'First element after <thead> must be <caption> (T34047)'
898 QUnit
.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert
) {
901 // Example 1: All cells except one cell without data-sort-value,
902 // which should be sorted at it's text content value.
904 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
906 '<tr><td>Cheetah</td></tr>' +
907 '<tr><td data-sort-value="Apple">Bird</td></tr>' +
908 '<tr><td data-sort-value="Bananna">Ferret</td></tr>' +
909 '<tr><td data-sort-value="Drupe">Elephant</td></tr>' +
910 '<tr><td data-sort-value="Cherry">Dolphin</td></tr>' +
913 $table
.tablesorter().find( '.headerSort:eq(0)' ).click();
916 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
917 $( tr
).find( 'td' ).each( function ( i
, td
) {
919 data
: $( td
).data( 'sortValue' ),
925 assert
.deepEqual( data
, [
946 ], 'Order matches expected order (based on data-sort-value attribute values)' );
950 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
952 '<tr><td>D</td></tr>' +
953 '<tr><td data-sort-value="E">A</td></tr>' +
954 '<tr><td>B</td></tr>' +
955 '<tr><td>G</td></tr>' +
956 '<tr><td data-sort-value="F">C</td></tr>' +
959 $table
.tablesorter().find( '.headerSort:eq(0)' ).click();
962 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
963 $( tr
).find( 'td' ).each( function ( i
, td
) {
965 data
: $( td
).data( 'sortValue' ),
971 assert
.deepEqual( data
, [
992 ], 'Order matches expected order (based on data-sort-value attribute values)' );
994 // Example 3: Test that live changes are used from data-sort-value,
995 // even if they change after the tablesorter is constructed (T40152).
997 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
999 '<tr><td>D</td></tr>' +
1000 '<tr><td data-sort-value="1">A</td></tr>' +
1001 '<tr><td>B</td></tr>' +
1002 '<tr><td data-sort-value="2">G</td></tr>' +
1003 '<tr><td>C</td></tr>' +
1006 // initialize table sorter and sort once
1009 .find( '.headerSort:eq(0)' ).click();
1011 // Change the sortValue data properties (T40152)
1013 $table
.find( 'td:contains(A)' ).data( 'sortValue', 3 );
1015 $table
.find( 'td:contains(B)' ).data( 'sortValue', 1 );
1016 // - remove data, bring back attribute: 2
1017 $table
.find( 'td:contains(G)' ).removeData( 'sortValue' );
1019 // Now sort again (twice, so it is back at Ascending)
1020 $table
.find( '.headerSort:eq(0)' ).click();
1021 $table
.find( '.headerSort:eq(0)' ).click();
1024 $table
.find( 'tbody > tr' ).each( function ( i
, tr
) {
1025 $( tr
).find( 'td' ).each( function ( i
, td
) {
1027 data
: $( td
).data( 'sortValue' ),
1028 text
: $( td
).text()
1033 assert
.deepEqual( data
, [
1054 ], 'Order matches expected order, using the current sortValue in $.data()' );
1058 tableTest( 'T10115: sort numbers with commas (ascending)',
1059 [ 'Numbers' ], numbers
, numbersAsc
,
1060 function ( $table
) {
1061 $table
.tablesorter();
1062 $table
.find( '.headerSort:eq(0)' ).click();
1066 tableTest( 'T10115: sort numbers with commas (descending)',
1067 [ 'Numbers' ], numbers
, reversed( numbersAsc
),
1068 function ( $table
) {
1069 $table
.tablesorter();
1070 $table
.find( '.headerSort:eq(0)' ).click().click();
1073 // TODO add numbers sorting tests for T10115 with a different language
1075 QUnit
.test( 'T34888 - Tables inside a tableheader cell', function ( assert
) {
1078 '<table class="sortable" id="mw-bug-32888">' +
1079 '<tr><th>header<table id="mw-bug-32888-2">' +
1080 '<tr><th>1</th><th>2</th></tr>' +
1081 '</table></th></tr>' +
1082 '<tr><td>A</td></tr>' +
1083 '<tr><td>B</td></tr>' +
1086 $table
.tablesorter();
1089 $table
.find( '> thead:eq(0) > tr > th.headerSort' ).length
,
1091 'Child tables inside a headercell should not interfere with sortable headers (T34888)'
1094 $( '#mw-bug-32888-2' ).find( 'th.headerSort' ).length
,
1096 'The headers of child tables inside a headercell should not be sortable themselves (T34888)'
1101 'Correct date sorting I',
1103 correctDateSorting1
,
1104 correctDateSortingSorted1
,
1105 function ( $table
) {
1106 mw
.config
.set( 'wgDefaultDateFormat', 'mdy' );
1108 $table
.tablesorter();
1109 $table
.find( '.headerSort:eq(0)' ).click();
1114 'Correct date sorting II',
1116 correctDateSorting2
,
1117 correctDateSortingSorted2
,
1118 function ( $table
) {
1119 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
1121 $table
.tablesorter();
1122 $table
.find( '.headerSort:eq(0)' ).click();
1130 isoDateSortingSorted
,
1131 function ( $table
) {
1132 mw
.config
.set( 'wgDefaultDateFormat', 'dmy' );
1134 $table
.tablesorter();
1135 $table
.find( '.headerSort:eq(0)' ).click();
1139 QUnit
.test( 'Sorting images using alt text', function ( assert
) {
1141 '<table class="sortable">' +
1142 '<tr><th>THEAD</th></tr>' +
1143 '<tr><td><img alt="2"/></td></tr>' +
1144 '<tr><td>1</td></tr>' +
1147 $table
.tablesorter().find( '.headerSort:eq(0)' ).click();
1150 $table
.find( 'td' ).first().text(),
1152 'Applied correct sorting order'
1156 QUnit
.test( 'Sorting images using alt text (complex)', function ( assert
) {
1158 '<table class="sortable">' +
1159 '<tr><th>THEAD</th></tr>' +
1160 '<tr><td><img alt="D" />A</td></tr>' +
1161 '<tr><td>CC</td></tr>' +
1162 '<tr><td><a><img alt="A" /></a>F</tr>' +
1163 '<tr><td><img alt="A" /><strong>E</strong></tr>' +
1164 '<tr><td><strong><img alt="A" />D</strong></tr>' +
1165 '<tr><td><img alt="A" />C</tr>' +
1168 $table
.tablesorter().find( '.headerSort:eq(0)' ).click();
1171 $table
.find( 'td' ).text(),
1173 'Applied correct sorting order'
1177 QUnit
.test( 'Sorting images using alt text (with format autodetection)', function ( assert
) {
1179 '<table class="sortable">' +
1180 '<tr><th>THEAD</th></tr>' +
1181 '<tr><td><img alt="1" />7</td></tr>' +
1182 '<tr><td>1<img alt="6" /></td></tr>' +
1183 '<tr><td>5</td></tr>' +
1184 '<tr><td>4</td></tr>' +
1187 $table
.tablesorter().find( '.headerSort:eq(0)' ).click();
1190 $table
.find( 'td' ).text(),
1192 'Applied correct sorting order'
1196 QUnit
.test( 'T40911 - The row with the largest amount of columns should receive the sort indicators', function ( assert
) {
1198 '<table class="sortable">' +
1200 '<tr><th rowspan="2" id="A1">A1</th><th colspan="2">B2a</th></tr>' +
1201 '<tr><th id="B2b">B2b</th><th id="C2b">C2b</th></tr>' +
1203 '<tr><td>A</td><td>Aa</td><td>Ab</td></tr>' +
1204 '<tr><td>B</td><td>Ba</td><td>Bb</td></tr>' +
1207 $table
.tablesorter();
1210 $table
.find( '#A1' ).attr( 'class' ),
1212 'The first column of the first row should be sortable'
1215 $table
.find( '#B2b' ).attr( 'class' ),
1217 'The th element of the 2nd row of the 2nd column should be sortable'
1220 $table
.find( '#C2b' ).attr( 'class' ),
1222 'The th element of the 2nd row of the 3rd column should be sortable'
1226 QUnit
.test( 'rowspans in table headers should prefer the last row when rows are equal in length', function ( assert
) {
1228 '<table class="sortable">' +
1230 '<tr><th rowspan="2" id="A1">A1</th><th>B2a</th></tr>' +
1231 '<tr><th id="B2b">B2b</th></tr>' +
1233 '<tr><td>A</td><td>Aa</td></tr>' +
1234 '<tr><td>B</td><td>Ba</td></tr>' +
1237 $table
.tablesorter();
1240 $table
.find( '#A1' ).attr( 'class' ),
1242 'The first column of the first row should be sortable'
1245 $table
.find( '#B2b' ).attr( 'class' ),
1247 'The th element of the 2nd row of the 2nd column should be sortable'
1251 QUnit
.test( 'holes in the table headers should not throw JS errors', function ( assert
) {
1253 '<table class="sortable">' +
1255 '<tr><th id="A1">A1</th><th>B1</th><th id="C1" rowspan="2">C1</th></tr>' +
1256 '<tr><th id="A2">A2</th></tr>' +
1258 '<tr><td>A</td><td>Aa</td><td>Aaa</td></tr>' +
1259 '<tr><td>B</td><td>Ba</td><td>Bbb</td></tr>' +
1262 $table
.tablesorter();
1263 assert
.equal( $table
.find( '#A2' ).data( 'headerIndex' ),
1265 'A2 should not be a sort header'
1267 assert
.equal( $table
.find( '#C1' ).data( 'headerIndex' ),
1269 'C1 should be a sort header'
1274 QUnit
.test( 'td cells in thead should not be taken into account for longest row calculation', function ( assert
) {
1276 '<table class="sortable">' +
1278 '<tr><th id="A1">A1</th><th>B1</th><td id="C1">C1</td></tr>' +
1279 '<tr><th id="A2">A2</th><th>B2</th><th id="C2">C2</th></tr>' +
1283 $table
.tablesorter();
1284 assert
.equal( $table
.find( '#C2' ).data( 'headerIndex' ),
1286 'C2 should be a sort header'
1288 assert
.equal( $table
.find( '#C1' ).data( 'headerIndex' ),
1290 'C1 should not be a sort header'
1294 // T43889 - exploding rowspans in more complex cases
1296 'Rowspan exploding with row headers',
1297 '<table class="sortable">' +
1298 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1300 '<tr><td>1</td><th rowspan="2">foo</th><td rowspan="2">bar</td><td>baz</td></tr>' +
1301 '<tr><td>2</td><td>baz</td></tr>' +
1304 [ '1', 'foo', 'bar', 'baz' ],
1305 [ '2', 'foo', 'bar', 'baz' ]
1309 // T55211 - exploding rowspans in more complex cases
1311 'Rowspan exploding with row headers and colspans', function ( assert
) {
1312 var $table
= $( '<table class="sortable">' +
1313 '<thead><tr><th rowspan="2">n</th><th colspan="2">foo</th><th rowspan="2">baz</th></tr>' +
1314 '<tr><th>foo</th><th>bar</th></tr></thead>' +
1316 '<tr><td>1</td><td>foo</td><td>bar</td><td>baz</td></tr>' +
1317 '<tr><td>2</td><td>foo</td><td>bar</td><td>baz</td></tr>' +
1318 '</tbody></table>' );
1320 $table
.tablesorter();
1321 assert
.equal( $table
.find( 'tr:eq(1) th:eq(1)' ).data( 'headerIndex' ),
1323 'Incorrect index of sort header'
1329 'Rowspan exploding with colspanned cells',
1330 '<table class="sortable">' +
1331 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1333 '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td></tr>' +
1334 '<tr><td>2</td><td colspan="2">foobar</td></tr>' +
1337 [ '1', 'foo', 'bar', 'baz' ],
1338 [ '2', 'foobar', 'baz' ]
1343 'Rowspan exploding with colspanned cells (2)',
1344 '<table class="sortable">' +
1345 '<thead><tr><th>n</th><th>foo</th><th>bar</th><th>baz</th><th id="sortme">n2</th></tr></thead>' +
1347 '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td><td>2</td></tr>' +
1348 '<tr><td>2</td><td colspan="2">foobar</td><td>1</td></tr>' +
1351 [ '2', 'foobar', 'baz', '1' ],
1352 [ '1', 'foo', 'bar', 'baz', '2' ]
1357 'Rowspan exploding with rightmost rows spanning most',
1358 '<table class="sortable">' +
1359 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th></tr></thead>' +
1361 '<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td></tr>' +
1362 '<tr><td>2</td></tr>' +
1363 '<tr><td>3</td><td rowspan="2">foo</td></tr>' +
1364 '<tr><td>4</td></tr>' +
1367 [ '1', 'foo', 'bar' ],
1368 [ '2', 'foo', 'bar' ],
1369 [ '3', 'foo', 'bar' ],
1370 [ '4', 'foo', 'bar' ]
1375 'Rowspan exploding with rightmost rows spanning most (2)',
1376 '<table class="sortable">' +
1377 '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' +
1379 '<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td><td>baz</td></tr>' +
1380 '<tr><td>2</td><td>baz</td></tr>' +
1381 '<tr><td>3</td><td rowspan="2">foo</td><td>baz</td></tr>' +
1382 '<tr><td>4</td><td>baz</td></tr>' +
1385 [ '1', 'foo', 'bar', 'baz' ],
1386 [ '2', 'foo', 'bar', 'baz' ],
1387 [ '3', 'foo', 'bar', 'baz' ],
1388 [ '4', 'foo', 'bar', 'baz' ]
1393 'Rowspan exploding with row-and-colspanned cells',
1394 '<table class="sortable">' +
1395 '<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>bar</th><th>baz</th></tr></thead>' +
1397 '<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="4">bar</td><td>baz</td></tr>' +
1398 '<tr><td>2</td><td>baz</td></tr>' +
1399 '<tr><td>3</td><td colspan="2" rowspan="2">foo</td><td>baz</td></tr>' +
1400 '<tr><td>4</td><td>baz</td></tr>' +
1403 [ '1', 'foo1', 'foo2', 'bar', 'baz' ],
1404 [ '2', 'foo1', 'foo2', 'bar', 'baz' ],
1405 [ '3', 'foo', 'bar', 'baz' ],
1406 [ '4', 'foo', 'bar', 'baz' ]
1411 'Rowspan exploding with uneven rowspan layout',
1412 '<table class="sortable">' +
1413 '<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>foo3</th><th>bar</th><th>baz</th></tr></thead>' +
1415 '<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>bar</td><td>baz</td></tr>' +
1416 '<tr><td>2</td><td rowspan="3">bar</td><td>baz</td></tr>' +
1417 '<tr><td>3</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>baz</td></tr>' +
1418 '<tr><td>4</td><td>baz</td></tr>' +
1421 [ '1', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1422 [ '2', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1423 [ '3', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ],
1424 [ '4', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ]
1428 QUnit
.test( 'T105731 - incomplete rows in table body', function ( assert
) {
1429 var $table
, parsers
;
1431 '<table class="sortable">' +
1432 '<tr><th>A</th><th>B</th></tr>' +
1433 '<tr><td>3</td></tr>' +
1434 '<tr><td>1</td><td>2</td></tr>' +
1437 $table
.tablesorter();
1438 $table
.find( '.headerSort:eq(0)' ).click();
1439 // now the first row have 2 columns
1440 $table
.find( '.headerSort:eq(1)' ).click();
1442 parsers
= $table
.data( 'tablesorter' ).config
.parsers
;
1447 'detectParserForColumn() detect 2 parsers'
1453 'detectParserForColumn() detect parser.id "number" for second column'
1457 parsers
[ 1 ].format( $table
.find( 'tbody > tr > td:eq(1)' ).text() ),
1459 'empty cell is sorted as number -Infinity'
1463 QUnit
.test( 'bug T114721 - use of expand-child class', function ( assert
) {
1464 var $table
, parsers
;
1466 '<table class="sortable">' +
1467 '<tr><th>A</th><th>B</th></tr>' +
1468 '<tr><td>b</td><td>4</td></tr>' +
1469 '<tr class="expand-child"><td colspan="2">some text follow b</td></tr>' +
1470 '<tr><td>a</td><td>2</td></tr>' +
1471 '<tr class="expand-child"><td colspan="2">some text follow a</td></tr>' +
1472 '<tr class="expand-child"><td colspan="2">more text</td></tr>' +
1475 $table
.tablesorter();
1476 $table
.find( '.headerSort:eq(0)' ).click();
1479 tableExtract( $table
),
1482 [ 'some text follow a' ],
1485 [ 'some text follow b' ]
1487 'row with expand-child class follow above row'
1490 parsers
= $table
.data( 'tablesorter' ).config
.parsers
;
1494 'detectParserForColumn() detect parser.id "number" for second column'
1498 }( jQuery
, mediaWiki
) );