From ed3bc05dbf2284d45091beb5ca975bb5ee1cc106 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 6 Sep 2011 23:09:04 +0000 Subject: [PATCH] jquery.tablesorter.test: Add tests for data-sort-value * Follows-up r86108 --- .../jquery/jquery.tablesorter.test.js | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) 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" + } + ] ); + +}); + })(); -- 2.20.1