From: Timo Tijhof Date: Thu, 30 Jan 2014 03:56:22 +0000 (-0800) Subject: jquery.tablesorter.test: Re-organise variables X-Git-Tag: 1.31.0-rc.0~16801^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=878c57e3945d2bf0f8faa8259106e3200c3a2d09;p=lhc%2Fweb%2Fwiklou.git jquery.tablesorter.test: Re-organise variables * Remove inline /*jshint onevar:false */ rule. Change-Id: I5980f56c8878d66af3d11e60aa7b31fa7bca41fd --- diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index f73fd7bfce..fe174ce377 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -1,7 +1,161 @@ ( function ( $, mw ) { - /*jshint onevar: false */ + var config, header, - var config = { + // Data set "simple" + a1 = [ 'A', '1' ], + a2 = [ 'A', '2' ], + a3 = [ 'A', '3' ], + b1 = [ 'B', '1' ], + b2 = [ 'B', '2' ], + b3 = [ 'B', '3' ], + simple = [a2, b3, a1, a3, b2, b1], + simpleAsc = [a1, a2, a3, b1, b2, b3], + simpleDescasc = [b1, b2, b3, a1, a2, a3], + + // Data set "colspan" + aaa1 = [ 'A', 'A', 'A', '1' ], + aab5 = [ 'A', 'A', 'B', '5' ], + abc3 = [ 'A', 'B', 'C', '3' ], + bbc2 = [ 'B', 'B', 'C', '2' ], + 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 + ['45.238.27.109'], + ['44.172.9.22'], + ['247.240.82.209'], + ['204.204.132.158'], + ['170.38.91.162'], + ['197.219.164.9'], + ['45.68.154.72'], + ['182.195.149.80'] + ], + ipv4Sorted = [ + // Sort order should go octet by octet + ['44.172.9.22'], + ['45.68.154.72'], + ['45.238.27.109'], + ['170.38.91.162'], + ['182.195.149.80'], + ['197.219.164.9'], + ['204.204.132.158'], + ['247.240.82.209'] + ], + + // Data set "umlaut" + umlautWords = [ + ['Günther'], + ['Peter'], + ['Björn'], + ['Bjorn'], + ['Apfel'], + ['Äpfel'], + ['Strasse'], + ['Sträßschen'] + ], + umlautWordsSorted = [ + ['Äpfel'], + ['Apfel'], + ['Björn'], + ['Bjorn'], + ['Günther'], + ['Peter'], + ['Sträßschen'], + ['Strasse'] + ], + + complexMDYDates = [ + ['January, 19 2010'], + ['April 21 1991'], + ['04 22 1991'], + ['5.12.1990'], + ['December 12 \'10'] + ], + complexMDYSorted = [ + ['5.12.1990'], + ['April 21 1991'], + ['04 22 1991'], + ['January, 19 2010'], + ['December 12 \'10'] + ], + + currencyUnsorted = [ + ['1.02 $'], + ['$ 3.00'], + ['€ 2,99'], + ['$ 1.00'], + ['$3.50'], + ['$ 1.50'], + ['€ 0.99'] + ], + currencySorted = [ + ['€ 0.99'], + ['$ 1.00'], + ['1.02 $'], + ['$ 1.50'], + ['$ 3.00'], + ['$3.50'], + // Comma's sort after dots + // Not intentional but test to detect changes + ['€ 2,99'] + ], + + numbers = [ + [ '12' ], + [ '7' ], + [ '13,000'], + [ '9' ], + [ '14' ], + [ '8.0' ] + ], + numbersAsc = [ + [ '7' ], + [ '8.0' ], + [ '9' ], + [ '12' ], + [ '14' ], + [ '13,000'] + ], + + correctDateSorting1 = [ + ['01 January 2010'], + ['05 February 2010'], + ['16 January 2010'] + ], + correctDateSortingSorted1 = [ + ['01 January 2010'], + ['16 January 2010'], + ['05 February 2010'] + ], + + correctDateSorting2 = [ + ['January 01 2010'], + ['February 05 2010'], + ['January 16 2010'] + ], + correctDateSortingSorted2 = [ + ['January 01 2010'], + ['January 16 2010'], + ['February 05 2010'] + ]; + + config = { wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], wgMonthNamesShort: ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], wgDefaultDateFormat: 'dmy', @@ -76,14 +230,15 @@ */ function tableTest( msg, header, data, expected, callback ) { QUnit.test( msg, 1, function ( assert ) { - var $table = tableCreate( header, data ); + var extracted, + $table = tableCreate( header, data ); // Give caller a chance to set up sorting and manipulate the table. callback( $table ); // Table sorting is done synchronously; if it ever needs to change back // to asynchronous, we'll need a timeout or a callback here. - var extracted = tableExtract( $table ); + extracted = tableExtract( $table ); assert.deepEqual( extracted, expected, msg ); } ); } @@ -99,7 +254,8 @@ */ function tableTestHTML( msg, html, expected, callback ) { QUnit.test( msg, 1, function ( assert ) { - var $table = $( html ); + var extracted, + $table = $( html ); // Give caller a chance to set up sorting and manipulate the table. if ( callback ) { @@ -111,7 +267,7 @@ // Table sorting is done synchronously; if it ever needs to change back // to asynchronous, we'll need a timeout or a callback here. - var extracted = tableExtract( $table ); + extracted = tableExtract( $table ); assert.deepEqual( extracted, expected, msg ); } ); } @@ -126,24 +282,13 @@ } // Sample data set using planets named and their radius - var header = [ 'Planet' , 'Radius (km)'], - mercury = [ 'Mercury', '2439.7' ], - venus = [ 'Venus' , '6051.8' ], - earth = [ 'Earth' , '6371.0' ], - mars = [ 'Mars' , '3390.0' ], - jupiter = [ 'Jupiter', '69911' ], - saturn = [ 'Saturn' , '58232' ]; - - // Initial data set - var planets = [mercury, venus, earth, mars, jupiter, saturn]; - var ascendingName = [earth, jupiter, mars, mercury, saturn, venus]; - var ascendingRadius = [mercury, mars, venus, earth, saturn, jupiter]; + header = [ 'Planet', 'Radius (km)']; tableTest( 'Basic planet table: sorting initially - ascending by name', header, planets, - ascendingName, + planetsAscName, function ( $table ) { $table.tablesorter( { sortList: [ { 0: 'asc' } @@ -154,7 +299,7 @@ 'Basic planet table: sorting initially - descending by radius', header, planets, - reversed( ascendingRadius ), + reversed( planetsAscRadius ), function ( $table ) { $table.tablesorter( { sortList: [ { 1: 'desc' } @@ -165,7 +310,7 @@ 'Basic planet table: ascending by name', header, planets, - ascendingName, + planetsAscName, function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(0)' ).click(); @@ -175,7 +320,7 @@ 'Basic planet table: ascending by name a second time', header, planets, - ascendingName, + planetsAscName, function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(0)' ).click(); @@ -185,7 +330,7 @@ 'Basic planet table: ascending by name (multiple clicks)', header, planets, - ascendingName, + planetsAscName, function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(0)' ).click(); @@ -197,7 +342,7 @@ 'Basic planet table: descending by name', header, planets, - reversed( ascendingName ), + reversed( planetsAscName ), function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(0)' ).click().click(); @@ -207,7 +352,7 @@ 'Basic planet table: ascending radius', header, planets, - ascendingRadius, + planetsAscRadius, function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(1)' ).click(); @@ -217,31 +362,20 @@ 'Basic planet table: descending radius', header, planets, - reversed( ascendingRadius ), + reversed( planetsAscRadius ), function ( $table ) { $table.tablesorter(); $table.find( '.headerSort:eq(1)' ).click().click(); } ); - // Sample data set to test multiple column sorting - header = [ 'column1' , 'column2']; - var - a1 = [ 'A', '1' ], - a2 = [ 'A', '2' ], - a3 = [ 'A', '3' ], - b1 = [ 'B', '1' ], - b2 = [ 'B', '2' ], - b3 = [ 'B', '3' ]; - var initial = [a2, b3, a1, a3, b2, b1]; - var asc = [a1, a2, a3, b1, b2, b3]; - var descasc = [b1, b2, b3, a1, a2, a3]; + header = [ 'column1', 'column2' ]; tableTest( 'Sorting multiple columns by passing sort list', header, - initial, - asc, + simple, + simpleAsc, function ( $table ) { $table.tablesorter( { sortList: [ @@ -254,8 +388,8 @@ tableTest( 'Sorting multiple columns by programmatically triggering sort()', header, - initial, - descasc, + simple, + simpleDescasc, function ( $table ) { $table.tablesorter(); $table.data( 'tablesorter' ).sort( @@ -269,8 +403,8 @@ tableTest( 'Reset to initial sorting by triggering sort() without any parameters', header, - initial, - asc, + simple, + simpleAsc, function ( $table ) { $table.tablesorter( { sortList: [ @@ -290,8 +424,8 @@ tableTest( 'Sort via click event after having initialized the tablesorter with initial sorting', header, - initial, - descasc, + simple, + simpleDescasc, function ( $table ) { $table.tablesorter( { sortList: [ { 0: 'asc' }, { 1: 'asc' } ] } @@ -302,8 +436,8 @@ tableTest( 'Multi-sort via click event after having initialized the tablesorter with initial sorting', header, - initial, - asc, + simple, + simpleAsc, function ( $table ) { $table.tablesorter( { sortList: [ { 0: 'desc' }, { 1: 'desc' } ] } @@ -317,7 +451,7 @@ } ); QUnit.test( 'Reset sorting making table appear unsorted', 3, function ( assert ) { - var $table = tableCreate( header, initial ); + var $table = tableCreate( header, simple ); $table.tablesorter( { sortList: [ { 0: 'desc' }, @@ -346,18 +480,11 @@ } ); // Sorting with colspans - header = [ 'column1a' , 'column1b', 'column1c', 'column2' ]; - var - aaa1 = [ 'A', 'A', 'A', '1' ], - aab5 = [ 'A', 'A', 'B', '5' ], - abc3 = [ 'A', 'B', 'C', '3' ], - bbc2 = [ 'B', 'B', 'C', '2' ], - caa4 = [ 'C', 'A', 'A', '4' ]; - // initial is already declared above - initial = [ aab5, aaa1, abc3, bbc2, caa4 ]; + header = [ 'column1a', 'column1b', 'column1c', 'column2' ]; + tableTest( 'Sorting with colspanned headers: spanned column', header, - initial, + colspanInitial, [ aaa1, aab5, abc3, bbc2, caa4 ], function ( $table ) { // Make colspanned header for test @@ -370,7 +497,7 @@ ); tableTest( 'Sorting with colspanned headers: sort spanned column twice', header, - initial, + colspanInitial, [ caa4, bbc2, abc3, aab5, aaa1 ], function ( $table ) { // Make colspanned header for test @@ -384,7 +511,7 @@ ); tableTest( 'Sorting with colspanned headers: subsequent column', header, - initial, + colspanInitial, [ aaa1, bbc2, abc3, caa4, aab5 ], function ( $table ) { // Make colspanned header for test @@ -397,7 +524,7 @@ ); tableTest( 'Sorting with colspanned headers: sort subsequent column twice', header, - initial, + colspanInitial, [ aab5, caa4, abc3, bbc2, aaa1 ], function ( $table ) { // Make colspanned header for test @@ -410,7 +537,6 @@ } ); - tableTest( 'Basic planet table: one unsortable column', header, @@ -480,29 +606,6 @@ } ); - var ipv4 = [ - // Some randomly generated fake IPs - ['45.238.27.109'], - ['44.172.9.22'], - ['247.240.82.209'], - ['204.204.132.158'], - ['170.38.91.162'], - ['197.219.164.9'], - ['45.68.154.72'], - ['182.195.149.80'] - ]; - var ipv4Sorted = [ - // Sort order should go octet by octet - ['44.172.9.22'], - ['45.68.154.72'], - ['45.238.27.109'], - ['170.38.91.162'], - ['182.195.149.80'], - ['197.219.164.9'], - ['204.204.132.158'], - ['247.240.82.209'] - ]; - tableTest( 'Bug 17141: IPv4 address sorting', ['IP'], @@ -524,30 +627,6 @@ } ); - var umlautWords = [ - // Some words with Umlauts - ['Günther'], - ['Peter'], - ['Björn'], - ['Bjorn'], - ['Apfel'], - ['Äpfel'], - ['Strasse'], - ['Sträßschen'] - ]; - - var umlautWordsSorted = [ - // Some words with Umlauts - ['Äpfel'], - ['Apfel'], - ['Björn'], - ['Bjorn'], - ['Günther'], - ['Peter'], - ['Sträßschen'], - ['Strasse'] - ]; - tableTest( 'Accented Characters with custom collation', ['Name'], @@ -585,7 +664,7 @@ ); } ); - var planetsRowspan = [ + planetsRowspan = [ [ 'Earth', '6051.8' ], jupiter, [ 'Mars', '6051.8' ], @@ -593,7 +672,7 @@ saturn, venus ]; - var planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ]; + planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ]; tableTest( 'Basic planet table: same value for multiple rows via rowspan', @@ -648,23 +727,6 @@ } ); - var complexMDYDates = [ - // Some words with Umlauts - ['January, 19 2010'], - ['April 21 1991'], - ['04 22 1991'], - ['5.12.1990'], - ['December 12 \'10'] - ]; - - var complexMDYSorted = [ - ['5.12.1990'], - ['April 21 1991'], - ['04 22 1991'], - ['January, 19 2010'], - ['December 12 \'10'] - ]; - tableTest( 'Complex date parsing I', ['date'], @@ -678,28 +740,6 @@ } ); - var currencyUnsorted = [ - ['1.02 $'], - ['$ 3.00'], - ['€ 2,99'], - ['$ 1.00'], - ['$3.50'], - ['$ 1.50'], - ['€ 0.99'] - ]; - - var currencySorted = [ - ['€ 0.99'], - ['$ 1.00'], - ['1.02 $'], - ['$ 1.50'], - ['$ 3.00'], - ['$3.50'], - // Comma's sort after dots - // Not intentional but test to detect changes - ['€ 2,99'] - ]; - tableTest( 'Currency parsing I', ['currency'], @@ -711,15 +751,15 @@ } ); - var ascendingNameLegacy = ascendingName.slice( 0 ); - ascendingNameLegacy[4] = ascendingNameLegacy[5]; - ascendingNameLegacy.pop(); + planetsAscNameLegacy = planetsAscName.slice( 0 ); + planetsAscNameLegacy[4] = planetsAscNameLegacy[5]; + planetsAscNameLegacy.pop(); tableTest( 'Legacy compat with .sortbottom', header, planets, - ascendingNameLegacy, + planetsAscNameLegacy, function ( $table ) { $table.find( 'tr:last' ).addClass( 'sortbottom' ); $table.tablesorter(); @@ -928,23 +968,6 @@ } ); - var numbers = [ - [ '12' ], - [ '7' ], - [ '13,000'], - [ '9' ], - [ '14' ], - [ '8.0' ] - ]; - var numbersAsc = [ - [ '7' ], - [ '8.0' ], - [ '9' ], - [ '12' ], - [ '14' ], - [ '13,000'] - ]; - tableTest( 'bug 8115: sort numbers with commas (ascending)', ['Numbers'], numbers, numbersAsc, function ( $table ) { @@ -987,19 +1010,6 @@ ); } ); - - var correctDateSorting1 = [ - ['01 January 2010'], - ['05 February 2010'], - ['16 January 2010'] - ]; - - var correctDateSortingSorted1 = [ - ['01 January 2010'], - ['16 January 2010'], - ['05 February 2010'] - ]; - tableTest( 'Correct date sorting I', ['date'], @@ -1013,18 +1023,6 @@ } ); - var correctDateSorting2 = [ - ['January 01 2010'], - ['February 05 2010'], - ['January 16 2010'] - ]; - - var correctDateSortingSorted2 = [ - ['January 01 2010'], - ['January 16 2010'], - ['February 05 2010'] - ]; - tableTest( 'Correct date sorting II', ['date'],