| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
QUnit.deferredCallback = function(func) { |
| 10 |
return function(){ |
| 11 |
var defer = $.Deferred(); |
| 12 |
func(defer); |
| 13 |
return defer.promise(); |
| 14 |
}; |
| 15 |
}; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
QUnit.SequentialRunner = function(runnerCreator){ |
| 40 |
var result = { |
| 41 |
defer: $.Deferred().resolve(), |
| 42 |
promise: function(){ |
| 43 |
return this.defer.promise(); |
| 44 |
}, |
| 45 |
next: function(runner) { |
| 46 |
this.defer = this.defer.then( QUnit.deferredCallback(runner) ); |
| 47 |
return this; |
| 48 |
} |
| 49 |
}; |
| 50 |
if (runnerCreator) { |
| 51 |
result.nextTask = function(args) { |
| 52 |
var deferredRunner = QUnit.deferredCallback( runnerCreator.apply(this, arguments) ); |
| 53 |
this.defer = this.defer.then(deferredRunner); |
| 54 |
return this; |
| 55 |
}; |
| 56 |
} |
| 57 |
return result; |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
QUnit.assertOnEvent = function($element, eventType, actions, assertions) { |
| 82 |
return function(defer){ |
| 83 |
$element |
| 84 |
.off(eventType) |
| 85 |
.on(eventType, function() { |
| 86 |
$element.off(eventType); |
| 87 |
assertions(); |
| 88 |
defer && defer.resolve(); |
| 89 |
}); |
| 90 |
actions(); |
| 91 |
}; |
| 92 |
}; |
| 93 |
|
| 94 |
QUnit.extend(QUnit.assert, { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
cacheCompare : function(table, col, expected, txt, filtered){ |
| 99 |
var flat = [], |
| 100 |
result = $.tablesorter.getColumnText( table, col, function( data ){ |
| 101 |
return !( filtered && data.$row.hasClass( table.config.widgetOptions.filter_filteredRow ) ); |
| 102 |
}); |
| 103 |
|
| 104 |
flat = flat.concat.apply( flat, result.parsed ); |
| 105 |
QUnit.assert.deepEqual( flat, expected, 'Comparing parser cache: ' + txt); |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
jQuery(function($){ |
| 140 |
|
| 141 |
var ts = $.tablesorter, |
| 142 |
$table1 = $('#table1'), |
| 143 |
$table2 = $('#table2'), |
| 144 |
$table3 = $('#table3'), |
| 145 |
$table4 = $('#table4'), |
| 146 |
$table5 = $('#table5'), |
| 147 |
$table6 = $('#table6'), |
| 148 |
table1 = $table1[0], |
| 149 |
table2 = $table2[0], |
| 150 |
table3 = $table3[0], |
| 151 |
table4 = $table4[0], |
| 152 |
table5 = $table5[0], |
| 153 |
table6 = $table6[0], |
| 154 |
th0 = $table1.find('th')[0], |
| 155 |
init = false, |
| 156 |
sortIndx = 0, |
| 157 |
updateIndx = 0, |
| 158 |
updateCallback = 0, |
| 159 |
events = ['sortStart', 'sortBegin', 'sortEnd', ' '], |
| 160 |
returnTime = function(string){ |
| 161 |
return new Date(string).getTime(); |
| 162 |
}, |
| 163 |
undef, c1, c2, c3, c4, e, i, t; |
| 164 |
|
| 165 |
|
| 166 |
ts.addWidget({ |
| 167 |
id : 'test', |
| 168 |
options: { |
| 169 |
'test': [] |
| 170 |
}, |
| 171 |
format: function() {} |
| 172 |
}); |
| 173 |
|
| 174 |
$table1 |
| 175 |
.on('tablesorter-initialized', function(){ |
| 176 |
init = true; |
| 177 |
}) |
| 178 |
.tablesorter({ |
| 179 |
widgets: ['test'], |
| 180 |
widgetOptions: { |
| 181 |
|
| 182 |
test: [0,1] |
| 183 |
} |
| 184 |
}); |
| 185 |
|
| 186 |
$table2.tablesorter({ |
| 187 |
headers: { |
| 188 |
0: { sorter: 'text' }, |
| 189 |
1: { sorter: 'text' }, |
| 190 |
2: { sorter: false } |
| 191 |
}, |
| 192 |
widgets: ['test'], |
| 193 |
widgetOptions: { |
| 194 |
|
| 195 |
test: [0] |
| 196 |
} |
| 197 |
}); |
| 198 |
|
| 199 |
$table3.tablesorter({ |
| 200 |
emptyTo: 'bottom', |
| 201 |
stringTo: 'max', |
| 202 |
headers: { |
| 203 |
0: { empty : 'top' }, |
| 204 |
2: { string: 'min' }, |
| 205 |
3: { sorter: 'digit', empty : 'zero', string : 'top' } |
| 206 |
}, |
| 207 |
|
| 208 |
widgets: ['test'] |
| 209 |
}); |
| 210 |
|
| 211 |
$table4.tablesorter({ |
| 212 |
sortAppend : [[2,0],[3,0]], |
| 213 |
sortForce : [[0,0],[1,0]], |
| 214 |
textExtraction : { |
| 215 |
'.te-test' : function(node){ |
| 216 |
return $(node).find('span').text(); |
| 217 |
}, |
| 218 |
2 : function(node){ |
| 219 |
return $(node).find('span').text(); |
| 220 |
} |
| 221 |
}, |
| 222 |
initialized: function(table){ |
| 223 |
var e, c = table.config; |
| 224 |
|
| 225 |
|
| 226 |
c.$headers.eq(4).trigger('sort'); |
| 227 |
e = $.Event('sort'); |
| 228 |
e.which = 1; |
| 229 |
e.shiftKey = true; |
| 230 |
c.$headers.eq(5).trigger(e); |
| 231 |
}, |
| 232 |
numberSorter: function(a, b, dir){ |
| 233 |
return dir ? a-b : b-a; |
| 234 |
} |
| 235 |
}); |
| 236 |
|
| 237 |
$table5.tablesorter(); |
| 238 |
$table6.tablesorter(); |
| 239 |
|
| 240 |
QUnit.module('core'); |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
QUnit.test( 'tablesorter loaded & initialized', function(assert) { |
| 245 |
assert.expect(3); |
| 246 |
assert.equal( typeof ts, 'object', 'tablesorter loaded'); |
| 247 |
assert.equal( table1.hasInitialized, true, 'tablesorter initialized flag'); |
| 248 |
assert.equal( init, true, 'tablesorter initialized event'); |
| 249 |
}); |
| 250 |
|
| 251 |
c1 = table1.config; |
| 252 |
c2 = table2.config; |
| 253 |
c3 = table3.config; |
| 254 |
c4 = table4.config; |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
QUnit.test( 'column numbering', function(assert) { |
| 261 |
assert.expect(2); |
| 262 |
var internalColumn = true, |
| 263 |
dataColumn = true; |
| 264 |
$table4.find('thead th').each(function(i){ |
| 265 |
internalColumn = internalColumn && this.column === i; |
| 266 |
dataColumn = dataColumn && $(this).attr('data-column') == i; |
| 267 |
}); |
| 268 |
assert.equal( internalColumn, true, 'Correct internal column numbering' ); |
| 269 |
assert.equal( dataColumn, true, 'Correct data-column attribute numbering' ); |
| 270 |
}); |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
var d = ts.isDigit; |
| 276 |
QUnit.test( 'isDigit', function(assert) { |
| 277 |
assert.expect(18); |
| 278 |
assert.ok( d('-1'), 'allow negative (-1)'); |
| 279 |
assert.ok( d('+1'), 'allow plus (+1)'); |
| 280 |
assert.ok( d('(1)'), 'allow parenthesis (1)'); |
| 281 |
assert.ok( d('123'), "string has numbers ('123')"); |
| 282 |
assert.ok( d(123), 'has numbers (123)'); |
| 283 |
assert.ok( d('1.2'), 'remove decimal (1.2)'); |
| 284 |
assert.ok( d('1,234'),'remove commas (1,234)'); |
| 285 |
assert.ok( d("11'"), "remove apostrophe's (11')"); |
| 286 |
assert.ok( d('3\'4"'),"remove quotes (3'4\")"); |
| 287 |
assert.ok( d(' 12 '), 'remove spaces ( 12 )'); |
| 288 |
assert.ok( !d('x'), 'non-digit alphabet'); |
| 289 |
assert.ok( !d('1x'), 'digit + alphabet'); |
| 290 |
assert.ok( !d('x1'), 'alphabet + digit'); |
| 291 |
assert.ok( !d('@'), 'non-digit symbols'); |
| 292 |
assert.ok( !d('1-'), 'negative after (1-) not allowed?'); |
| 293 |
assert.ok( !d('1+'), 'plus after (1+) not allowed?'); |
| 294 |
assert.ok( !d('$2'), 'no money; the currency parser will catch these'); |
| 295 |
assert.ok( !d(''), "empty string ('')"); |
| 296 |
}); |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
var ff = function(str) { |
| 302 |
return ts.formatFloat(str, table1); |
| 303 |
}; |
| 304 |
QUnit.test( 'formatFloat', function(assert) { |
| 305 |
assert.expect(18); |
| 306 |
assert.strictEqual( ff(''), '', 'returns empty string' ); |
| 307 |
assert.strictEqual( ff(5), 5, 'returns numerical values'); |
| 308 |
|
| 309 |
c1.usNumberFormat = false; |
| 310 |
assert.strictEqual( ts.formatFloat('1,234,567.89'), 1234567.89, 'use format float without including table - defaults to US number format'); |
| 311 |
|
| 312 |
assert.strictEqual( ff('1 234,56'), 1234.56, 'parse non-U.S. (French) number format'); |
| 313 |
assert.strictEqual( ff('1.234,56'), 1234.56, 'parse non-U.S. (German) number format'); |
| 314 |
assert.strictEqual( ff('-32,32'), -32.32, 'negative non-U.S. signed numbers'); |
| 315 |
assert.strictEqual( ff('-1.234,56'), -1234.56, 'negative non-U.S. signed numbers'); |
| 316 |
assert.strictEqual( ff('(32,32)'), -32.32, 'parenthesis wrapped non-U.S. negative number'); |
| 317 |
assert.strictEqual( ff(' (32,32) '), -32.32, 'space + parenthesis wrapped non-U.S. negative number'); |
| 318 |
|
| 319 |
c1.usNumberFormat = true; |
| 320 |
assert.strictEqual( ff('1,234.56'), 1234.56, 'parse U.S. number format'); |
| 321 |
assert.strictEqual( ff('-32.32'), -32.32, 'negative U.S. signed numbers'); |
| 322 |
assert.strictEqual( ff('(32.32)'), -32.32, 'parenthesis wrapped U.S. negative number'); |
| 323 |
assert.strictEqual( ff(' (32.32)'), -32.32, 'space + parenthesis wrapped U.S. negative number'); |
| 324 |
|
| 325 |
assert.strictEqual( ff('fred'), 'fred', 'return string if not a number'); |
| 326 |
assert.strictEqual( ff(' fred '), 'fred', 'return trimmed string if not a number'); |
| 327 |
assert.strictEqual( ff('fred 12'), 'fred 12', 'return string if number not at beginning'); |
| 328 |
assert.strictEqual( ff('12fred'), 12, 'parse number + string into number only'); |
| 329 |
assert.strictEqual( ff('(fred)'), '(fred)', 'leave parenthesis intact on strings'); |
| 330 |
|
| 331 |
}); |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
var gd = function(n){ |
| 337 |
return ts.getData( c2.$headers[n], c2.headers[n], 'sorter' ); |
| 338 |
}; |
| 339 |
|
| 340 |
QUnit.test( 'getData', function(assert) { |
| 341 |
assert.expect(4); |
| 342 |
var txt = [ 'jQuery data', 'meta data', 'headers option', 'header class name' ]; |
| 343 |
for (i = 0; i < 4; i++) { |
| 344 |
assert.equal( gd(i), 'false', txt[i]); |
| 345 |
} |
| 346 |
}); |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
QUnit.test( 'isValueInArray', function(assert) { |
| 353 |
var v = ts.isValueInArray; |
| 354 |
assert.expect(6); |
| 355 |
assert.ok( v( 0, null ) < 0, 'null' ); |
| 356 |
assert.ok( v( 0, [] ) < 0, 'Empty array' ); |
| 357 |
assert.ok( v( 1, [[ 1,0 ], [ 0,0 ]] ) === 0, 'Column found (first array)' ); |
| 358 |
assert.ok( v( 1, [[ 0,0 ], [ 1,0 ]] ) === 1, 'Column found (second array)' ); |
| 359 |
assert.ok( v( 4, [[ 0,0 ], [ 1,0 ], [ 4,0 ]] ) === 2, 'Column found (third array)' ); |
| 360 |
assert.ok( v( 3, [[ 0,0 ], [ 1,0 ], [ 4,0 ]] ) < 0 , 'Column not found' ); |
| 361 |
}); |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
QUnit.test( 'isProcessing', function(assert) { |
| 367 |
$table3.trigger('sortReset'); |
| 368 |
assert.expect(5); |
| 369 |
var p = ts.isProcessing, |
| 370 |
findClasses = function( applied, columns ) { |
| 371 |
var i, tmp, |
| 372 |
headers = 0, |
| 373 |
len = columns.length, |
| 374 |
headers = 0, |
| 375 |
|
| 376 |
result = applied && $table3.hasClass( ts.css.processing ); |
| 377 |
if ( len === 1 && columns[ 0 ] < 0 ) { |
| 378 |
|
| 379 |
return ( !result || applied && result ) && c3.$headers.find( '.' + ts.css.processing ).length === 0; |
| 380 |
} |
| 381 |
for ( i = 0; i < len; i++ ) { |
| 382 |
tmp = c3.$headers.eq( columns[ i ] ).hasClass( ts.css.processing ); |
| 383 |
if ( tmp ) { headers++; } |
| 384 |
result = result && tmp; |
| 385 |
} |
| 386 |
return result && headers === len; |
| 387 |
}; |
| 388 |
$table3.trigger('sorton', [[[0,0], [1,0]]]); |
| 389 |
p( $table3, true ); |
| 390 |
assert.ok( findClasses( true, [ 0, 1 ] ), 'Processing 2 columns' ); |
| 391 |
p( $table3, false ); |
| 392 |
assert.ok( findClasses( false, [ -1 ] ), 'No sort' ); |
| 393 |
p( $table3, true, c3.$headers.eq(4) ); |
| 394 |
assert.ok( findClasses( true, [ -1 ] ), 'Processing specified column not in sortList' ); |
| 395 |
p( $table3, true, c3.$headers.eq(1) ); |
| 396 |
assert.ok( findClasses( true, [ 1 ] ), 'Processing specified column in sortList' ); |
| 397 |
$table3.trigger('sortReset'); |
| 398 |
assert.ok( findClasses( false, [ -1 ] ), 'No sort' ); |
| 399 |
}); |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
QUnit.test( 'replace accents', function(assert) { |
| 405 |
assert.expect(6); |
| 406 |
assert.strictEqual( ts.replaceAccents('\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5'), 'aaaaaaaAAAAAAA', "replaced a's"); |
| 407 |
assert.strictEqual( ts.replaceAccents('\u00e9\u00e8\u00ea\u00eb\u011b\u0119\u00c9\u00c8\u00ca\u00cb\u011a\u0118'), 'eeeeeeEEEEEE', "replaced e's"); |
| 408 |
assert.strictEqual( ts.replaceAccents('\u00ed\u00ec\u0130\u00ee\u00ef\u0131\u00cd\u00cc\u0130\u00ce\u00cf'), 'iiiiiiIIiII', "replaced i's"); |
| 409 |
assert.strictEqual( ts.replaceAccents('\u00f3\u00f2\u00f4\u00f5\u00f6\u00d3\u00d2\u00d4\u00d5\u00d6'), 'oooooOOOOO', "replaced o's"); |
| 410 |
assert.strictEqual( ts.replaceAccents('\u00fa\u00f9\u00fb\u00fc\u016f\u00da\u00d9\u00db\u00dc\u016e'), 'uuuuuUUUUU', "replaced u's"); |
| 411 |
assert.strictEqual( ts.replaceAccents('\u00e7\u0107\u010d\u00c7\u0106\u010c\u00df\u1e9e'), 'cccCCCssSS', 'replaced c & s sharp'); |
| 412 |
}); |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
QUnit.test( 'detect parsers', function(assert) { |
| 418 |
var done = assert.async(); |
| 419 |
assert.expect(2); |
| 420 |
$('#testblock2').html('<table class="tablesorter"><thead>' + |
| 421 |
'<tr><th class="col-off" colspan="2">Info</th><th class="col-off" colspan="4">Details</th></tr>' + |
| 422 |
'<tr>' + |
| 423 |
'<th class="col-first">First Name</th>' + |
| 424 |
'<th class="col-last">Last Name</th>' + |
| 425 |
'<th class="col-age" id="age">Age</th>' + |
| 426 |
'<th class="col-total">Total</th>' + |
| 427 |
'<th class="col-discount">Discount</th>' + |
| 428 |
'<th class="col-date">Date</th>' + |
| 429 |
'</tr></thead>' + |
| 430 |
'<tbody>' + |
| 431 |
'<tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>' + |
| 432 |
'<tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr>' + |
| 433 |
'<tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>' + |
| 434 |
'<tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>' + |
| 435 |
'<tr><td>Bruce</td><td>Evans</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2007 9:12 AM</td></tr>' + |
| 436 |
'</tbody></table>') |
| 437 |
.find('table') |
| 438 |
.tablesorter({ |
| 439 |
headers : { |
| 440 |
0 : { sorter: false }, |
| 441 |
1 : { sorter: false }, |
| 442 |
3 : { sorter: 'digit' } |
| 443 |
}, |
| 444 |
initialized: function(table){ |
| 445 |
var i, |
| 446 |
result = true, |
| 447 |
parsers = [ 'text', 'digit', 'digit', 'currency', 'percent', 'usLongDate' ], |
| 448 |
c = table.config; |
| 449 |
for (i = 0; i < c.columns; i++){ |
| 450 |
result = result && c.parsers[i].id === parsers[i]; |
| 451 |
} |
| 452 |
assert.equal( result, true, 'detect parsers by header index' ); |
| 453 |
|
| 454 |
$(table) |
| 455 |
.trigger('destroy') |
| 456 |
.tablesorter({ |
| 457 |
headers : { |
| 458 |
'.col-first' : { sorter: 'url' }, |
| 459 |
'.col-off' : { sorter: false }, |
| 460 |
'.col-total' : { sorter : 'percent' }, |
| 461 |
'#age, .col-last' : { sorter: 'currency' }, |
| 462 |
'.col-date' : { sorter : 'time' }, |
| 463 |
'.col-discount' : { sorter: 'digit' } |
| 464 |
}, |
| 465 |
initialized: function(table){ |
| 466 |
var i, |
| 467 |
result = true, |
| 468 |
parsers = [ 'url', 'currency', 'currency', 'percent', 'digit', 'time' ], |
| 469 |
c = table.config; |
| 470 |
for (i = 0; i < c.columns; i++){ |
| 471 |
result = result && c.parsers[i].id === parsers[i]; |
| 472 |
} |
| 473 |
assert.equal( result, true, 'detect parsers by class/id' ); |
| 474 |
done(); |
| 475 |
} |
| 476 |
}); |
| 477 |
} |
| 478 |
}); |
| 479 |
|
| 480 |
}); |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
var p = ts.parsers, |
| 486 |
|
| 487 |
parserTests = 86, |
| 488 |
|
| 489 |
sample1 = { |
| 490 |
'text' : { 'test': 'test', 'TesT': 'test', '\u00e1 test': '\u00e1 test' }, |
| 491 |
'currency' : { '\u00a31': 1, '($2.23)': -2.23, '5\u20ac': 5, '(11\u00a4)': -11, '500\u00a5': 500, '25\u00a2': 25, '$1,000.50': 1000.5 }, |
| 492 |
'ipAddress' : { '255.255.255.255': '255.255.255.255', '32.32.32.32': '032.032.032.032', '1.1.1.1': '001.001.001.001' }, |
| 493 |
'url' : { 'http://google.com': 'google.com', 'ftp://fred.com': 'fred.com', 'https://github.com': 'github.com' }, |
| 494 |
'isoDate' : { '2012/12/12': returnTime('2012/12/12'), '2012-12/12': returnTime('2012/12/12'), '2013-1-1': returnTime('2013/1/1'), '2013/1/1 12:34:56 AM': returnTime('2013/1/1 12:34:56 AM') }, |
| 495 |
'percent' : { '100%': 100, '22%': 22, '%2': 2, '2 %': 2, '(4%)': -4, '1,234.56 %': 1234.56 }, |
| 496 |
'usLongDate': { 'Feb 23, 1999': returnTime('Feb 23, 1999'), 'Feb 23, 1999 12:34': returnTime('Feb 23, 1999 12:34'), 'Feb 23, 1999 12:34 AM': returnTime('Feb 23, 1999 12:34 AM'), 'Feb 23, 1999 12:34:56 PM': returnTime('Feb 23, 1999 12:34:56 PM'), '01 Jan 2013': returnTime('01 Jan 2013') }, |
| 497 |
'shortDate' : { '1/2/2001': returnTime('1/2/2001'), '1 2 2001': returnTime('1/2/2001'), '1.2.2001': returnTime('1/2/2001'), '1-2-2001': returnTime('1/2/2001'), '1/2/2001 12:34 PM' : returnTime('1/2/2001 12:34 PM'), '1.2.2001 13:34' : returnTime('1/2/2001 13:34') }, |
| 498 |
'time' : { '12:34 AM': returnTime('2000/01/01 12:34 AM'), '1:00 pm': returnTime('2000/01/01 1:00 pm'), '09:54 PM': returnTime('2000/01/01 9:54 PM') }, |
| 499 |
'digit' : { '12': 12, '$23': 23, '&44^': 44, '#(33)': -33, '1,000': 1000, '12.34': 12.34 } |
| 500 |
}, |
| 501 |
|
| 502 |
sample2 = { |
| 503 |
'text' : { 'TesT': 'TesT', '\u00e1 test': 'a test' }, |
| 504 |
'currency' : { '\u20ac 123 456,78': 123456.78, '\u20ac 123.456,78': 123456.78 }, |
| 505 |
'shortDate' : { '2/1/2001': returnTime('1/2/2001'), '2-1-2001': returnTime('1/2/2001'), '2 1,2001': returnTime('1/2/2001') } |
| 506 |
}, |
| 507 |
|
| 508 |
sample3 = { |
| 509 |
'shortDate' : { '2001/1/2': returnTime('1/2/2001'), '2001-1/2': returnTime('1/2/2001'), '2001,1.2': returnTime('1/2/2001') } |
| 510 |
}, |
| 511 |
report = function(assert, s) { |
| 512 |
for (i = 0; i < p.length; i++) { |
| 513 |
t = p[i].id; |
| 514 |
if (s.hasOwnProperty(t)) { |
| 515 |
|
| 516 |
$.each(s[t], function(k,v){ |
| 517 |
|
| 518 |
if (p[i].is(k)) { |
| 519 |
assert.equal( p[i].format(k, table1, th0, 0), v, t + ' parser: "' + k + '" parsed to ' + v ); |
| 520 |
} else { |
| 521 |
assert.equal( p[i].format(k, table1, th0, 0), v, t + ' parser **NOT DETECTED**: "' + k + '", but returns ' + v ); |
| 522 |
} |
| 523 |
}); |
| 524 |
|
| 525 |
assert.strictEqual( p[i].format(undef, table1, th0, 0), undef, t + ' parser: will return undefined values properly' ); |
| 526 |
assert.strictEqual( p[i].format(null, table1, th0, 0), null, t + ' parser: will return null values properly' ); |
| 527 |
} |
| 528 |
} |
| 529 |
}; |
| 530 |
|
| 531 |
QUnit.test( 'testing parsers', function(assert) { |
| 532 |
assert.expect(parserTests); |
| 533 |
report(assert, sample1); |
| 534 |
var $t = $(th0); |
| 535 |
|
| 536 |
c1.sortLocaleCompare = true; |
| 537 |
c1.ignoreCase = false; |
| 538 |
c1.usNumberFormat = false; |
| 539 |
$t.data('dateFormat', 'ddmmyyyy'); |
| 540 |
report(assert, sample2); |
| 541 |
|
| 542 |
c1.usNumberFormat = true; |
| 543 |
$t.data('dateFormat', 'yyyymmdd'); |
| 544 |
report(assert, sample3); |
| 545 |
|
| 546 |
|
| 547 |
assert.equal( ts.getParserById('metadata').format(null, table1, th0, 0), 'zzz', 'metadata parser found sortValue'); |
| 548 |
c1.parserMetadataName = 'poe'; |
| 549 |
assert.equal( ts.getParserById('metadata').format(null, table1, th0, 0), 'nevermore', 'metadata parser found poe'); |
| 550 |
}); |
| 551 |
|
| 552 |
QUnit.test( 'textExtraction Method', function(assert) { |
| 553 |
assert.expect(4); |
| 554 |
|
| 555 |
$table1.trigger('sorton', [[[ 0,0 ]]]); |
| 556 |
assert.cacheCompare( table1, 0, [ 'test1', 'test2', 'test3', |
| 557 |
'testa', 'testb', 'testc', '' ], 'from data-attribute' ); |
| 558 |
|
| 559 |
$table3.trigger('sorton', [[[ 0,1 ]]]); |
| 560 |
assert.cacheCompare( table3, 0, [ '', 'a255', 'a102', 'a87', 'a55', 'a43', 'a33', 'a10', 'a02', 'a1' ], 'ignore data-attribute' ); |
| 561 |
|
| 562 |
assert.cacheCompare( table4, 1, [ 'f11', 'f11', 'f12', 'f12', 'f12', 'f12', 'f12', 'f13', 'f13', 'f13' ], 'extract using class name' ); |
| 563 |
|
| 564 |
assert.cacheCompare( table4, 2, [ 'a21', 'a21', 'a23', 'a23', 'a23', 'a22', 'a22', 'a23', 'a24', 'a24' ], 'extract using column index' ); |
| 565 |
|
| 566 |
}); |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
QUnit.test( 'parser cache; sorton methods; empty & string', function(assert) { |
| 572 |
assert.expect(18); |
| 573 |
$table1.trigger('sortReset'); |
| 574 |
|
| 575 |
|
| 576 |
assert.cacheCompare( table1, 'all', [ 'test2', 'x2', 'test1', 'x3', 'test3', 'x1', |
| 577 |
'', 'x0', 'testb', 'x5', 'testc', 'x4', 'testa', 'x6' ], 'unsorted' ); |
| 578 |
|
| 579 |
$table1.trigger('sorton', [[[ 0,0 ]]]); |
| 580 |
assert.cacheCompare( table1, 'all', [ 'test1', 'x3', 'test2', 'x2', 'test3', 'x1', |
| 581 |
'testa', 'x6', 'testb', 'x5', 'testc', 'x4', '', 'x0' ], 'ascending sort' ); |
| 582 |
|
| 583 |
$table1.trigger('sorton', [[[ 0,1 ]]]); |
| 584 |
assert.cacheCompare( table1, 'all', [ 'test3', 'x1', 'test2', 'x2', 'test1', 'x3', |
| 585 |
'testc', 'x4', 'testb', 'x5', 'testa', 'x6', '', 'x0' ], 'descending sort' ); |
| 586 |
|
| 587 |
|
| 588 |
$table3.trigger('sorton', [[[ 0,0 ]]]); |
| 589 |
assert.cacheCompare( table3, 0, [ '', 'a1', 'a02', 'a10', 'a33', 'a43', 'a55', 'a87', 'a102', 'a255' ], 'asc sort; empty to top' ); |
| 590 |
|
| 591 |
$table3.trigger('sorton', [[[ 0,1 ]]]); |
| 592 |
assert.cacheCompare( table3, 0, [ '', 'a255', 'a102', 'a87', 'a55', 'a43', 'a33', 'a10', 'a02', 'a1' ], 'desc sort; empty to top' ); |
| 593 |
|
| 594 |
|
| 595 |
$table3.trigger('sorton', [[[ 1,0 ]]]); |
| 596 |
assert.cacheCompare( table3, 1, [ -35, -5, -1, 1, 2, 4, 33, 44, 'nr', '' ], 'asc sort; empty to bottom; string to max' ); |
| 597 |
|
| 598 |
$table3.trigger('sorton', [[[ 1,1 ]]]); |
| 599 |
assert.cacheCompare( table3, 1, [ 'nr', 44, 33, 4, 2, 1, -1, -5, -35, '' ], 'desc sort; empty to bottom; string to max' ); |
| 600 |
|
| 601 |
$table3.trigger('sorton', [[[ 2,0 ]]]); |
| 602 |
assert.cacheCompare( table3, 2, [ 'nr', 'nr', 1, 2, 3, 4, 5, 6, 7, '' ], 'asc sort; empty to bottom; string to min' ); |
| 603 |
|
| 604 |
$table3.trigger('sorton', [[[ 2,1 ]]]); |
| 605 |
assert.cacheCompare( table3, 2, [ 7, 6, 5, 4, 3, 2, 1, 'nr', 'nr', '' ], 'desc sort; empty to bottom; string to min' ); |
| 606 |
|
| 607 |
$table3.trigger('sorton', [[[ 3,0 ]]]); |
| 608 |
assert.cacheCompare( table3, 3, [ 'n/a #2', 'n/a #1', -8.4, -2.2, -0.1, '', 5.2, 11.4, 23.6, 97.4 ], 'asc sort; empty to zero; string to top' ); |
| 609 |
|
| 610 |
$table3.trigger('sorton', [[[ 3,1 ]]]); |
| 611 |
assert.cacheCompare( table3, 3, [ 'n/a #2', 'n/a #1', 97.4, 23.6, 11.4, 5.2, '', -0.1, -2.2, -8.4 ], 'desc sort; empty to zero; string to top' ); |
| 612 |
|
| 613 |
$table3.find('th:eq(3)').data('string', 'bottom'); |
| 614 |
$table3.trigger('update'); |
| 615 |
assert.cacheCompare( table3, 3, [ 97.4, 23.6, 11.4, 5.2, '', -0.1, -2.2, -8.4, 'n/a #1', 'n/a #2' ], 'desc sort; empty to zero; string to bottom' ); |
| 616 |
|
| 617 |
$table3.trigger('sorton', [[[ 3,0 ]]]); |
| 618 |
assert.cacheCompare( table3, 3, [ -8.4, -2.2, -0.1, '', 5.2, 11.4, 23.6, 97.4, 'n/a #1', 'n/a #2' ], 'asc sort; empty to zero; string to bottom' ); |
| 619 |
|
| 620 |
$table3.find('th:eq(3)').data('string', 'none'); |
| 621 |
c3.headers[3].empty = 'bottom'; |
| 622 |
c3.sortList = [[ 3, 1 ]]; |
| 623 |
$table3.trigger('update'); |
| 624 |
assert.cacheCompare( table3, 3, [ 97.4, 23.6, 11.4, 5.2, 'n/a #1', 'n/a #2', -0.1, -2.2, -8.4, '' ], 'desc sort; empty to zero; string to none/zero' ); |
| 625 |
|
| 626 |
$table3.trigger('sorton', [[[ 3,0 ]]]); |
| 627 |
assert.cacheCompare( table3, 3, [ -8.4, -2.2, -0.1, 'n/a #1', 'n/a #2', 5.2, 11.4, 23.6, 97.4, '' ], 'asc sort; empty to zero; string to none/zero' ); |
| 628 |
|
| 629 |
t = [ 'x', 'X', 'y', 'Y', 'z', 'Z', 'a', 'A', 'b', 'B', 'c', 'C' ]; |
| 630 |
assert.deepEqual( t.sort($.tablesorter.sortText), [ 'A', 'B', 'C', 'X', 'Y', 'Z', 'a', 'b', 'c', 'x', 'y', 'z' ], 'test sortText function directly' ); |
| 631 |
|
| 632 |
t = [ 'a02', 'a10', 'a43', 'a255', 'a102', 'a33', '', 'a1', 'a55', 'a87' ]; |
| 633 |
assert.deepEqual( t.sort($.tablesorter.sortNatural), [ '', 'a1', 'a02', 'a10', 'a33', 'a43', 'a55', 'a87', 'a102', 'a255' ], 'test sortNatural function directly' ); |
| 634 |
|
| 635 |
assert.cacheCompare( table4, 6, [ '', '', '', '', '', '', '', '', '', '' ], 'parser-false does not extract text' ); |
| 636 |
|
| 637 |
}); |
| 638 |
|
| 639 |
QUnit.test( 'colspan parsing', function(assert) { |
| 640 |
assert.expect(3); |
| 641 |
|
| 642 |
t = [ |
| 643 |
'g1', '6', 'a9', 155, 'l', 'nytimes', |
| 644 |
'g1', '2', 'z1 957 k mit', 'z1 957 k mit', 'z1 957 k mit', 'z1 957 k mit', |
| 645 |
'g3', '0', 'a13', 17, 17, 'google', |
| 646 |
'g2', '8', 'z9', 10, 'g', 'facebook', |
| 647 |
'g1', '3', 'z24 67', 'z24 67', 'b', 'whitehouse', |
| 648 |
'g4', '7 a10', '7 a10', 87, 'z', 'google', |
| 649 |
'g3', '9', 'z12', 0, 'k nasa', 'k nasa' |
| 650 |
]; |
| 651 |
assert.cacheCompare( table6,'all', t, 'colspans in tbody (duplicateSpan:true)' ); |
| 652 |
|
| 653 |
$('#testblock').html('<table class="tablesorter">' + |
| 654 |
'<thead><tr><th>1</th><th>2</th><th>3</th><th>4</th></tr></thead>' + |
| 655 |
'<tbody>' + |
| 656 |
'<tr><td>1</td><td colspan="2">2</td><td>3</td></tr>' + |
| 657 |
'<tr><td colspan="3">y</td><td>z</td></tr>' + |
| 658 |
'<tr><td>a</td><td>b</td><td colspan="2">c</td></tr>' + |
| 659 |
'</tbody></table>') |
| 660 |
.find('table') |
| 661 |
.tablesorter({ |
| 662 |
headers : { '*' : { sorter: 'text' } }, |
| 663 |
duplicateSpan: false |
| 664 |
}); |
| 665 |
t = [ |
| 666 |
'1', '2', '', '3', |
| 667 |
'y', '', '', 'z', |
| 668 |
'a', 'b', 'c', '' |
| 669 |
]; |
| 670 |
assert.cacheCompare( $('#testblock table')[0], 'all', t, 'colspans not duplicated in cache (duplicateSpan:false)' ); |
| 671 |
|
| 672 |
|
| 673 |
$('#testblock').html('<table class="tablesorter">' + |
| 674 |
'<thead><tr><th>1</th><th>2</th><th>3</th><th>4</th></tr></thead>' + |
| 675 |
'<tbody>' + |
| 676 |
'<tr><td>1</td><td colspan="2">2</td><td>3</td></tr>' + |
| 677 |
'<tr><td colspan="3"><span class="col0">y0</span><span class="col1">y1</span><span class="col2">y2</span></td><td>z</td></tr>' + |
| 678 |
'<tr><td>a</td><td>b</td><td colspan="2"><span class="col2">c1</span><span class="col3">c2</span></td></tr>' + |
| 679 |
'</tbody></table>') |
| 680 |
.find('table') |
| 681 |
.tablesorter({ |
| 682 |
headers : { '*' : { sorter: 'text' } }, |
| 683 |
textExtraction: function(node, table, cellIndex) { |
| 684 |
var $span = $(node).find('.col' + cellIndex); |
| 685 |
if ($span.length) { |
| 686 |
return $span.text(); |
| 687 |
} |
| 688 |
return node.textContent; |
| 689 |
}, |
| 690 |
duplicateSpan: false |
| 691 |
}); |
| 692 |
t = [ |
| 693 |
'1', '2', '2', '3', |
| 694 |
'y0', 'y1', 'y2', 'z', |
| 695 |
'a', 'b', 'c1', 'c2' |
| 696 |
]; |
| 697 |
assert.cacheCompare( $('#testblock table')[0], 'all', t, 'colspans not duplicated but textExtraction defined' ); |
| 698 |
}); |
| 699 |
|
| 700 |
QUnit.test( 'sorton methods', function(assert) { |
| 701 |
assert.expect(6); |
| 702 |
|
| 703 |
$table3.trigger('sorton', [[[ 0,'d' ]]]); |
| 704 |
assert.equal( c3.sortList + '', '0,1', 'sorton desc [0,"d"]' ); |
| 705 |
|
| 706 |
$table3.trigger('sorton', [[[ 0,'a' ]]]); |
| 707 |
assert.equal( c3.sortList + '', '0,0', 'sorton asc [0,"a"]' ); |
| 708 |
|
| 709 |
$table3.trigger('sorton', [[[ 0,'n' ]]]); |
| 710 |
assert.equal( c3.sortList + '', '0,1', 'sorton next [0,"n"]' ); |
| 711 |
$table3.trigger('sorton', [[[ 0,'n' ]]]); |
| 712 |
assert.equal( c3.sortList + '', '0,0', 'sorton next [0,"n"]' ); |
| 713 |
|
| 714 |
$table3.trigger('sorton', [[ [ 0,'n'], [1,'o'], [2,'s'] ]]); |
| 715 |
assert.equal( c3.sortList + '', '0,1,1,0,2,1', 'sorton next/opposite/same [0,"n"],[1,"o"],[2,"s"]' ); |
| 716 |
|
| 717 |
$table3.trigger('sorton', [[ [ 0,'n'], [1,'o'], [2,'s'] ]]); |
| 718 |
assert.equal( c3.sortList + '', '0,0,1,1,2,0', 'sorton next/opposite/same [0,"n"],[1,"o"],[2,"s"]' ); |
| 719 |
|
| 720 |
}); |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
QUnit.test( 'sort Events', function(assert) { |
| 748 |
assert.expect(1); |
| 749 |
|
| 750 |
$table1.add($table5).on( events.join('.testing '), function(e){ |
| 751 |
if (e.type === events[sortIndx%3]) { |
| 752 |
sortIndx++; |
| 753 |
} |
| 754 |
}); |
| 755 |
|
| 756 |
$table1.trigger('sorton', [[[ 0,0 ]]]); |
| 757 |
$table1.trigger('sorton', [[[ 1,0 ]]]); |
| 758 |
|
| 759 |
|
| 760 |
$table5.trigger('sorton', [ [[0,0]] ]); |
| 761 |
|
| 762 |
$table1.add($table5).off( events.join('.testing ') ); |
| 763 |
|
| 764 |
|
| 765 |
assert.equal( sortIndx, 9, 'sortStart, sortBegin & sortEnd fired in order x2; including empty table' ); |
| 766 |
}); |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
QUnit.test( 'parser cache; update methods & callbacks', function(assert) { |
| 772 |
assert.expect(12); |
| 773 |
var oldColMax; |
| 774 |
c1.ignoreCase = true; |
| 775 |
|
| 776 |
$table1 |
| 777 |
.trigger('sorton', [ [[0,1]] ]) |
| 778 |
.on('updateComplete.testing', function(){ updateIndx++; }) |
| 779 |
.find('th:eq(1)').removeAttr('class').html('num').end() |
| 780 |
.find('td:nth-child(2)').html(function(i,h){ |
| 781 |
return h.substring(1); |
| 782 |
}); |
| 783 |
$table1 |
| 784 |
.trigger('updateAll', [false, function(){ |
| 785 |
updateCallback++; |
| 786 |
var nw = $table1.find('th:eq(1)')[0], |
| 787 |
ht = c1.$headers.eq(1).text() === 'num' |
| 788 |
hc = c1.headerContent[1] === 'num', |
| 789 |
hd = c1.$headers[1] === nw, |
| 790 |
hl = c1.headerList[1] === nw, |
| 791 |
p1 = c1.parsers[1].id === 'digit'; |
| 792 |
assert.equal(ht && hc && hd && hl && p1, true, 'testing header cache: updateAll - thead'); |
| 793 |
assert.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, |
| 794 |
'testc', 4, 'testb', 5, 'testa', 6, '', 0 ], 'updateAll - tbody' ); |
| 795 |
}]); |
| 796 |
|
| 797 |
|
| 798 |
$table1 |
| 799 |
.find('th:eq(1)').html('x-num').end() |
| 800 |
.trigger('updateHeaders', function(){ |
| 801 |
updateCallback++; |
| 802 |
var nw = $table1.find('th:eq(1)')[0], |
| 803 |
ht = c1.$headers.eq(1).text() === 'x-num', |
| 804 |
hc = c1.headerContent[1] === 'x-num', |
| 805 |
hd = c1.$headers[1] === nw, |
| 806 |
hl = c1.headerList[1] === nw; |
| 807 |
assert.equal(ht && hc && hd && hl, true, 'testing header cache: updateHeaders'); |
| 808 |
}); |
| 809 |
|
| 810 |
|
| 811 |
t = $('<tr class="temp"><td>testd</td><td>7</td></tr>'); |
| 812 |
$table1.find('tbody:last').prepend(t); |
| 813 |
oldColMax = c1.cache[1].colMax[1]; |
| 814 |
$table1.trigger('addRows', [t, true, function(){ |
| 815 |
updateCallback++; |
| 816 |
assert.equal( oldColMax === 6 && c1.cache[1].colMax[1] === 7, true, 'addRows includes updating colMax value'); |
| 817 |
assert.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, |
| 818 |
'testd', 7, 'testc', 4, 'testb', 5, 'testa', 6, '', 0 ], 'addRows method' ); |
| 819 |
}]); |
| 820 |
|
| 821 |
$table1.trigger('addRows', [null, true]); |
| 822 |
$table1.trigger('addRows', [$('<tr>'), true]); |
| 823 |
|
| 824 |
|
| 825 |
t = '<tr class="temp"><td>g</td><td>h</td><td>i</td><td>j</td></tr>'; |
| 826 |
$table2.trigger('addRows', [t, true, function(){ |
| 827 |
assert.cacheCompare( table2, 'all', [ 'a', 'b', 'c', 'd', |
| 828 |
'z', 'y', 'x', 'w', |
| 829 |
'g', 'h', 'i', 'j' ], 'addRows as string method' ); |
| 830 |
}]); |
| 831 |
$table2.find('tr.temp').remove(); |
| 832 |
|
| 833 |
|
| 834 |
t = $table1.find('td:contains("7")'); |
| 835 |
t.html('-8'); |
| 836 |
oldColMax = c1.cache[1].colMax[1]; |
| 837 |
$table1.trigger('updateCell', [t[0], true, function(){ |
| 838 |
updateCallback++; |
| 839 |
assert.equal( oldColMax === 7 && c1.cache[1].colMax[1] === 8, true, 'updateCell includes updating colMax value'); |
| 840 |
assert.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, |
| 841 |
'testd', -8, 'testc', 4, 'testb', 5, 'testa', 6, '', 0 ], 'updateCell method' ); |
| 842 |
}]); |
| 843 |
|
| 844 |
|
| 845 |
$table1.find('tr.temp').remove(); |
| 846 |
oldColMax = c1.cache[1].colMax[1]; |
| 847 |
$table1.trigger('update', [true, function(){ |
| 848 |
updateCallback++; |
| 849 |
assert.equal( oldColMax === 8 && c1.cache[1].colMax[1] === 6, true, 'update includes updating colMax value'); |
| 850 |
assert.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, |
| 851 |
'testc', 4, 'testb', 5, 'testa', 6, '', 0 ], 'update method' ); |
| 852 |
}]); |
| 853 |
|
| 854 |
$table5 |
| 855 |
.on('updateComplete.testing', function(){ updateIndx++; }) |
| 856 |
.trigger('update', [true, function(){ |
| 857 |
updateCallback++; |
| 858 |
assert.cacheCompare( table5, 'all', [], 'update method on empty table' ); |
| 859 |
}]); |
| 860 |
|
| 861 |
$table1.add($table5).off('updateComplete.testing'); |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
assert.equal( updateIndx, updateCallback, 'updatedComplete and update callback functions working properly' ); |
| 866 |
|
| 867 |
}); |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
QUnit.test( 'sortForce, sortAppend, sortMultiSortKey & sortResetKey; and numberSorter option', function(assert){ |
| 873 |
assert.expect(3); |
| 874 |
|
| 875 |
assert.cacheCompare( table4, 3, [ 2, 1, 7, 6, 5, 3, 4, 8, 9, 10 ], 'force x2 + sorted x2 + append x2, ascending' ); |
| 876 |
|
| 877 |
return QUnit.SequentialRunner( |
| 878 |
function(actions, assertions){ |
| 879 |
return QUnit.assertOnEvent($table4, 'sortEnd', actions, assertions); |
| 880 |
} |
| 881 |
).nextTask( |
| 882 |
function(){ |
| 883 |
c4.sortMultiSortKey = 'altKey'; |
| 884 |
c4.$headers.eq(5).trigger( $.Event('sort', { which: 1, altKey: true }) ); |
| 885 |
}, |
| 886 |
function(){ |
| 887 |
assert.cacheCompare( table4, 3, [ 2, 1, 6, 7, 5, 4, 3, 8, 10, 9 ], 'force x2 + sorted x2 + append x2, descending' ); |
| 888 |
} |
| 889 |
).nextTask( |
| 890 |
function() { |
| 891 |
c4.sortResetKey = 'shiftKey'; |
| 892 |
c4.$headers.eq(0).trigger( $.Event('sort', {which: 1, shiftKey: true}) ); |
| 893 |
}, |
| 894 |
function() { |
| 895 |
assert.cacheCompare( table4, 3, [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], 'sortResetKey' ); |
| 896 |
} |
| 897 |
).promise(); |
| 898 |
}); |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
QUnit.test( 'testing header css & sortReset method', function(assert) { |
| 904 |
assert.expect(7); |
| 905 |
t = $(th0); |
| 906 |
assert.equal( $table1.hasClass(ts.css.table), true, 'table class applied'); |
| 907 |
assert.equal( t.hasClass(ts.css.header), true, 'Header class present' ); |
| 908 |
assert.equal( t.parent().hasClass(ts.css.headerRow), true, 'Header row class present' ); |
| 909 |
assert.equal( $table1.find('tbody:eq(1)').hasClass(c1.cssInfoBlock), true, 'Tbody info block class present' ); |
| 910 |
$table1.trigger('sorton', [[[ 0,1 ]]] ); |
| 911 |
assert.equal( t.hasClass(ts.css.sortDesc), true, 'Descending class present' ); |
| 912 |
$table1.trigger('sorton', [[[ 0,0 ]]] ); |
| 913 |
assert.equal( t.hasClass(ts.css.sortAsc), true, 'Ascending class present' ); |
| 914 |
$table1.trigger('sortReset'); |
| 915 |
assert.equal( t.hasClass(ts.css.sortAsc) || t.hasClass(ts.css.sortDesc), false, 'Testing sortReset' ); |
| 916 |
}); |
| 917 |
|
| 918 |
QUnit.test( 'testing header css icons', function(assert) { |
| 919 |
var done = assert.async(); |
| 920 |
assert.expect(1); |
| 921 |
$('#testblock2').html('<table class="tablesorter"><thead><tr>' + |
| 922 |
'<th>A</th>' + |
| 923 |
'<th>B</th>' + |
| 924 |
'<th>C</th>' + |
| 925 |
'<th class="sorter-false">D</th>' + |
| 926 |
'</tr></thead><tbody></tbody></table>') |
| 927 |
.find('table') |
| 928 |
.tablesorter({ |
| 929 |
sortList: [[0,0], [1,1]], |
| 930 |
headerTemplate:'{content} {icon}', |
| 931 |
cssIconAsc: 'asc', |
| 932 |
cssIconDesc: 'desc', |
| 933 |
cssIconNone: 'none', |
| 934 |
cssIconDisabled: 'disabled', |
| 935 |
initialized: function(table){ |
| 936 |
var i, |
| 937 |
results = [], |
| 938 |
expected = ['asc', 'desc', 'none', 'disabled'], |
| 939 |
c = table.config; |
| 940 |
for (i = 0; i < c.columns; i++){ |
| 941 |
results[i] = c.$headers.eq(i).find('.' + ts.css.icon).hasClass(expected[i]); |
| 942 |
} |
| 943 |
assert.deepEqual( results, [true, true, true, true], 'applies correct cssIcon classes' ); |
| 944 |
done(); |
| 945 |
} |
| 946 |
}); |
| 947 |
}); |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
var zebra = function(){ |
| 953 |
t = true; |
| 954 |
var classes = ['odd','even']; |
| 955 |
$table2.find('tbody tr').each(function(i){ |
| 956 |
t = t ? $(this).hasClass( classes[i%2] ) : false; |
| 957 |
}); |
| 958 |
return t; |
| 959 |
}; |
| 960 |
|
| 961 |
QUnit.test( 'check widgetOption defaults across tables', function(assert) { |
| 962 |
assert.expect(4); |
| 963 |
assert.deepEqual(c1.widgetOptions.test, [0,1], 'widget option properly set'); |
| 964 |
assert.deepEqual(c2.widgetOptions.test, [0], 'widget option properly set'); |
| 965 |
assert.deepEqual(c3.widgetOptions.test, [], 'default widget option set on table'); |
| 966 |
assert.deepEqual(ts.defaults.widgetOptions.test, [], 'default widget option set in core'); |
| 967 |
}); |
| 968 |
|
| 969 |
QUnit.test( 'apply zebra widget', function(assert) { |
| 970 |
assert.expect(3); |
| 971 |
assert.equal( zebra(), false, 'zebra not applied' ); |
| 972 |
c2.widgets = [ 'zebra' ]; |
| 973 |
$table2.trigger('applyWidgets'); |
| 974 |
assert.equal( zebra(), true, 'zebra is applied' ); |
| 975 |
$table2 |
| 976 |
.append('<tr><td>s</td><td>t</td><td>u</td><td>v</td></tr>') |
| 977 |
.trigger('update'); |
| 978 |
assert.equal( zebra(), true, 'zebra is applied after update' ); |
| 979 |
}); |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
QUnit.test( 'has & remove zebra widget', function(assert) { |
| 985 |
var done = assert.async(); |
| 986 |
assert.expect(4); |
| 987 |
c2.widgets = [ 'zebra' ]; |
| 988 |
$table2.trigger('applyWidgets', function() { |
| 989 |
assert.equal( ts.hasWidget( table2, 'zebra'), true, 'table has zebra widget (using table element object)' ); |
| 990 |
assert.equal( ts.hasWidget( $table2, 'zebra'), true, 'table has zebra widget (using jQuery table object)' ); |
| 991 |
$table2.one( 'widgetRemoveEnd', function() { |
| 992 |
assert.ok( true, 'widgetRemoveEnd fired'); |
| 993 |
assert.equal( zebra() && c2.widgets.length === 0, false, 'zebra removed' ); |
| 994 |
done(); |
| 995 |
}); |
| 996 |
ts.removeWidget( table2, 'zebra' ); |
| 997 |
}); |
| 998 |
}); |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
QUnit.test('testing destroy method', function(assert) { |
| 1004 |
$table2.trigger('sorton', [[[ 0,1 ]]] ); |
| 1005 |
$table2.trigger('destroy'); |
| 1006 |
assert.expect(7); |
| 1007 |
t = $table2.find('th:first'); |
| 1008 |
e = jQuery._data(table2, 'events'); |
| 1009 |
assert.equal( $.isEmptyObject(e), true, 'no events applied' ); |
| 1010 |
assert.equal( $table2.data().hasOwnProperty('tablesorter'), false, 'Data removed' ); |
| 1011 |
assert.equal( $table2.attr('class'), 'tester', 'All table classes removed' ); |
| 1012 |
assert.equal( $table2.find('tr:first').attr('class'), '', 'Header row class removed' ); |
| 1013 |
assert.equal( t.attr('class').match('tablesorter'), null, 'Header classes removed' ); |
| 1014 |
assert.equal( t.children().length, 0, 'Inner wrapper removed' ); |
| 1015 |
assert.equal( typeof (t.data().column) , 'undefined', 'data-column removed'); |
| 1016 |
|
| 1017 |
$table2.tablesorter(); |
| 1018 |
}); |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
QUnit.test('extract widget names from table class', function(assert) { |
| 1024 |
assert.expect(2); |
| 1025 |
var widgets, |
| 1026 |
t = { |
| 1027 |
className: 'widget-filter widget-stickyHeaders ui-widget-content widget-test-2', |
| 1028 |
config: { |
| 1029 |
widgetClass: 'widget-{name}', |
| 1030 |
widgets: [] |
| 1031 |
} |
| 1032 |
}; |
| 1033 |
ts.addWidgetFromClass( t ); |
| 1034 |
assert.deepEqual( t.config.widgets, [ 'filter', 'stickyHeaders', 'test-2' ], 'Ignored "ui-widget-content"' ); |
| 1035 |
|
| 1036 |
t.className = 'stickyHeaders-widgey ui-widgey-content filter-widgey test-2-widgey'; |
| 1037 |
t.config.widgetClass = '{name}-widgey'; |
| 1038 |
t.config.widgets = []; |
| 1039 |
ts.addWidgetFromClass( t ); |
| 1040 |
assert.deepEqual( t.config.widgets, [ 'stickyHeaders', 'filter', 'test-2' ], 'Modified widgetClass option' ); |
| 1041 |
|
| 1042 |
}); |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
ipv6tests(); |
| 1049 |
|
| 1050 |
}); |