From: Krinkle Date: Tue, 6 Sep 2011 23:09:04 +0000 (+0000) Subject: jquery.tablesorter.test: Add tests for data-sort-value X-Git-Tag: 1.31.0-rc.0~27858 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=ed3bc05dbf2284d45091beb5ca975bb5ee1cc106;p=lhc%2Fweb%2Fwiklou.git jquery.tablesorter.test: Add tests for data-sort-value * Follows-up r86108 --- diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index fddf8444be..72e587417d 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -381,4 +381,87 @@ tableTest( } ); +test( 'data-sort-value attribute, when available, should override sorting position', function() { + var $table, data; + + // Simple example, one without data-sort-value which should be sorted at it's text. + $table = $( + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
Data
Cheetah
Bird
Ferret
Elephant
Dolphin
' + ); + $table.tablesorter().find( '.headerSort:eq(0)' ).click(); + + data = []; + $table.find( 'tbody > tr' ).each( function( i, tr ) { + $( tr ).find( 'td' ).each( function( i, td ) { + data.push( { data: $( td ).data( 'sort-value' ), text: $( td ).text() } ); + }); + }); + + deepEqual( data, [ + { + "data": "Apple", + "text": "Bird" + }, { + "data": "Bananna", + "text": "Ferret" + }, { + "data": undefined, + "text": "Cheetah" + }, { + "data": "Cherry", + "text": "Dolphin" + }, { + "data": "Drupe", + "text": "Elephant" + } + ] ); + + // Another example + $table = $( + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
Data
D
A
B
G
C
' + ); + $table.tablesorter().find( '.headerSort:eq(0)' ).click(); + + data = []; + $table.find( 'tbody > tr' ).each( function( i, tr ) { + $( tr ).find( 'td' ).each( function( i, td ) { + data.push( { data: $( td ).data( 'sort-value' ), text: $( td ).text() } ); + }); + }); + + deepEqual( data, [ + { + "data": undefined, + "text": "B" + }, { + "data": undefined, + "text": "D" + }, { + "data": "E", + "text": "A" + }, { + "data": "F", + "text": "C" + }, { + "data": undefined, + "text": "G" + } + ] ); + +}); + })();