jquery.tablesorter: Support sortable column headers with rowspans
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.tablesorter.test.js
index 7c8503b..d23bfc3 100644 (file)
                        $table.find( '.headerSort:eq(0)' ).click();
                }
        );
+       tableTest(
+               'Basic planet table: ascending by name (multiple clicks)',
+               header,
+               planets,
+               ascendingName,
+               function ( $table ) {
+                       $table.tablesorter();
+                       $table.find( '.headerSort:eq(0)' ).click();
+                       $table.find( '.headerSort:eq(1)' ).click();
+                       $table.find( '.headerSort:eq(0)' ).click();
+               }
+       );
        tableTest(
                'Basic planet table: descending by name',
                header,
                        $table.data( 'tablesorter' ).sort();
                }
        );
+       tableTest(
+               'Sort via click event after having initialized the tablesorter with initial sorting',
+               header,
+               initial,
+               descasc,
+               function ( $table ) {
+                       $table.tablesorter(
+                               { sortList: [ { 0: 'asc' }, { 1: 'asc' } ] }
+                       );
+                       $table.find( '.headerSort:eq(0)' ).click();
+               }
+       );
+       tableTest(
+               'Multi-sort via click event after having initialized the tablesorter with initial sorting',
+               header,
+               initial,
+               asc,
+               function ( $table ) {
+                       $table.tablesorter(
+                               { sortList: [ { 0: 'desc' }, { 1: 'desc' } ] }
+                       );
+                       $table.find( '.headerSort:eq(0)' ).click();
+
+                       // Pretend to click while pressing the multi-sort key
+                       var event = $.Event( 'click' );
+                       event[$table.data( 'tablesorter' ).config.sortMultiSortKey] = true;
+                       $table.find( '.headerSort:eq(1)' ).trigger( event );
+               }
+       );
        QUnit.test( 'Reset sorting making table appear unsorted', 3, function ( assert ) {
                var $table = tableCreate( header, initial );
                $table.tablesorter(
                        $table.find( '.headerSort:eq(0)' ).click();
                }
        );
+       tableTest( 'Sorting with colspanned headers: sort spanned column twice',
+               header,
+               initial,
+               [ caa4, bbc2, abc3, aab5, aaa1 ],
+               function ( $table ) {
+                       // Make colspanned header for test
+                       $table.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
+                       $table.find( 'tr:eq(0) th:eq(0)' ).prop( 'colspan', '3' );
+
+                       $table.tablesorter();
+                       $table.find( '.headerSort:eq(0)' ).click();
+                       $table.find( '.headerSort:eq(0)' ).click();
+               }
+       );
        tableTest( 'Sorting with colspanned headers: subsequent column',
                header,
                initial,
                        $table.find( '.headerSort:eq(1)' ).click();
                }
        );
+       tableTest( 'Sorting with colspanned headers: sort subsequent column twice',
+               header,
+               initial,
+               [ aab5, caa4, abc3, bbc2, aaa1 ],
+               function ( $table ) {
+                       // Make colspanned header for test
+                       $table.find( 'tr:eq(0) th:eq(1), tr:eq(0) th:eq(2)' ).remove();
+                       $table.find( 'tr:eq(0) th:eq(0)' ).prop( 'colspan', '3' );
+
+                       $table.tablesorter();
+                       $table.find( '.headerSort:eq(1)' ).click();
+                       $table.find( '.headerSort:eq(1)' ).click();
+               }
+       );
+
 
        // Regression tests!
        tableTest(
                );
        } );
 
+       QUnit.test( 'bug 38911 - The row with the largest amount of columns should receive the sort indicators', 3, function ( assert ) {
+               var $table = $(
+                       '<table class="sortable">' +
+                               '<thead>' +
+                               '<tr><th rowspan="2" id="A1">A1</th><th colspan="2">B2a</th></tr>' +
+                               '<tr><th id="B2b">B2b</th><th id="C2b">C2b</th></tr>' +
+                               '</thead>' +
+                               '<tr><td>A</td><td>Aa</td><td>Ab</td></tr>' +
+                               '<tr><td>B</td><td>Ba</td><td>Bb</td></tr>' +
+                               '</table>'
+               );
+               $table.tablesorter();
+
+               assert.equal(
+                       $table.find( '#A1' ).attr( 'class' ),
+                       'headerSort',
+                       'The first column of the first row should be sortable'
+               );
+               assert.equal(
+                       $table.find( '#B2b' ).attr( 'class' ),
+                       'headerSort',
+                       'The th element of the 2nd row of the 2nd column should be sortable'
+               );
+               assert.equal(
+                       $table.find( '#C2b' ).attr( 'class' ),
+                       'headerSort',
+                       'The th element of the 2nd row of the 3rd column should be sortable'
+               );
+       } );
+
+       QUnit.test( 'rowspans in table headers should prefer the last row when rows are equal in length', 2, function ( assert ) {
+               var $table = $(
+                       '<table class="sortable">' +
+                               '<thead>' +
+                               '<tr><th rowspan="2" id="A1">A1</th><th>B2a</th></tr>' +
+                               '<tr><th id="B2b">B2b</th></tr>' +
+                               '</thead>' +
+                               '<tr><td>A</td><td>Aa</td></tr>' +
+                               '<tr><td>B</td><td>Ba</td></tr>' +
+                               '</table>'
+               );
+               $table.tablesorter();
+
+               assert.equal(
+                       $table.find( '#A1' ).attr( 'class' ),
+                       'headerSort',
+                       'The first column of the first row should be sortable'
+               );
+               assert.equal(
+                       $table.find( '#B2b' ).attr( 'class' ),
+                       'headerSort',
+                       'The th element of the 2nd row of the 2nd column should be sortable'
+               );
+       } );
+
        // bug 41889 - exploding rowspans in more complex cases
        tableTestHTML(
                'Rowspan exploding with row headers',