Merge "(bug 42097) $.tablesorter fix when wgDefaultDateFormat is unrecognized"
[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 QUnit.test( 'Rowspan not exploded on init', 1, function ( assert ) {
397 var $table = tableCreate( header, planets );
398
399 // Modify the table to have a multiple-row-spanning cell:
400 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
401 $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
402 // - Set rowspan for 2nd cell of 3rd row to 3.
403 // This covers the removed cell in the 4th and 5th row.
404 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
405
406 $table.tablesorter();
407
408 assert.equal(
409 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan' ),
410 3,
411 'Rowspan not exploded'
412 );
413 });
414
415 var planetsRowspan = [ [ 'Earth', '6051.8' ], jupiter, [ 'Mars', '6051.8' ], mercury, saturn, venus ];
416 var planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ];
417
418 tableTest(
419 'Basic planet table: same value for multiple rows via rowspan',
420 header,
421 planets,
422 planetsRowspan,
423 function ( $table ) {
424 // Modify the table to have a multiple-row-spanning cell:
425 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
426 $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
427 // - Set rowspan for 2nd cell of 3rd row to 3.
428 // This covers the removed cell in the 4th and 5th row.
429 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
430
431 $table.tablesorter();
432 $table.find( '.headerSort:eq(0)' ).click();
433 }
434 );
435 tableTest(
436 'Basic planet table: same value for multiple rows via rowspan (sorting initially)',
437 header,
438 planets,
439 planetsRowspan,
440 function ( $table ) {
441 // Modify the table to have a multiple-row-spanning cell:
442 // - Remove 2nd cell of 4th row, and, 2nd cell or 5th row.
443 $table.find( 'tr:eq(3) td:eq(1), tr:eq(4) td:eq(1)' ).remove();
444 // - Set rowspan for 2nd cell of 3rd row to 3.
445 // This covers the removed cell in the 4th and 5th row.
446 $table.find( 'tr:eq(2) td:eq(1)' ).prop( 'rowspan', '3' );
447
448 $table.tablesorter( { sortList: [ { 0: 'asc' } ] } );
449 }
450 );
451 tableTest(
452 'Basic planet table: Same value for multiple rows via rowspan II',
453 header,
454 planets,
455 planetsRowspanII,
456 function ( $table ) {
457 // Modify the table to have a multiple-row-spanning cell:
458 // - Remove 1st cell of 4th row, and, 1st cell or 5th row.
459 $table.find( 'tr:eq(3) td:eq(0), tr:eq(4) td:eq(0)' ).remove();
460 // - Set rowspan for 1st cell of 3rd row to 3.
461 // This covers the removed cell in the 4th and 5th row.
462 $table.find( 'tr:eq(2) td:eq(0)' ).prop( 'rowspan', '3' );
463
464 $table.tablesorter();
465 $table.find( '.headerSort:eq(0)' ).click();
466 }
467 );
468
469 var complexMDYDates = [
470 // Some words with Umlauts
471 ['January, 19 2010'],
472 ['April 21 1991'],
473 ['04 22 1991'],
474 ['5.12.1990'],
475 ['December 12 \'10']
476 ];
477
478 var complexMDYSorted = [
479 ['5.12.1990'],
480 ['April 21 1991'],
481 ['04 22 1991'],
482 ['January, 19 2010'],
483 ['December 12 \'10']
484 ];
485
486 tableTest(
487 'Complex date parsing I',
488 ['date'],
489 complexMDYDates,
490 complexMDYSorted,
491 function ( $table ) {
492 mw.config.set( 'wgDefaultDateFormat', 'mdy' );
493
494 $table.tablesorter();
495 $table.find( '.headerSort:eq(0)' ).click();
496 }
497 );
498
499 var currencyUnsorted = [
500 ['1.02 $'],
501 ['$ 3.00'],
502 ['€ 2,99'],
503 ['$ 1.00'],
504 ['$3.50'],
505 ['$ 1.50'],
506 ['€ 0.99']
507 ];
508
509 var currencySorted = [
510 ['€ 0.99'],
511 ['$ 1.00'],
512 ['1.02 $'],
513 ['$ 1.50'],
514 ['$ 3.00'],
515 ['$3.50'],
516 // Comma's sort after dots
517 // Not intentional but test to detect changes
518 ['€ 2,99']
519 ];
520
521 tableTest(
522 'Currency parsing I',
523 ['currency'],
524 currencyUnsorted,
525 currencySorted,
526 function ( $table ) {
527 $table.tablesorter();
528 $table.find( '.headerSort:eq(0)' ).click();
529 }
530 );
531
532 var ascendingNameLegacy = ascendingName.slice(0);
533 ascendingNameLegacy[4] = ascendingNameLegacy[5];
534 ascendingNameLegacy.pop();
535
536 tableTest(
537 'Legacy compat with .sortbottom',
538 header,
539 planets,
540 ascendingNameLegacy,
541 function( $table ) {
542 $table.find( 'tr:last' ).addClass( 'sortbottom' );
543 $table.tablesorter();
544 $table.find( '.headerSort:eq(0)' ).click();
545 }
546 );
547
548 QUnit.test( 'Test detection routine', function ( assert ) {
549 var $table;
550 $table = $(
551 '<table class="sortable">' +
552 '<caption>CAPTION</caption>' +
553 '<tr><th>THEAD</th></tr>' +
554 '<tr><td>1</td></tr>' +
555 '<tr class="sortbottom"><td>text</td></tr>' +
556 '</table>'
557 );
558 $table.tablesorter();
559 $table.find( '.headerSort:eq(0)' ).click();
560
561 assert.equal(
562 $table.data( 'tablesorter' ).config.parsers[0].id,
563 'number',
564 'Correctly detected column content skipping sortbottom'
565 );
566 } );
567
568 /** FIXME: the diff output is not very readeable. */
569 QUnit.test( 'bug 32047 - caption must be before thead', function ( assert ) {
570 var $table;
571 $table = $(
572 '<table class="sortable">' +
573 '<caption>CAPTION</caption>' +
574 '<tr><th>THEAD</th></tr>' +
575 '<tr><td>A</td></tr>' +
576 '<tr><td>B</td></tr>' +
577 '<tr class="sortbottom"><td>TFOOT</td></tr>' +
578 '</table>'
579 );
580 $table.tablesorter();
581
582 assert.equal(
583 $table.children( ).get( 0 ).nodeName,
584 'CAPTION',
585 'First element after <thead> must be <caption> (bug 32047)'
586 );
587 });
588
589 QUnit.test( 'data-sort-value attribute, when available, should override sorting position', function ( assert ) {
590 var $table, data;
591
592 // Example 1: All cells except one cell without data-sort-value,
593 // which should be sorted at it's text content value.
594 $table = $(
595 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
596 '<tbody>' +
597 '<tr><td>Cheetah</td></tr>' +
598 '<tr><td data-sort-value="Apple">Bird</td></tr>' +
599 '<tr><td data-sort-value="Bananna">Ferret</td></tr>' +
600 '<tr><td data-sort-value="Drupe">Elephant</td></tr>' +
601 '<tr><td data-sort-value="Cherry">Dolphin</td></tr>' +
602 '</tbody></table>'
603 );
604 $table.tablesorter().find( '.headerSort:eq(0)' ).click();
605
606 data = [];
607 $table.find( 'tbody > tr' ).each( function( i, tr ) {
608 $( tr ).find( 'td' ).each( function( i, td ) {
609 data.push( {
610 data: $( td ).data( 'sortValue' ),
611 text: $( td ).text()
612 } );
613 });
614 });
615
616 assert.deepEqual( data, [
617 {
618 data: 'Apple',
619 text: 'Bird'
620 }, {
621 data: 'Bananna',
622 text: 'Ferret'
623 }, {
624 data: undefined,
625 text: 'Cheetah'
626 }, {
627 data: 'Cherry',
628 text: 'Dolphin'
629 }, {
630 data: 'Drupe',
631 text: 'Elephant'
632 }
633 ], 'Order matches expected order (based on data-sort-value attribute values)' );
634
635 // Example 2
636 $table = $(
637 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
638 '<tbody>' +
639 '<tr><td>D</td></tr>' +
640 '<tr><td data-sort-value="E">A</td></tr>' +
641 '<tr><td>B</td></tr>' +
642 '<tr><td>G</td></tr>' +
643 '<tr><td data-sort-value="F">C</td></tr>' +
644 '</tbody></table>'
645 );
646 $table.tablesorter().find( '.headerSort:eq(0)' ).click();
647
648 data = [];
649 $table.find( 'tbody > tr' ).each( function ( i, tr ) {
650 $( tr ).find( 'td' ).each( function ( i, td ) {
651 data.push( {
652 data: $( td ).data( 'sortValue' ),
653 text: $( td ).text()
654 } );
655 });
656 });
657
658 assert.deepEqual( data, [
659 {
660 data: undefined,
661 text: 'B'
662 }, {
663 data: undefined,
664 text: 'D'
665 }, {
666 data: 'E',
667 text: 'A'
668 }, {
669 data: 'F',
670 text: 'C'
671 }, {
672 data: undefined,
673 text: 'G'
674 }
675 ], 'Order matches expected order (based on data-sort-value attribute values)' );
676
677 // Example 3: Test that live changes are used from data-sort-value,
678 // even if they change after the tablesorter is constructed (bug 38152).
679 $table = $(
680 '<table class="sortable"><thead><tr><th>Data</th></tr></thead>' +
681 '<tbody>' +
682 '<tr><td>D</td></tr>' +
683 '<tr><td data-sort-value="1">A</td></tr>' +
684 '<tr><td>B</td></tr>' +
685 '<tr><td data-sort-value="2">G</td></tr>' +
686 '<tr><td>C</td></tr>' +
687 '</tbody></table>'
688 );
689 // initialize table sorter and sort once
690 $table
691 .tablesorter()
692 .find( '.headerSort:eq(0)' ).click();
693
694 // Change the sortValue data properties (bug 38152)
695 // - change data
696 $table.find( 'td:contains(A)' ).data( 'sortValue', 3 );
697 // - add data
698 $table.find( 'td:contains(B)' ).data( 'sortValue', 1 );
699 // - remove data, bring back attribute: 2
700 $table.find( 'td:contains(G)' ).removeData( 'sortValue' );
701
702 // Now sort again (twice, so it is back at Ascending)
703 $table.find( '.headerSort:eq(0)' ).click();
704 $table.find( '.headerSort:eq(0)' ).click();
705
706 data = [];
707 $table.find( 'tbody > tr' ).each( function( i, tr ) {
708 $( tr ).find( 'td' ).each( function( i, td ) {
709 data.push( {
710 data: $( td ).data( 'sortValue' ),
711 text: $( td ).text()
712 } );
713 });
714 });
715
716 assert.deepEqual( data, [
717 {
718 data: 1,
719 text: 'B'
720 }, {
721 data: 2,
722 text: 'G'
723 }, {
724 data: 3,
725 text: 'A'
726 }, {
727 data: undefined,
728 text: 'C'
729 }, {
730 data: undefined,
731 text: 'D'
732 }
733 ], 'Order matches expected order, using the current sortValue in $.data()' );
734
735 });
736
737 var numbers = [
738 [ '12' ],
739 [ '7' ],
740 [ '13,000'],
741 [ '9' ],
742 [ '14' ],
743 [ '8.0' ]
744 ];
745 var numbersAsc = [
746 [ '7' ],
747 [ '8.0' ],
748 [ '9' ],
749 [ '12' ],
750 [ '14' ],
751 [ '13,000']
752 ];
753
754 tableTest( 'bug 8115: sort numbers with commas (ascending)',
755 ['Numbers'], numbers, numbersAsc,
756 function( $table ) {
757 $table.tablesorter();
758 $table.find( '.headerSort:eq(0)' ).click();
759 }
760 );
761
762 tableTest( 'bug 8115: sort numbers with commas (descending)',
763 ['Numbers'], numbers, reversed(numbersAsc),
764 function( $table ) {
765 $table.tablesorter();
766 $table.find( '.headerSort:eq(0)' ).click().click();
767 }
768 );
769 // TODO add numbers sorting tests for bug 8115 with a different language
770
771 QUnit.test( 'bug 32888 - Tables inside a tableheader cell', 2, function ( assert ) {
772 var $table;
773 $table = $(
774 '<table class="sortable" id="mw-bug-32888">' +
775 '<tr><th>header<table id="mw-bug-32888-2">'+
776 '<tr><th>1</th><th>2</th></tr>' +
777 '</table></th></tr>' +
778 '<tr><td>A</td></tr>' +
779 '<tr><td>B</td></tr>' +
780 '</table>'
781 );
782 $table.tablesorter();
783
784 assert.equal(
785 $table.find('> thead:eq(0) > tr > th.headerSort').length,
786 1,
787 'Child tables inside a headercell should not interfere with sortable headers (bug 32888)'
788 );
789 assert.equal(
790 $( '#mw-bug-32888-2' ).find('th.headerSort').length,
791 0,
792 'The headers of child tables inside a headercell should not be sortable themselves (bug 32888)'
793 );
794 });
795
796
797 var correctDateSorting1 = [
798 ['01 January 2010'],
799 ['05 February 2010'],
800 ['16 January 2010']
801 ];
802
803 var correctDateSortingSorted1 = [
804 ['01 January 2010'],
805 ['16 January 2010'],
806 ['05 February 2010']
807 ];
808
809 tableTest(
810 'Correct date sorting I',
811 ['date'],
812 correctDateSorting1,
813 correctDateSortingSorted1,
814 function ( $table ) {
815 mw.config.set( 'wgDefaultDateFormat', 'mdy' );
816
817 $table.tablesorter();
818 $table.find( '.headerSort:eq(0)' ).click();
819 }
820 );
821
822 var correctDateSorting2 = [
823 ['January 01 2010'],
824 ['February 05 2010'],
825 ['January 16 2010']
826 ];
827
828 var correctDateSortingSorted2 = [
829 ['January 01 2010'],
830 ['January 16 2010'],
831 ['February 05 2010']
832 ];
833
834 tableTest(
835 'Correct date sorting II',
836 ['date'],
837 correctDateSorting2,
838 correctDateSortingSorted2,
839 function ( $table ) {
840 mw.config.set( 'wgDefaultDateFormat', 'dmy' );
841
842 $table.tablesorter();
843 $table.find( '.headerSort:eq(0)' ).click();
844 }
845 );
846
847 }( jQuery, mediaWiki ) );