Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.tablesorter.test.js
1 ( function ( $, mw ) {
2
3 var config = {
4 wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
5 wgMonthNamesShort: ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
6 wgDefaultDateFormat: 'dmy',
7 wgContentLanguage: 'en'
8 };
9
10 QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment({ config: config }) );
11
12 /**
13 * Create an HTML table from an array of row arrays containing text strings.
14 * First row will be header row. No fancy rowspan/colspan stuff.
15 *
16 * @param {String[]} header
17 * @param {String[][]} data
18 * @return jQuery
19 */
20 function tableCreate( header, data ) {
21 var i,
22 $table = $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ),
23 $thead = $table.find( 'thead' ),
24 $tbody = $table.find( 'tbody' ),
25 $tr = $( '<tr>' );
26
27 $.each( header, function ( i, str ) {
28 var $th = $( '<th>' );
29 $th.text( str ).appendTo( $tr );
30 });
31 $tr.appendTo( $thead );
32
33 for ( i = 0; i < data.length; i++ ) {
34 $tr = $( '<tr>' );
35 $.each( data[i], function ( j, str ) {
36 var $td = $( '<td>' );
37 $td.text( str ).appendTo( $tr );
38 });
39 $tr.appendTo( $tbody );
40 }
41 return $table;
42 }
43
44 /**
45 * Extract text from table.
46 *
47 * @param {jQuery} $table
48 * @return String[][]
49 */
50 function tableExtract( $table ) {
51 var data = [];
52
53 $table.find( 'tbody' ).find( 'tr' ).each( function( i, tr ) {
54 var row = [];
55 $( tr ).find( 'td,th' ).each( function( i, td ) {
56 row.push( $( td ).text() );
57 });
58 data.push( row );
59 });
60 return data;
61 }
62
63 /**
64 * Run a table test by building a table with the given data,
65 * running some callback on it, then checking the results.
66 *
67 * @param {String} msg text to pass on to qunit for the comparison
68 * @param {String[]} header cols to make the table
69 * @param {String[][]} data rows/cols to make the table
70 * @param {String[][]} expected rows/cols to compare against at end
71 * @param {function($table)} callback something to do with the table before we compare
72 */
73 function tableTest( msg, header, data, expected, callback ) {
74 QUnit.test( msg, 1, function ( assert ) {
75 var $table = tableCreate( header, data );
76
77 // Give caller a chance to set up sorting and manipulate the table.
78 callback( $table );
79
80 // Table sorting is done synchronously; if it ever needs to change back
81 // to asynchronous, we'll need a timeout or a callback here.
82 var extracted = tableExtract( $table );
83 assert.deepEqual( extracted, expected, msg );
84 });
85 }
86
87 function reversed(arr) {
88 // Clone array
89 var arr2 = arr.slice(0);
90
91 arr2.reverse();
92
93 return arr2;
94 }
95
96 // Sample data set using planets named and their radius
97 var header = [ 'Planet' , 'Radius (km)'],
98 mercury = [ 'Mercury', '2439.7' ],
99 venus = [ 'Venus' , '6051.8' ],
100 earth = [ 'Earth' , '6371.0' ],
101 mars = [ 'Mars' , '3390.0' ],
102 jupiter = [ 'Jupiter', '69911' ],
103 saturn = [ 'Saturn' , '58232' ];
104
105 // Initial data set
106 var planets = [mercury, venus, earth, mars, jupiter, saturn];
107 var ascendingName = [earth, jupiter, mars, mercury, saturn, venus];
108 var ascendingRadius = [mercury, mars, venus, earth, saturn, jupiter];
109
110 tableTest(
111 'Basic planet table: sorting initially - ascending by name',
112 header,
113 planets,
114 ascendingName,
115 function ( $table ) {
116 $table.tablesorter( { sortList: [ { 0: 'asc' } ] } );
117 }
118 );
119 tableTest(
120 'Basic planet table: sorting initially - descending by radius',
121 header,
122 planets,
123 reversed(ascendingRadius),
124 function ( $table ) {
125 $table.tablesorter( { sortList: [ { 1: 'desc' } ] } );
126 }
127 );
128 tableTest(
129 'Basic planet table: ascending by name',
130 header,
131 planets,
132 ascendingName,
133 function ( $table ) {
134 $table.tablesorter();
135 $table.find( '.headerSort:eq(0)' ).click();
136 }
137 );
138 tableTest(
139 'Basic planet table: ascending by name a second time',
140 header,
141 planets,
142 ascendingName,
143 function ( $table ) {
144 $table.tablesorter();
145 $table.find( '.headerSort:eq(0)' ).click();
146 }
147 );
148 tableTest(
149 'Basic planet table: descending by name',
150 header,
151 planets,
152 reversed(ascendingName),
153 function ( $table ) {
154 $table.tablesorter();
155 $table.find( '.headerSort:eq(0)' ).click().click();
156 }
157 );
158 tableTest(
159 'Basic planet table: ascending radius',
160 header,
161 planets,
162 ascendingRadius,
163 function ( $table ) {
164 $table.tablesorter();
165 $table.find( '.headerSort:eq(1)' ).click();
166 }
167 );
168 tableTest(
169 'Basic planet table: descending radius',
170 header,
171 planets,
172 reversed(ascendingRadius),
173 function ( $table ) {
174 $table.tablesorter();
175 $table.find( '.headerSort:eq(1)' ).click().click();
176 }
177 );
178
179 // Sample data set to test multiple column sorting
180 var header = [ 'column1' , 'column2'],
181 a1 = [ 'A', '1' ],
182 a2 = [ 'A', '2' ],
183 a3 = [ 'A', '3' ],
184 b1 = [ 'B', '1' ],
185 b2 = [ 'B', '2' ],
186 b3 = [ 'B', '3' ];
187 var initial = [a2, b3, a1, a3, b2, b1];
188 var asc = [a1, a2, a3, b1, b2, b3];
189 var descasc = [b1, b2, b3, a1, a2, a3];
190
191 tableTest(
192 'Sorting multiple columns by passing sort list',
193 header,
194 initial,
195 asc,
196 function ( $table ) {
197 $table.tablesorter(
198 { sortList: [ { 0: 'asc' }, { 1: 'asc' } ] }
199 );
200 }
201 );
202 tableTest(
203 'Sorting multiple columns by programmatically triggering sort()',
204 header,
205 initial,
206 descasc,
207 function ( $table ) {
208 $table.tablesorter();
209 $table.data( 'tablesorter' ).sort(
210 [ { 0: 'desc' }, { 1: 'asc' } ]
211 );
212 }
213 );
214 tableTest(
215 'Reset to initial sorting by triggering sort() without any parameters',
216 header,
217 initial,
218 asc,
219 function ( $table ) {
220 $table.tablesorter(
221 { sortList: [ { 0: 'asc' }, { 1: 'asc' } ] }
222 );
223 $table.data( 'tablesorter' ).sort(
224 [ { 0: 'desc' }, { 1: 'asc' } ]
225 );
226 $table.data( 'tablesorter' ).sort();
227 }
228 );
229 QUnit.test( 'Reset sorting making table appear unsorted', 3, function ( assert ) {
230 var $table = tableCreate( header, initial );
231 $table.tablesorter(
232 { sortList: [ { 0: 'desc' }, { 1: 'asc' } ] }
233 );
234 $table.data( 'tablesorter' ).sort( [] );
235
236 assert.equal(
237 $table.find( 'th.headerSortUp' ).length + $table.find( 'th.headerSortDown' ).length,
238 0,
239 'No sort specific sort classes addign to header cells'
240 );
241
242 assert.equal(
243 $table.find( 'th' ).first().attr( 'title' ),
244 mw.msg( 'sort-ascending' ),
245 'First header cell has default title'
246 );
247
248 assert.equal(
249 $table.find( 'th' ).first().attr( 'title' ),
250 $table.find( 'th' ).last().attr( 'title' ),
251 'Both header cells\' titles match'
252 );
253 } );
254
255 // Regression tests!
256 tableTest(
257 'Bug 28775: German-style (dmy) short numeric dates',
258 ['Date'],
259 [ // German-style dates are day-month-year
260 ['11.11.2011'],
261 ['01.11.2011'],
262 ['02.10.2011'],
263 ['03.08.2011'],
264 ['09.11.2011']
265 ],
266 [ // Sorted by ascending date
267 ['03.08.2011'],
268 ['02.10.2011'],
269 ['01.11.2011'],
270 ['09.11.2011'],
271 ['11.11.2011']
272 ],
273 function ( $table ) {
274 mw.config.set( 'wgDefaultDateFormat', 'dmy' );
275 mw.config.set( 'wgContentLanguage', 'de' );
276
277 $table.tablesorter();
278 $table.find( '.headerSort:eq(0)' ).click();
279 }
280 );
281
282 tableTest(
283 'Bug 28775: American-style (mdy) short numeric dates',
284 ['Date'],
285 [ // American-style dates are month-day-year
286 ['11.11.2011'],
287 ['01.11.2011'],
288 ['02.10.2011'],
289 ['03.08.2011'],
290 ['09.11.2011']
291 ],
292 [ // Sorted by ascending date
293 ['01.11.2011'],
294 ['02.10.2011'],
295 ['03.08.2011'],
296 ['09.11.2011'],
297 ['11.11.2011']
298 ],
299 function ( $table ) {
300 mw.config.set( 'wgDefaultDateFormat', 'mdy' );
301
302 $table.tablesorter();
303 $table.find( '.headerSort:eq(0)' ).click();
304 }
305 );
306
307 var ipv4 = [
308 // Some randomly generated fake IPs
309 ['45.238.27.109'],
310 ['44.172.9.22'],
311 ['247.240.82.209'],
312 ['204.204.132.158'],
313 ['170.38.91.162'],
314 ['197.219.164.9'],
315 ['45.68.154.72'],
316 ['182.195.149.80']
317 ];
318 var ipv4Sorted = [
319 // Sort order should go octet by octet
320 ['44.172.9.22'],
321 ['45.68.154.72'],
322 ['45.238.27.109'],
323 ['170.38.91.162'],
324 ['182.195.149.80'],
325 ['197.219.164.9'],
326 ['204.204.132.158'],
327 ['247.240.82.209']
328 ];
329
330 tableTest(
331 'Bug 17141: IPv4 address sorting',
332 ['IP'],
333 ipv4,
334 ipv4Sorted,
335 function ( $table ) {
336 $table.tablesorter();
337 $table.find( '.headerSort:eq(0)' ).click();
338 }
339 );
340 tableTest(
341 'Bug 17141: IPv4 address sorting (reverse)',
342 ['IP'],
343 ipv4,
344 reversed(ipv4Sorted),
345 function ( $table ) {
346 $table.tablesorter();
347 $table.find( '.headerSort:eq(0)' ).click().click();
348 }
349 );
350
351 var umlautWords = [
352 // Some words with Umlauts
353 ['Günther'],
354 ['Peter'],
355 ['Björn'],
356 ['Bjorn'],
357 ['Apfel'],
358 ['Äpfel'],
359 ['Strasse'],
360 ['Sträßschen']
361 ];
362
363 var umlautWordsSorted = [
364 // Some words with Umlauts
365 ['Äpfel'],
366 ['Apfel'],
367 ['Björn'],
368 ['Bjorn'],
369 ['Günther'],
370 ['Peter'],
371 ['Sträßschen'],
372 ['Strasse']
373 ];
374
375 tableTest(
376 'Accented Characters with custom collation',
377 ['Name'],
378 umlautWords,
379 umlautWordsSorted,
380 function ( $table ) {
381 mw.config.set( 'tableSorterCollation', {
382 'ä': 'ae',
383 'ö': 'oe',
384 'ß': 'ss',
385 'ü':'ue'
386 } );
387
388 $table.tablesorter();
389 $table.find( '.headerSort:eq(0)' ).click();
390 }
391 );
392
393 var planetsRowspan = [["Earth","6051.8"], jupiter, ["Mars","6051.8"], mercury, saturn, venus];
394 var planetsRowspanII = [jupiter, mercury, saturn, venus, ['Venus', '6371.0'], ['Venus', '3390.0']];
395
396 tableTest(
397 'Basic planet table: same value for multiple rows via rowspan',
398 header,
399 planets,
400 planetsRowspan,
401 function ( $table ) {
402 // Modify the table to have a multiple-row-spanning cell:
403 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
404 $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
405 // - Set rowspan for 2nd cell of 3rd row to 3.
406 // This covers the removed cell in the 4th and 5th row.
407 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
408
409 $table.tablesorter();
410 $table.find( '.headerSort:eq(0)' ).click();
411 }
412 );
413 tableTest(
414 'Basic planet table: same value for multiple rows via rowspan (sorting initially)',
415 header,
416 planets,
417 planetsRowspan,
418 function ( $table ) {
419 // Modify the table to have a multiple-row-spanning cell:
420 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
421 $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
422 // - Set rowspan for 2nd cell of 3rd row to 3.
423 // This covers the removed cell in the 4th and 5th row.
424 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
425
426 $table.tablesorter( { sortList: [ { 0: 'asc' } ] } );
427 }
428 );
429 tableTest(
430 'Basic planet table: Same value for multiple rows via rowspan II',
431 header,
432 planets,
433 planetsRowspanII,
434 function ( $table ) {
435 // Modify the table to have a multiple-row-spanning cell:
436 // - Remove 1st cell of 4th row, and, 1st cell or 5th row.
437 $table.find( 'tr:eq(3) td:eq(0), tr:eq(4) td:eq(0)' ).remove();
438 // - Set rowspan for 1st cell of 3rd row to 3.
439 // This covers the removed cell in the 4th and 5th row.
440 $table.find( 'tr:eq(2) td:eq(0)' ).prop( 'rowspan', '3' );
441
442 $table.tablesorter();
443 $table.find( '.headerSort:eq(0)' ).click();
444 }
445 );
446
447 var complexMDYDates = [
448 // Some words with Umlauts
449 ['January, 19 2010'],
450 ['April 21 1991'],
451 ['04 22 1991'],
452 ['5.12.1990'],
453 ['December 12 \'10']
454 ];
455
456 var complexMDYSorted = [
457 ['5.12.1990'],
458 ['April 21 1991'],
459 ['04 22 1991'],
460 ['January, 19 2010'],
461 ['December 12 \'10']
462 ];
463
464 tableTest(
465 'Complex date parsing I',
466 ['date'],
467 complexMDYDates,
468 complexMDYSorted,
469 function ( $table ) {
470 mw.config.set( 'wgDefaultDateFormat', 'mdy' );
471
472 $table.tablesorter();
473 $table.find( '.headerSort:eq(0)' ).click();
474 }
475 );
476
477 var currencyUnsorted = [
478 ['1.02 $'],
479 ['$ 3.00'],
480 ['€ 2,99'],
481 ['$ 1.00'],
482 ['$3.50'],
483 ['$ 1.50'],
484 ['€ 0.99']
485 ];
486
487 var currencySorted = [
488 ['€ 0.99'],
489 ['$ 1.00'],
490 ['1.02 $'],
491 ['$ 1.50'],
492 ['$ 3.00'],
493 ['$3.50'],
494 // Comma's sort after dots
495 // Not intentional but test to detect changes
496 ['€ 2,99']
497 ];
498
499 tableTest(
500 'Currency parsing I',
501 ['currency'],
502 currencyUnsorted,
503 currencySorted,
504 function ( $table ) {
505 $table.tablesorter();
506 $table.find( '.headerSort:eq(0)' ).click();
507 }
508 );
509
510 var ascendingNameLegacy = ascendingName.slice(0);
511 ascendingNameLegacy[4] = ascendingNameLegacy[5];
512 ascendingNameLegacy.pop();
513
514 tableTest(
515 'Legacy compat with .sortbottom',
516 header,
517 planets,
518 ascendingNameLegacy,
519 function( $table ) {
520 $table.find( 'tr:last' ).addClass( 'sortbottom' );
521 $table.tablesorter();
522 $table.find( '.headerSort:eq(0)' ).click();
523 }
524 );
525
526 QUnit.test( 'Test detection routine', function ( assert ) {
527 var $table;
528 $table = $(
529 '<table class="sortable">' +
530 '<caption>CAPTION</caption>' +
531 '<tr><th>THEAD</th></tr>' +
532 '<tr><td>1</td></tr>' +
533 '<tr class="sortbottom"><td>text</td></tr>' +
534 '</table>'
535 );
536 $table.tablesorter();
537
538 assert.equal(
539 $table.data( 'tablesorter' ).config.parsers[0].id,
540 'number',
541 'Correctly detected column content skipping sortbottom'
542 );
543 } );
544
545 /** FIXME: the diff output is not very readeable. */
546 QUnit.test( 'bug 32047 - caption must be before thead', function ( assert ) {
547 var $table;
548 $table = $(
549 '<table class="sortable">' +
550 '<caption>CAPTION</caption>' +
551 '<tr><th>THEAD</th></tr>' +
552 '<tr><td>A</td></tr>' +
553 '<tr><td>B</td></tr>' +
554 '<tr class="sortbottom"><td>TFOOT</td></tr>' +
555 '</table>'
556 );
557 $table.tablesorter();
558
559 assert.equal(
560 $table.children( ).get( 0 ).nodeName,
561 'CAPTION',
562 'First element after <thead> must be <caption> (bug 32047)'
563 );
564 });
565
566 QUnit.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert ) {
567 var $table, data;
568
569 // Example 1: All cells except one cell without data-sort-value,
570 // which should be sorted at it's text content value.
571 $table = $(
572 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
573 '<tbody>' +
574 '<tr><td>Cheetah</td></tr>' +
575 '<tr><td data-sort-value="Apple">Bird</td></tr>' +
576 '<tr><td data-sort-value="Bananna">Ferret</td></tr>' +
577 '<tr><td data-sort-value="Drupe">Elephant</td></tr>' +
578 '<tr><td data-sort-value="Cherry">Dolphin</td></tr>' +
579 '</tbody></table>'
580 );
581 $table.tablesorter().find( '.headerSort:eq(0)' ).click();
582
583 data = [];
584 $table.find( 'tbody > tr' ).each( function( i, tr ) {
585 $( tr ).find( 'td' ).each( function( i, td ) {
586 data.push( {
587 data: $( td ).data( 'sortValue' ),
588 text: $( td ).text()
589 } );
590 });
591 });
592
593 assert.deepEqual( data, [
594 {
595 data: 'Apple',
596 text: 'Bird'
597 }, {
598 data: 'Bananna',
599 text: 'Ferret'
600 }, {
601 data: undefined,
602 text: 'Cheetah'
603 }, {
604 data: 'Cherry',
605 text: 'Dolphin'
606 }, {
607 data: 'Drupe',
608 text: 'Elephant'
609 }
610 ], 'Order matches expected order (based on data-sort-value attribute values)' );
611
612 // Example 2
613 $table = $(
614 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
615 '<tbody>' +
616 '<tr><td>D</td></tr>' +
617 '<tr><td data-sort-value="E">A</td></tr>' +
618 '<tr><td>B</td></tr>' +
619 '<tr><td>G</td></tr>' +
620 '<tr><td data-sort-value="F">C</td></tr>' +
621 '</tbody></table>'
622 );
623 $table.tablesorter().find( '.headerSort:eq(0)' ).click();
624
625 data = [];
626 $table.find( 'tbody > tr' ).each( function ( i, tr ) {
627 $( tr ).find( 'td' ).each( function ( i, td ) {
628 data.push( {
629 data: $( td ).data( 'sortValue' ),
630 text: $( td ).text()
631 } );
632 });
633 });
634
635 assert.deepEqual( data, [
636 {
637 data: undefined,
638 text: 'B'
639 }, {
640 data: undefined,
641 text: 'D'
642 }, {
643 data: 'E',
644 text: 'A'
645 }, {
646 data: 'F',
647 text: 'C'
648 }, {
649 data: undefined,
650 text: 'G'
651 }
652 ], 'Order matches expected order (based on data-sort-value attribute values)' );
653
654 // Example 3: Test that live changes are used from data-sort-value,
655 // even if they change after the tablesorter is constructed (bug 38152).
656 $table = $(
657 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
658 '<tbody>' +
659 '<tr><td>D</td></tr>' +
660 '<tr><td data-sort-value="1">A</td></tr>' +
661 '<tr><td>B</td></tr>' +
662 '<tr><td data-sort-value="2">G</td></tr>' +
663 '<tr><td>C</td></tr>' +
664 '</tbody></table>'
665 );
666 // initialize table sorter and sort once
667 $table
668 .tablesorter()
669 .find( '.headerSort:eq(0)' ).click();
670
671 // Change the sortValue data properties (bug 38152)
672 // - change data
673 $table.find( 'td:contains(A)' ).data( 'sortValue', 3 );
674 // - add data
675 $table.find( 'td:contains(B)' ).data( 'sortValue', 1 );
676 // - remove data, bring back attribute: 2
677 $table.find( 'td:contains(G)' ).removeData( 'sortValue' );
678
679 // Now sort again (twice, so it is back at Ascending)
680 $table.find( '.headerSort:eq(0)' ).click();
681 $table.find( '.headerSort:eq(0)' ).click();
682
683 data = [];
684 $table.find( 'tbody > tr' ).each( function( i, tr ) {
685 $( tr ).find( 'td' ).each( function( i, td ) {
686 data.push( {
687 data: $( td ).data( 'sortValue' ),
688 text: $( td ).text()
689 } );
690 });
691 });
692
693 assert.deepEqual( data, [
694 {
695 data: 1,
696 text: "B"
697 }, {
698 data: 2,
699 text: "G"
700 }, {
701 data: 3,
702 text: "A"
703 }, {
704 data: undefined,
705 text: "C"
706 }, {
707 data: undefined,
708 text: "D"
709 }
710 ], 'Order matches expected order, using the current sortValue in $.data()' );
711
712 });
713
714 var numbers = [
715 [ '12' ],
716 [ '7' ],
717 [ '13,000'],
718 [ '9' ],
719 [ '14' ],
720 [ '8.0' ]
721 ];
722 var numbersAsc = [
723 [ '7' ],
724 [ '8.0' ],
725 [ '9' ],
726 [ '12' ],
727 [ '14' ],
728 [ '13,000']
729 ];
730
731 tableTest( 'bug 8115: sort numbers with commas (ascending)',
732 ['Numbers'], numbers, numbersAsc,
733 function( $table ) {
734 $table.tablesorter();
735 $table.find( '.headerSort:eq(0)' ).click();
736 }
737 );
738
739 tableTest( 'bug 8115: sort numbers with commas (descending)',
740 ['Numbers'], numbers, reversed(numbersAsc),
741 function( $table ) {
742 $table.tablesorter();
743 $table.find( '.headerSort:eq(0)' ).click().click();
744 }
745 );
746 // TODO add numbers sorting tests for bug 8115 with a different language
747
748 QUnit.test( 'bug 32888 - Tables inside a tableheader cell', 2, function ( assert ) {
749 var $table;
750 $table = $(
751 '<table class="sortable" id="mw-bug-32888">' +
752 '<tr><th>header<table id="mw-bug-32888-2">'+
753 '<tr><th>1</th><th>2</th></tr>' +
754 '</table></th></tr>' +
755 '<tr><td>A</td></tr>' +
756 '<tr><td>B</td></tr>' +
757 '</table>'
758 );
759 $table.tablesorter();
760
761 assert.equal(
762 $table.find('> thead:eq(0) > tr > th.headerSort').length,
763 1,
764 'Child tables inside a headercell should not interfere with sortable headers (bug 32888)'
765 );
766 assert.equal(
767 $( '#mw-bug-32888-2' ).find('th.headerSort').length,
768 0,
769 'The headers of child tables inside a headercell should not be sortable themselves (bug 32888)'
770 );
771 });
772
773
774 var correctDateSorting1 = [
775 ['01 January 2010'],
776 ['05 February 2010'],
777 ['16 January 2010']
778 ];
779
780 var correctDateSortingSorted1 = [
781 ['01 January 2010'],
782 ['16 January 2010'],
783 ['05 February 2010']
784 ];
785
786 tableTest(
787 'Correct date sorting I',
788 ['date'],
789 correctDateSorting1,
790 correctDateSortingSorted1,
791 function ( $table ) {
792 mw.config.set( 'wgDefaultDateFormat', 'mdy' );
793
794 $table.tablesorter();
795 $table.find( '.headerSort:eq(0)' ).click();
796 }
797 );
798
799 var correctDateSorting2 = [
800 ['January 01 2010'],
801 ['February 05 2010'],
802 ['January 16 2010']
803 ];
804
805 var correctDateSortingSorted2 = [
806 ['January 01 2010'],
807 ['January 16 2010'],
808 ['February 05 2010']
809 ];
810
811 tableTest(
812 'Correct date sorting II',
813 ['date'],
814 correctDateSorting2,
815 correctDateSortingSorted2,
816 function ( $table ) {
817 mw.config.set( 'wgDefaultDateFormat', 'dmy' );
818
819 $table.tablesorter();
820 $table.find( '.headerSort:eq(0)' ).click();
821 }
822 );
823
824 }( jQuery, mediaWiki ) );