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