Merge "SpecialMostlinkedCategories: Use LinkRenderer instead of Linker::link()"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.tablesorter.test.js
index 759322a..ca26aaf 100644 (file)
@@ -1,5 +1,19 @@
 ( function ( $, mw ) {
-       var header,
+       var header = [ 'Planet', 'Radius (km)' ],
+
+               // Data set "planets"
+               mercury = [ 'Mercury', '2439.7' ],
+               venus = [ 'Venus', '6051.8' ],
+               earth = [ 'Earth', '6371.0' ],
+               mars = [ 'Mars', '3390.0' ],
+               jupiter = [ 'Jupiter', '69911' ],
+               saturn = [ 'Saturn', '58232' ],
+               planets = [ mercury, venus, earth, mars, jupiter, saturn ],
+               planetsAscName = [ earth, jupiter, mars, mercury, saturn, venus ],
+               planetsAscRadius = [ mercury, mars, venus, earth, saturn, jupiter ],
+               planetsRowspan,
+               planetsRowspanII,
+               planetsAscNameLegacy,
 
                // Data set "simple"
                a1 = [ 'A', '1' ],
@@ -13,6 +27,7 @@
                simpleDescasc = [ b1, b2, b3, a1, a2, a3 ],
 
                // Data set "colspan"
+               header4 = [ 'column1a', 'column1b', 'column1c', 'column2' ],
                aaa1 = [ 'A', 'A', 'A', '1' ],
                aab5 = [ 'A', 'A', 'B', '5' ],
                abc3 = [ 'A', 'B', 'C', '3' ],
                caa4 = [ 'C', 'A', 'A', '4' ],
                colspanInitial = [ aab5, aaa1, abc3, bbc2, caa4 ],
 
-               // Data set "planets"
-               mercury = [ 'Mercury', '2439.7' ],
-               venus = [ 'Venus', '6051.8' ],
-               earth = [ 'Earth', '6371.0' ],
-               mars = [ 'Mars', '3390.0' ],
-               jupiter = [ 'Jupiter', '69911' ],
-               saturn = [ 'Saturn', '58232' ],
-               planets = [ mercury, venus, earth, mars, jupiter, saturn ],
-               planetsAscName = [ earth, jupiter, mars, mercury, saturn, venus ],
-               planetsAscRadius = [ mercury, mars, venus, earth, saturn, jupiter ],
-               planetsRowspan,
-               planetsRowspanII,
-               planetsAscNameLegacy,
-
                // Data set "ipv4"
                ipv4 = [
                        // Some randomly generated fake IPs
                        [ 'Strasse' ]
                ],
 
+               // Data set "digraph"
+               digraphWords = [
+                       [ 'London' ],
+                       [ 'Ljubljana' ],
+                       [ 'Luxembourg' ],
+                       [ 'Njivice' ],
+                       [ 'Norwich' ],
+                       [ 'New York' ]
+               ],
+               digraphWordsSorted = [
+                       [ 'London' ],
+                       [ 'Luxembourg' ],
+                       [ 'Ljubljana' ],
+                       [ 'New York' ],
+                       [ 'Norwich' ],
+                       [ 'Njivice' ]
+               ],
+
                complexMDYDates = [
                        [ 'January, 19 2010' ],
                        [ 'April 21 1991' ],
                        [ 'January 01 2010' ],
                        [ 'January 16 2010' ],
                        [ 'February 05 2010' ]
+               ],
+               isoDateSorting = [
+                       [ '2010-02-01' ],
+                       [ '2009-12-25T12:30:45.001Z' ],
+                       [ '2010-01-31' ],
+                       [ '2009' ],
+                       [ '2009-12-25T12:30:45' ],
+                       [ '2009-12-25T12:30:45.111' ],
+                       [ '2009-12-25T12:30:45+01:00' ]
+               ],
+               isoDateSortingSorted = [
+                       [ '2009' ],
+                       [ '2009-12-25T12:30:45' ],
+                       [ '2009-12-25T12:30:45+01:00' ],
+                       [ '2009-12-25T12:30:45.001Z' ],
+                       [ '2009-12-25T12:30:45.111' ],
+                       [ '2010-01-31' ],
+                       [ '2010-02-01' ]
                ];
 
        QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment( {
         * Create an HTML table from an array of row arrays containing text strings.
         * First row will be header row. No fancy rowspan/colspan stuff.
         *
-        * @param {String[]} header
-        * @param {String[][]} data
+        * @param {string[]} header
+        * @param {string[][]} data
         * @return {jQuery}
         */
        function tableCreate( header, data ) {
         * Extract text from table.
         *
         * @param {jQuery} $table
-        * @return {String[][]}
+        * @return {string[][]}
         */
        function tableExtract( $table ) {
                var data = [];
         * Run a table test by building a table with the given data,
         * running some callback on it, then checking the results.
         *
-        * @param {String} msg text to pass on to qunit for the comparison
-        * @param {String[]} header cols to make the table
-        * @param {String[][]} data rows/cols to make the table
-        * @param {String[][]} expected rows/cols to compare against at end
+        * @param {string} msg text to pass on to qunit for the comparison
+        * @param {string[]} header cols to make the table
+        * @param {string[][]} data rows/cols to make the table
+        * @param {string[][]} expected rows/cols to compare against at end
         * @param {function($table)} callback something to do with the table before we compare
         */
        function tableTest( msg, header, data, expected, callback ) {
         * Run a table test by building a table with the given HTML,
         * running some callback on it, then checking the results.
         *
-        * @param {String} msg text to pass on to qunit for the comparison
-        * @param {String} HTML to make the table
-        * @param {String[][]} expected rows/cols to compare against at end
-        * @param {function($table)} callback something to do with the table before we compare
+        * @param {string} msg text to pass on to qunit for the comparison
+        * @param {string} html HTML to make the table
+        * @param {string[][]} expected Rows/cols to compare against at end
+        * @param {function($table)} callback Something to do with the table before we compare
         */
        function tableTestHTML( msg, html, expected, callback ) {
                QUnit.test( msg, 1, function ( assert ) {
        }
 
        // Sample data set using planets named and their radius
-       header = [ 'Planet', 'Radius (km)' ];
 
        tableTest(
                'Basic planet table: sorting initially - ascending by name',
                        $table.find( '.headerSort:eq(1)' ).click().click();
                }
        );
-
-       header = [ 'column1', 'column2' ];
-
        tableTest(
                'Sorting multiple columns by passing sort list',
                header,
        } );
 
        // Sorting with colspans
-       header = [ 'column1a', 'column1b', 'column1c', 'column2' ];
 
        tableTest( 'Sorting with colspanned headers: spanned column',
-               header,
+               header4,
                colspanInitial,
                [ aaa1, aab5, abc3, bbc2, caa4 ],
                function ( $table ) {
                }
        );
        tableTest( 'Sorting with colspanned headers: sort spanned column twice',
-               header,
+               header4,
                colspanInitial,
                [ caa4, bbc2, abc3, aab5, aaa1 ],
                function ( $table ) {
                }
        );
        tableTest( 'Sorting with colspanned headers: subsequent column',
-               header,
+               header4,
                colspanInitial,
                [ aaa1, bbc2, abc3, caa4, aab5 ],
                function ( $table ) {
                }
        );
        tableTest( 'Sorting with colspanned headers: sort subsequent column twice',
-               header,
+               header4,
                colspanInitial,
                [ aab5, caa4, abc3, bbc2, aaa1 ],
                function ( $table ) {
                }
        );
 
-       tableTest(
-               'Basic planet table: one unsortable column',
-               header,
-               planets,
-               planets,
-               function ( $table ) {
-                       $table.find( 'tr:eq(0) > th:eq(0)' ).addClass( 'unsortable' );
+       QUnit.test( 'Basic planet table: one unsortable column', 3, function ( assert ) {
+               var $table = tableCreate( header, planets ),
+                       $cell;
+               $table.find( 'tr:eq(0) > th:eq(0)' ).addClass( 'unsortable' );
 
-                       $table.tablesorter();
-                       $table.find( 'tr:eq(0) > th:eq(0)' ).click();
-               }
-       );
+               $table.tablesorter();
+               $table.find( 'tr:eq(0) > th:eq(0)' ).click();
+
+               assert.deepEqual(
+                       tableExtract( $table ),
+                       planets,
+                       'table not sorted'
+               );
+
+               $cell = $table.find( 'tr:eq(0) > th:eq(0)' );
+               $table.find( 'tr:eq(0) > th:eq(1)' ).click();
+
+               assert.equal(
+                       $cell.hasClass( 'headerSortUp' ) || $cell.hasClass( 'headerSortDown' ),
+                       false,
+                       'after sort: no class headerSortUp or headerSortDown'
+               );
+
+               assert.equal(
+                       $cell.attr( 'title' ),
+                       undefined,
+                       'after sort: no title tag added'
+               );
+
+       } );
 
        // Regression tests!
        tableTest(
                }
        );
 
+       tableTest(
+               'Digraphs with custom collation',
+               [ 'City' ],
+               digraphWords,
+               digraphWordsSorted,
+               function ( $table ) {
+                       mw.config.set( 'tableSorterCollation', {
+                               lj: 'lzzzz',
+                               nj: 'nzzzz'
+                       } );
+
+                       $table.tablesorter();
+                       $table.find( '.headerSort:eq(0)' ).click();
+               }
+       );
+
        QUnit.test( 'Rowspan not exploded on init', 1, function ( assert ) {
                var $table = tableCreate( header, planets );
 
                }
        );
 
+       tableTest(
+               'ISO date sorting',
+               [ 'isoDate' ],
+               isoDateSorting,
+               isoDateSortingSorted,
+               function ( $table ) {
+                       mw.config.set( 'wgDefaultDateFormat', 'dmy' );
+
+                       $table.tablesorter();
+                       $table.find( '.headerSort:eq(0)' ).click();
+               }
+       );
+
        QUnit.test( 'Sorting images using alt text', 1, function ( assert ) {
                var $table = $(
                        '<table class="sortable">' +
        tableTestHTML(
                'Rowspan exploding with colspanned cells (2)',
                '<table class="sortable">' +
-                       '<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th><th>quux</th></tr></thead>' +
+                       '<thead><tr><th>n</th><th>foo</th><th>bar</th><th>baz</th><th id="sortme">n2</th></tr></thead>' +
                        '<tbody>' +
-                       '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td><td>quux</td></tr>' +
-                       '<tr><td>2</td><td colspan="2">foobar</td><td>quux</td></tr>' +
+                       '<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td><td>2</td></tr>' +
+                       '<tr><td>2</td><td colspan="2">foobar</td><td>1</td></tr>' +
                        '</tbody></table>',
                [
-                       [ '1', 'foo', 'bar', 'baz', 'quux' ],
-                       [ '2', 'foobar', 'baz', 'quux' ]
+                       [ '2', 'foobar', 'baz', '1' ],
+                       [ '1', 'foo', 'bar', 'baz', '2' ]
                ]
        );
 
                ]
        );
 
+       QUnit.test( 'bug 105731 - incomplete rows in table body', 3, function ( assert ) {
+               var $table, parsers;
+               $table = $(
+                       '<table class="sortable">' +
+                               '<tr><th>A</th><th>B</th></tr>' +
+                               '<tr><td>3</td></tr>' +
+                               '<tr><td>1</td><td>2</td></tr>' +
+                               '</table>'
+               );
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+               // now the first row have 2 columns
+               $table.find( '.headerSort:eq(1)' ).click();
+
+               parsers = $table.data( 'tablesorter' ).config.parsers;
+
+               assert.equal(
+                       parsers.length,
+                       2,
+                       'detectParserForColumn() detect 2 parsers'
+               );
+
+               assert.equal(
+                       parsers[ 1 ].id,
+                       'number',
+                       'detectParserForColumn() detect parser.id "number" for second column'
+               );
+
+               assert.equal(
+                       parsers[ 1 ].format( $table.find( 'tbody > tr > td:eq(1)' ).text() ),
+                       0,
+                       'empty cell is sorted as number 0'
+               );
+       } );
+
+       QUnit.test( 'bug T114721 - use of expand-child class', 2, function ( assert ) {
+               var $table, parsers;
+               $table = $(
+                       '<table class="sortable">' +
+                               '<tr><th>A</th><th>B</th></tr>' +
+                               '<tr><td>b</td><td>4</td></tr>' +
+                               '<tr class="expand-child"><td colspan="2">some text follow b</td></tr>' +
+                               '<tr><td>a</td><td>2</td></tr>' +
+                               '<tr class="expand-child"><td colspan="2">some text follow a</td></tr>' +
+                               '<tr class="expand-child"><td colspan="2">more text</td></tr>' +
+                               '</table>'
+               );
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+
+               assert.deepEqual(
+                       tableExtract( $table ),
+                       [
+                               [ 'a', '2' ],
+                               [ 'some text follow a' ],
+                               [ 'more text' ],
+                               [ 'b', '4' ],
+                               [ 'some text follow b' ]
+                       ],
+                       'row with expand-child class follow above row'
+               );
+
+               parsers = $table.data( 'tablesorter' ).config.parsers;
+               assert.equal(
+                       parsers[ 1 ].id,
+                       'number',
+                       'detectParserForColumn() detect parser.id "number" for second column'
+               );
+       } );
+
 }( jQuery, mediaWiki ) );