| 1 |
QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment( { |
| 2 |
beforeEach: function () { |
| 3 |
this.liveMonths = mw.language.months; |
| 4 |
mw.language.months = { |
| 5 |
keys: { |
| 6 |
names: [ 'january', 'february', 'march', 'april', 'may_long', 'june', |
| 7 |
'july', 'august', 'september', 'october', 'november', 'december' ], |
| 8 |
genitive: [ 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen', |
| 9 |
'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen', 'december-gen' ], |
| 10 |
abbrev: [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', |
| 11 |
'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ] |
| 12 |
}, |
| 13 |
names: [ 'January', 'February', 'March', 'April', 'May', 'June', |
| 14 |
'July', 'August', 'September', 'October', 'November', 'December' ], |
| 15 |
genitive: [ 'January', 'February', 'March', 'April', 'May', 'June', |
| 16 |
'July', 'August', 'September', 'October', 'November', 'December' ], |
| 17 |
abbrev: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', |
| 18 |
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] |
| 19 |
}; |
| 20 |
}, |
| 21 |
afterEach: function () { |
| 22 |
mw.language.months = this.liveMonths; |
| 23 |
}, |
| 24 |
config: { |
| 25 |
wgDefaultDateFormat: 'dmy', |
| 26 |
wgSeparatorTransformTable: [ '', '' ], |
| 27 |
wgDigitTransformTable: [ '', '' ], |
| 28 |
wgPageViewLanguage: 'en' |
| 29 |
} |
| 30 |
} ), () => { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
function tableCreate( header, data ) { |
| 40 |
const $table = $( '<table class="sortable"><thead></thead><tbody></tbody></table>' ); |
| 41 |
const $thead = $table.find( 'thead' ); |
| 42 |
const $tbody = $table.find( 'tbody' ); |
| 43 |
let $tr = $( '<tr>' ); |
| 44 |
|
| 45 |
header.forEach( ( str ) => { |
| 46 |
const $th = $( '<th>' ); |
| 47 |
$th.text( str ).appendTo( $tr ); |
| 48 |
} ); |
| 49 |
$tr.appendTo( $thead ); |
| 50 |
|
| 51 |
for ( let i = 0; i < data.length; i++ ) { |
| 52 |
$tr = $( '<tr>' ); |
| 53 |
|
| 54 |
data[ i ].forEach( ( str ) => { |
| 55 |
const $td = $( '<td>' ); |
| 56 |
$td.text( str ).appendTo( $tr ); |
| 57 |
} ); |
| 58 |
$tr.appendTo( $tbody ); |
| 59 |
} |
| 60 |
return $table; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function tableExtract( $table ) { |
| 70 |
const data = []; |
| 71 |
|
| 72 |
$table.find( 'tbody tr' ).each( ( i, tr ) => { |
| 73 |
const row = []; |
| 74 |
$( tr ).find( 'td, th' ).each( ( j, td ) => { |
| 75 |
row.push( $( td ).text() ); |
| 76 |
} ); |
| 77 |
data.push( row ); |
| 78 |
} ); |
| 79 |
return data; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
function tableTestHTML( msg, html, expected, callback ) { |
| 92 |
QUnit.test( msg, ( assert ) => { |
| 93 |
const $table = $( html ); |
| 94 |
|
| 95 |
|
| 96 |
if ( callback ) { |
| 97 |
callback( $table ); |
| 98 |
} else { |
| 99 |
$table.tablesorter(); |
| 100 |
$table.find( '#sortme' ).trigger( 'click' ); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
const extracted = tableExtract( $table ); |
| 106 |
assert.deepEqual( extracted, expected, msg ); |
| 107 |
} ); |
| 108 |
} |
| 109 |
|
| 110 |
function reversed( arr ) { |
| 111 |
|
| 112 |
const arr2 = arr.slice( 0 ); |
| 113 |
arr2.reverse(); |
| 114 |
return arr2; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
const planetHeader = [ 'Planet', 'Radius (km)' ]; |
| 119 |
const mercury = [ 'Mercury', '2439.7' ]; |
| 120 |
const venus = [ 'Venus', '6051.8' ]; |
| 121 |
const earth = [ 'Earth', '6371.0' ]; |
| 122 |
const mars = [ 'Mars', '3390.0' ]; |
| 123 |
const jupiter = [ 'Jupiter', '69911' ]; |
| 124 |
const saturn = [ 'Saturn', '58232' ]; |
| 125 |
const planets = [ mercury, venus, earth, mars, jupiter, saturn ]; |
| 126 |
const planetsAscName = [ earth, jupiter, mars, mercury, saturn, venus ]; |
| 127 |
const planetsAscRadius = [ mercury, mars, venus, earth, saturn, jupiter ]; |
| 128 |
const planetsTotal = [ [ 'total', '146395.5' ] ]; |
| 129 |
|
| 130 |
|
| 131 |
const a1 = [ 'A', '1' ]; |
| 132 |
const a2 = [ 'A', '2' ]; |
| 133 |
const a3 = [ 'A', '3' ]; |
| 134 |
const b1 = [ 'B', '1' ]; |
| 135 |
const b2 = [ 'B', '2' ]; |
| 136 |
const b3 = [ 'B', '3' ]; |
| 137 |
const simple = [ a2, b3, a1, a3, b2, b1 ]; |
| 138 |
const simpleAsc = [ a1, a2, a3, b1, b2, b3 ]; |
| 139 |
const simpleDescasc = [ b1, b2, b3, a1, a2, a3 ]; |
| 140 |
|
| 141 |
QUnit.test( |
| 142 |
'Planets: initial sort ascending by name', |
| 143 |
( assert ) => { |
| 144 |
const $table = tableCreate( planetHeader, planets ); |
| 145 |
$table.tablesorter( { sortList: [ |
| 146 |
{ 0: 'asc' } |
| 147 |
] } ); |
| 148 |
|
| 149 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 150 |
} |
| 151 |
); |
| 152 |
QUnit.test( |
| 153 |
'Planets: initial sort descending by radius', |
| 154 |
( assert ) => { |
| 155 |
const $table = tableCreate( planetHeader, planets ); |
| 156 |
$table.tablesorter( { sortList: [ |
| 157 |
{ 1: 'desc' } |
| 158 |
] } ); |
| 159 |
|
| 160 |
assert.deepEqual( tableExtract( $table ), reversed( planetsAscRadius ) ); |
| 161 |
} |
| 162 |
); |
| 163 |
QUnit.test( |
| 164 |
'Planets: ascending by name', |
| 165 |
( assert ) => { |
| 166 |
const $table = tableCreate( planetHeader, planets ); |
| 167 |
$table.tablesorter(); |
| 168 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 169 |
|
| 170 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 171 |
} |
| 172 |
); |
| 173 |
QUnit.test( |
| 174 |
'Planets: ascending by name (again)', |
| 175 |
( assert ) => { |
| 176 |
const $table = tableCreate( planetHeader, planets ); |
| 177 |
$table.tablesorter(); |
| 178 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 179 |
|
| 180 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 181 |
} |
| 182 |
); |
| 183 |
QUnit.test( |
| 184 |
'Planets: ascending by name (multiple clicks)', |
| 185 |
( assert ) => { |
| 186 |
const $table = tableCreate( planetHeader, planets ); |
| 187 |
$table.tablesorter(); |
| 188 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 189 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 190 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 191 |
|
| 192 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 193 |
} |
| 194 |
); |
| 195 |
QUnit.test( |
| 196 |
'Planets: descending by name', |
| 197 |
( assert ) => { |
| 198 |
const $table = tableCreate( planetHeader, planets ); |
| 199 |
$table.tablesorter(); |
| 200 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ).trigger( 'click' ); |
| 201 |
|
| 202 |
assert.deepEqual( tableExtract( $table ), reversed( planetsAscName ) ); |
| 203 |
} |
| 204 |
); |
| 205 |
QUnit.test( |
| 206 |
'Planets: return to initial sort', |
| 207 |
( assert ) => { |
| 208 |
const $table = tableCreate( planetHeader, planets ); |
| 209 |
$table.tablesorter(); |
| 210 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ).trigger( 'click' ).trigger( 'click' ); |
| 211 |
|
| 212 |
assert.deepEqual( tableExtract( $table ), planets ); |
| 213 |
} |
| 214 |
); |
| 215 |
QUnit.test( |
| 216 |
'Planets: ascending radius', |
| 217 |
( assert ) => { |
| 218 |
const $table = tableCreate( planetHeader, planets ); |
| 219 |
$table.tablesorter(); |
| 220 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 221 |
|
| 222 |
assert.deepEqual( tableExtract( $table ), planetsAscRadius ); |
| 223 |
} |
| 224 |
); |
| 225 |
QUnit.test( |
| 226 |
'Planets: descending radius', |
| 227 |
( assert ) => { |
| 228 |
const $table = tableCreate( planetHeader, planets ); |
| 229 |
$table.tablesorter(); |
| 230 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ).trigger( 'click' ); |
| 231 |
|
| 232 |
assert.deepEqual( tableExtract( $table ), reversed( planetsAscRadius ) ); |
| 233 |
} |
| 234 |
); |
| 235 |
QUnit.test( |
| 236 |
'Sorting multiple columns by passing sort list', |
| 237 |
( assert ) => { |
| 238 |
const $table = tableCreate( planetHeader, simple ); |
| 239 |
$table.tablesorter( |
| 240 |
{ sortList: [ |
| 241 |
{ 0: 'asc' }, |
| 242 |
{ 1: 'asc' } |
| 243 |
] } |
| 244 |
); |
| 245 |
|
| 246 |
assert.deepEqual( tableExtract( $table ), simpleAsc ); |
| 247 |
} |
| 248 |
); |
| 249 |
QUnit.test( |
| 250 |
'Sorting multiple columns by programmatically triggering sort()', |
| 251 |
( assert ) => { |
| 252 |
const $table = tableCreate( planetHeader, simple ); |
| 253 |
$table.tablesorter(); |
| 254 |
$table.data( 'tablesorter' ).sort( |
| 255 |
[ |
| 256 |
{ 0: 'desc' }, |
| 257 |
{ 1: 'asc' } |
| 258 |
] |
| 259 |
); |
| 260 |
|
| 261 |
assert.deepEqual( tableExtract( $table ), simpleDescasc ); |
| 262 |
} |
| 263 |
); |
| 264 |
QUnit.test( |
| 265 |
'Reset to initial sorting by triggering sort() without any parameters', |
| 266 |
( assert ) => { |
| 267 |
const $table = tableCreate( planetHeader, simple ); |
| 268 |
$table.tablesorter( |
| 269 |
{ sortList: [ |
| 270 |
{ 0: 'asc' }, |
| 271 |
{ 1: 'asc' } |
| 272 |
] } |
| 273 |
); |
| 274 |
$table.data( 'tablesorter' ).sort( |
| 275 |
[ |
| 276 |
{ 0: 'desc' }, |
| 277 |
{ 1: 'asc' } |
| 278 |
] |
| 279 |
); |
| 280 |
$table.data( 'tablesorter' ).sort(); |
| 281 |
|
| 282 |
assert.deepEqual( tableExtract( $table ), simpleAsc ); |
| 283 |
} |
| 284 |
); |
| 285 |
QUnit.test( |
| 286 |
'Sort via click event after having initialized the tablesorter with initial sorting', |
| 287 |
( assert ) => { |
| 288 |
const $table = tableCreate( planetHeader, simple ); |
| 289 |
$table.tablesorter( |
| 290 |
{ sortList: [ { 0: 'asc' }, { 1: 'asc' } ] } |
| 291 |
); |
| 292 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 293 |
|
| 294 |
assert.deepEqual( tableExtract( $table ), simpleDescasc ); |
| 295 |
} |
| 296 |
); |
| 297 |
QUnit.test( |
| 298 |
'Multi-sort via click event after having initialized the tablesorter with initial sorting', |
| 299 |
( assert ) => { |
| 300 |
const $table = tableCreate( planetHeader, simple ); |
| 301 |
$table.tablesorter( |
| 302 |
{ sortList: [ { 0: 'desc' }, { 1: 'desc' } ] } |
| 303 |
); |
| 304 |
|
| 305 |
|
| 306 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 307 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 308 |
|
| 309 |
|
| 310 |
const event = $.Event( 'click' ); |
| 311 |
event[ $table.data( 'tablesorter' ).config.sortMultiSortKey ] = true; |
| 312 |
$table.find( '.headerSort' ).eq( 1 ).trigger( event ); |
| 313 |
|
| 314 |
assert.deepEqual( tableExtract( $table ), simpleAsc ); |
| 315 |
} |
| 316 |
); |
| 317 |
QUnit.test( 'Reset sorting making table appear unsorted', ( assert ) => { |
| 318 |
const $table = tableCreate( planetHeader, simple ); |
| 319 |
$table.tablesorter( |
| 320 |
{ sortList: [ |
| 321 |
{ 0: 'desc' }, |
| 322 |
{ 1: 'asc' } |
| 323 |
] } |
| 324 |
); |
| 325 |
$table.data( 'tablesorter' ).sort( [] ); |
| 326 |
|
| 327 |
assert.strictEqual( |
| 328 |
$table.find( 'th.headerSortUp' ).length + $table.find( 'th.headerSortDown' ).length, |
| 329 |
0, |
| 330 |
'No sort specific sort classes addign to header cells' |
| 331 |
); |
| 332 |
|
| 333 |
assert.strictEqual( |
| 334 |
$table.find( 'th' ).first().attr( 'title' ), |
| 335 |
mw.msg( 'sort-ascending' ), |
| 336 |
'First header cell has default title' |
| 337 |
); |
| 338 |
|
| 339 |
assert.strictEqual( |
| 340 |
$table.find( 'th' ).first().attr( 'title' ), |
| 341 |
$table.find( 'th' ).last().attr( 'title' ), |
| 342 |
'Both header cells\' titles match' |
| 343 |
); |
| 344 |
} ); |
| 345 |
|
| 346 |
|
| 347 |
const header4 = [ 'column1a', 'column1b', 'column1c', 'column2' ]; |
| 348 |
const aaa1 = [ 'A', 'A', 'A', '1' ]; |
| 349 |
const aab5 = [ 'A', 'A', 'B', '5' ]; |
| 350 |
const abc3 = [ 'A', 'B', 'C', '3' ]; |
| 351 |
const bbc2 = [ 'B', 'B', 'C', '2' ]; |
| 352 |
const caa4 = [ 'C', 'A', 'A', '4' ]; |
| 353 |
const colspanInitial = [ aab5, aaa1, abc3, bbc2, caa4 ]; |
| 354 |
QUnit.test( 'Sorting with colspanned headers: spanned column', |
| 355 |
( assert ) => { |
| 356 |
const $table = tableCreate( header4, colspanInitial ); |
| 357 |
|
| 358 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 359 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 360 |
$table.find( 'tr th' ).eq( 0 ).attr( 'colspan', '3' ); |
| 361 |
|
| 362 |
$table.tablesorter(); |
| 363 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 364 |
|
| 365 |
assert.deepEqual( tableExtract( $table ), [ aaa1, aab5, abc3, bbc2, caa4 ] ); |
| 366 |
} |
| 367 |
); |
| 368 |
QUnit.test( 'Sorting with colspanned headers: sort spanned column twice', |
| 369 |
( assert ) => { |
| 370 |
const $table = tableCreate( header4, colspanInitial ); |
| 371 |
|
| 372 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 373 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 374 |
$table.find( 'tr' ).eq( 0 ).find( 'th' ).eq( 0 ).attr( 'colspan', '3' ); |
| 375 |
|
| 376 |
$table.tablesorter(); |
| 377 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 378 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 379 |
|
| 380 |
assert.deepEqual( tableExtract( $table ), [ caa4, bbc2, abc3, aab5, aaa1 ] ); |
| 381 |
} |
| 382 |
); |
| 383 |
QUnit.test( 'Sorting with colspanned headers: subsequent column', |
| 384 |
( assert ) => { |
| 385 |
const $table = tableCreate( header4, colspanInitial ); |
| 386 |
|
| 387 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 388 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 389 |
$table.find( 'tr th' ).eq( 0 ).attr( 'colspan', '3' ); |
| 390 |
|
| 391 |
$table.tablesorter(); |
| 392 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 393 |
|
| 394 |
assert.deepEqual( tableExtract( $table ), [ aaa1, bbc2, abc3, caa4, aab5 ] ); |
| 395 |
} |
| 396 |
); |
| 397 |
QUnit.test( 'Sorting with colspanned headers: sort subsequent column twice', |
| 398 |
( assert ) => { |
| 399 |
const $table = tableCreate( header4, colspanInitial ); |
| 400 |
|
| 401 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 402 |
$table.find( 'tr th' ).eq( 1 ).remove(); |
| 403 |
$table.find( 'tr th' ).eq( 0 ).attr( 'colspan', '3' ); |
| 404 |
|
| 405 |
$table.tablesorter(); |
| 406 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 407 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 408 |
|
| 409 |
assert.deepEqual( tableExtract( $table ), [ aab5, caa4, abc3, bbc2, aaa1 ] ); |
| 410 |
} |
| 411 |
); |
| 412 |
|
| 413 |
QUnit.test( 'Basic planet table: one unsortable column', ( assert ) => { |
| 414 |
const $table = tableCreate( planetHeader, planets ); |
| 415 |
$table.find( 'tr > th' ).eq( 0 ).addClass( 'unsortable' ); |
| 416 |
|
| 417 |
$table.tablesorter(); |
| 418 |
$table.find( 'tr > th' ).eq( 0 ).trigger( 'click' ); |
| 419 |
|
| 420 |
assert.deepEqual( |
| 421 |
tableExtract( $table ), |
| 422 |
planets, |
| 423 |
'table not sorted' |
| 424 |
); |
| 425 |
|
| 426 |
const $cell = $table.find( 'tr > th' ).eq( 0 ); |
| 427 |
$table.find( 'tr > th' ).eq( 1 ).trigger( 'click' ); |
| 428 |
|
| 429 |
assert.strictEqual( |
| 430 |
|
| 431 |
$cell.hasClass( 'headerSortUp' ) || $cell.hasClass( 'headerSortDown' ), |
| 432 |
false, |
| 433 |
'after sort: no class headerSortUp or headerSortDown' |
| 434 |
); |
| 435 |
|
| 436 |
assert.strictEqual( |
| 437 |
$cell.attr( 'title' ), |
| 438 |
undefined, |
| 439 |
'after sort: no title tag added' |
| 440 |
); |
| 441 |
|
| 442 |
} ); |
| 443 |
|
| 444 |
QUnit.test( |
| 445 |
'T30775: German-style (dmy) short numeric dates', |
| 446 |
( assert ) => { |
| 447 |
const $table = tableCreate( [ 'Date' ], [ |
| 448 |
|
| 449 |
[ '11.11.2011' ], |
| 450 |
[ '01.11.2011' ], |
| 451 |
[ '02.10.2011' ], |
| 452 |
[ '03.08.2011' ], |
| 453 |
[ '09.11.2011' ] |
| 454 |
] ); |
| 455 |
mw.config.set( 'wgDefaultDateFormat', 'dmy' ); |
| 456 |
mw.config.set( 'wgPageViewLanguage', 'de' ); |
| 457 |
$table.tablesorter(); |
| 458 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 459 |
|
| 460 |
assert.deepEqual( tableExtract( $table ), [ |
| 461 |
|
| 462 |
[ '03.08.2011' ], |
| 463 |
[ '02.10.2011' ], |
| 464 |
[ '01.11.2011' ], |
| 465 |
[ '09.11.2011' ], |
| 466 |
[ '11.11.2011' ] |
| 467 |
] ); |
| 468 |
} |
| 469 |
); |
| 470 |
|
| 471 |
QUnit.test( |
| 472 |
'T30775: American-style (mdy) short numeric dates', |
| 473 |
( assert ) => { |
| 474 |
const $table = tableCreate( [ 'Date' ], [ |
| 475 |
|
| 476 |
[ '11.11.2011' ], |
| 477 |
[ '01.11.2011' ], |
| 478 |
[ '02.10.2011' ], |
| 479 |
[ '03.08.2011' ], |
| 480 |
[ '09.11.2011' ] |
| 481 |
] ); |
| 482 |
mw.config.set( 'wgDefaultDateFormat', 'mdy' ); |
| 483 |
|
| 484 |
$table.tablesorter(); |
| 485 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 486 |
|
| 487 |
assert.deepEqual( tableExtract( $table ), [ |
| 488 |
|
| 489 |
[ '01.11.2011' ], |
| 490 |
[ '02.10.2011' ], |
| 491 |
[ '03.08.2011' ], |
| 492 |
[ '09.11.2011' ], |
| 493 |
[ '11.11.2011' ] |
| 494 |
] ); |
| 495 |
} |
| 496 |
); |
| 497 |
|
| 498 |
const ipv4 = [ |
| 499 |
|
| 500 |
[ '45.238.27.109' ], |
| 501 |
[ '44.172.9.22' ], |
| 502 |
[ '247.240.82.209' ], |
| 503 |
[ '204.204.132.158' ], |
| 504 |
[ '170.38.91.162' ], |
| 505 |
[ '197.219.164.9' ], |
| 506 |
[ '45.68.154.72' ], |
| 507 |
[ '182.195.149.80' ] |
| 508 |
]; |
| 509 |
const ipv4Sorted = [ |
| 510 |
|
| 511 |
[ '44.172.9.22' ], |
| 512 |
[ '45.68.154.72' ], |
| 513 |
[ '45.238.27.109' ], |
| 514 |
[ '170.38.91.162' ], |
| 515 |
[ '182.195.149.80' ], |
| 516 |
[ '197.219.164.9' ], |
| 517 |
[ '204.204.132.158' ], |
| 518 |
[ '247.240.82.209' ] |
| 519 |
]; |
| 520 |
QUnit.test( |
| 521 |
'IPv4 address sorting (T19141)', |
| 522 |
( assert ) => { |
| 523 |
const $table = tableCreate( [ 'IP' ], ipv4 ); |
| 524 |
$table.tablesorter(); |
| 525 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 526 |
|
| 527 |
assert.deepEqual( tableExtract( $table ), ipv4Sorted ); |
| 528 |
} |
| 529 |
); |
| 530 |
QUnit.test( |
| 531 |
'IPv4 address reverse sorting (T19141)', |
| 532 |
( assert ) => { |
| 533 |
const $table = tableCreate( [ 'IP' ], ipv4 ); |
| 534 |
$table.tablesorter(); |
| 535 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ).trigger( 'click' ); |
| 536 |
|
| 537 |
assert.deepEqual( tableExtract( $table ), reversed( ipv4Sorted ) ); |
| 538 |
} |
| 539 |
); |
| 540 |
|
| 541 |
const umlautWords = [ |
| 542 |
[ 'Günther' ], |
| 543 |
[ 'Peter' ], |
| 544 |
[ 'Björn' ], |
| 545 |
[ 'ä' ], |
| 546 |
[ 'z' ], |
| 547 |
[ 'Bjorn' ], |
| 548 |
[ 'BjÖrn' ], |
| 549 |
[ 'apfel' ], |
| 550 |
[ 'Apfel' ], |
| 551 |
[ 'Äpfel' ], |
| 552 |
[ 'Strasse' ], |
| 553 |
[ 'Sträßschen' ] |
| 554 |
]; |
| 555 |
const umlautWordsSortedEn = [ |
| 556 |
[ 'ä' ], |
| 557 |
[ 'Äpfel' ], |
| 558 |
[ 'apfel' ], |
| 559 |
[ 'Apfel' ], |
| 560 |
[ 'Björn' ], |
| 561 |
[ 'BjÖrn' ], |
| 562 |
[ 'Bjorn' ], |
| 563 |
[ 'Günther' ], |
| 564 |
[ 'Peter' ], |
| 565 |
[ 'Sträßschen' ], |
| 566 |
[ 'Strasse' ], |
| 567 |
[ 'z' ] |
| 568 |
]; |
| 569 |
const umlautWordsSortedSv = [ |
| 570 |
[ 'apfel' ], |
| 571 |
[ 'Apfel' ], |
| 572 |
[ 'Bjorn' ], |
| 573 |
[ 'Björn' ], |
| 574 |
[ 'BjÖrn' ], |
| 575 |
[ 'Günther' ], |
| 576 |
[ 'Peter' ], |
| 577 |
[ 'Strasse' ], |
| 578 |
[ 'Sträßschen' ], |
| 579 |
[ 'z' ], |
| 580 |
[ 'ä' ],sh |
| 581 |
[ 'Äpfel' ] |
| 582 |
]; |
| 583 |
QUnit.test( |
| 584 |
'Accented Characters with custom collation', |
| 585 |
( assert ) => { |
| 586 |
const $table = tableCreate( [ 'Name' ], umlautWords ); |
| 587 |
mw.config.set( 'tableSorterCollation', { |
| 588 |
ä: 'ae', |
| 589 |
ö: 'oe', |
| 590 |
ß: 'ss', |
| 591 |
ü: 'ue' |
| 592 |
} ); |
| 593 |
|
| 594 |
$table.tablesorter(); |
| 595 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 596 |
|
| 597 |
assert.deepEqual( tableExtract( $table ), umlautWordsSortedEn ); |
| 598 |
} |
| 599 |
); |
| 600 |
QUnit.test( |
| 601 |
'Accented Characters Swedish locale', |
| 602 |
( assert ) => { |
| 603 |
const $table = tableCreate( [ 'Name' ], umlautWords ); |
| 604 |
mw.config.set( 'wgPageViewLanguage', 'sv' ); |
| 605 |
|
| 606 |
$table.tablesorter(); |
| 607 |
|
| 608 |
$table.find( '.headerSort:eq(0)' ).trigger( 'click' ); |
| 609 |
|
| 610 |
assert.deepEqual( tableExtract( $table ), umlautWordsSortedSv ); |
| 611 |
} |
| 612 |
); |
| 613 |
QUnit.test( |
| 614 |
'Digraphs with custom collation', |
| 615 |
( assert ) => { |
| 616 |
const $table = tableCreate( [ 'City' ], [ |
| 617 |
[ 'London' ], |
| 618 |
[ 'Ljubljana' ], |
| 619 |
[ 'Luxembourg' ], |
| 620 |
[ 'Njivice' ], |
| 621 |
[ 'Norwich' ], |
| 622 |
[ 'New York' ] |
| 623 |
] ); |
| 624 |
mw.config.set( 'tableSorterCollation', { |
| 625 |
lj: 'lzzzz', |
| 626 |
nj: 'nzzzz' |
| 627 |
} ); |
| 628 |
|
| 629 |
$table.tablesorter(); |
| 630 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 631 |
|
| 632 |
assert.deepEqual( tableExtract( $table ), [ |
| 633 |
[ 'London' ], |
| 634 |
[ 'Luxembourg' ], |
| 635 |
[ 'Ljubljana' ], |
| 636 |
[ 'New York' ], |
| 637 |
[ 'Norwich' ], |
| 638 |
[ 'Njivice' ] |
| 639 |
] ); |
| 640 |
} |
| 641 |
); |
| 642 |
|
| 643 |
QUnit.test( 'Rowspan not exploded on init', ( assert ) => { |
| 644 |
const $table = tableCreate( planetHeader, planets ); |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
$table.find( 'tr' ).eq( 3 ).find( 'td' ).eq( 1 ).remove(); |
| 649 |
$table.find( 'tr' ).eq( 4 ).find( 'td' ).eq( 1 ).remove(); |
| 650 |
|
| 651 |
|
| 652 |
$table.find( 'tr' ).eq( 2 ).find( 'td' ).eq( 1 ).attr( 'rowspan', '3' ); |
| 653 |
|
| 654 |
$table.tablesorter(); |
| 655 |
|
| 656 |
assert.strictEqual( |
| 657 |
$table.find( 'tr' ).eq( 2 ).find( 'td' ).eq( 1 ).prop( 'rowSpan' ), |
| 658 |
3, |
| 659 |
'Rowspan not exploded' |
| 660 |
); |
| 661 |
} ); |
| 662 |
|
| 663 |
const planetsRowspan = [ |
| 664 |
[ 'Earth', '6051.8' ], |
| 665 |
jupiter, |
| 666 |
[ 'Mars', '6051.8' ], |
| 667 |
mercury, |
| 668 |
saturn, |
| 669 |
venus |
| 670 |
]; |
| 671 |
const planetsRowspanII = [ jupiter, mercury, saturn, venus, [ 'Venus', '6371.0' ], [ 'Venus', '3390.0' ] ]; |
| 672 |
QUnit.test( |
| 673 |
'Basic planet table: same value for multiple rows via rowspan', |
| 674 |
( assert ) => { |
| 675 |
const $table = tableCreate( planetHeader, planets ); |
| 676 |
|
| 677 |
|
| 678 |
$table.find( 'tr' ).eq( 3 ).find( 'td' ).eq( 1 ).remove(); |
| 679 |
$table.find( 'tr' ).eq( 4 ).find( 'td' ).eq( 1 ).remove(); |
| 680 |
|
| 681 |
|
| 682 |
$table.find( 'tr' ).eq( 2 ).find( 'td' ).eq( 1 ).attr( 'rowspan', '3' ); |
| 683 |
|
| 684 |
$table.tablesorter(); |
| 685 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 686 |
|
| 687 |
assert.deepEqual( tableExtract( $table ), planetsRowspan ); |
| 688 |
} |
| 689 |
); |
| 690 |
QUnit.test( |
| 691 |
'Basic planet table: same value for multiple rows via rowspan (sorting initially)', |
| 692 |
( assert ) => { |
| 693 |
const $table = tableCreate( planetHeader, planets ); |
| 694 |
|
| 695 |
|
| 696 |
$table.find( 'tr' ).eq( 3 ).find( 'td' ).eq( 1 ).remove(); |
| 697 |
$table.find( 'tr' ).eq( 4 ).find( 'td' ).eq( 1 ).remove(); |
| 698 |
|
| 699 |
|
| 700 |
$table.find( 'tr' ).eq( 2 ).find( 'td' ).eq( 1 ).attr( 'rowspan', '3' ); |
| 701 |
|
| 702 |
$table.tablesorter( { sortList: [ |
| 703 |
{ 0: 'asc' } |
| 704 |
] } ); |
| 705 |
|
| 706 |
assert.deepEqual( tableExtract( $table ), planetsRowspan ); |
| 707 |
} |
| 708 |
); |
| 709 |
QUnit.test( |
| 710 |
'Basic planet table: Same value for multiple rows via rowspan II', |
| 711 |
( assert ) => { |
| 712 |
const $table = tableCreate( planetHeader, planets ); |
| 713 |
|
| 714 |
|
| 715 |
$table.find( 'tr' ).eq( 3 ).find( 'td' ).eq( 0 ).remove(); |
| 716 |
$table.find( 'tr' ).eq( 4 ).find( 'td' ).eq( 0 ).remove(); |
| 717 |
|
| 718 |
|
| 719 |
$table.find( 'tr' ).eq( 2 ).find( 'td' ).eq( 0 ).attr( 'rowspan', '3' ); |
| 720 |
|
| 721 |
$table.tablesorter(); |
| 722 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 723 |
|
| 724 |
assert.deepEqual( tableExtract( $table ), planetsRowspanII ); |
| 725 |
} |
| 726 |
); |
| 727 |
|
| 728 |
QUnit.test( |
| 729 |
'Complex date parsing I', |
| 730 |
( assert ) => { |
| 731 |
const $table = tableCreate( [ 'Date' ], [ |
| 732 |
[ 'January, 19 2010' ], |
| 733 |
[ 'April 21 1991' ], |
| 734 |
[ '04 22 1991' ], |
| 735 |
[ '5.12.1990' ], |
| 736 |
[ 'December 12 \'10' ] |
| 737 |
] ); |
| 738 |
mw.config.set( 'wgDefaultDateFormat', 'mdy' ); |
| 739 |
|
| 740 |
$table.tablesorter(); |
| 741 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 742 |
|
| 743 |
assert.deepEqual( tableExtract( $table ), [ |
| 744 |
[ '5.12.1990' ], |
| 745 |
[ 'April 21 1991' ], |
| 746 |
[ '04 22 1991' ], |
| 747 |
[ 'January, 19 2010' ], |
| 748 |
[ 'December 12 \'10' ] |
| 749 |
] ); |
| 750 |
} |
| 751 |
); |
| 752 |
|
| 753 |
QUnit.test( |
| 754 |
'Currency parsing I', |
| 755 |
( assert ) => { |
| 756 |
const $table = tableCreate( [ 'Currency' ], [ |
| 757 |
[ '1.02 $' ], |
| 758 |
[ '$ 3.00' ], |
| 759 |
[ '€ 2,99' ], |
| 760 |
[ '$ 1.00' ], |
| 761 |
[ '$3.50' ], |
| 762 |
[ '$ 1.50' ], |
| 763 |
[ '€ 0.99' ] |
| 764 |
] ); |
| 765 |
$table.tablesorter(); |
| 766 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 767 |
|
| 768 |
assert.deepEqual( tableExtract( $table ), [ |
| 769 |
[ '€ 0.99' ], |
| 770 |
[ '$ 1.00' ], |
| 771 |
[ '1.02 $' ], |
| 772 |
[ '$ 1.50' ], |
| 773 |
[ '$ 3.00' ], |
| 774 |
[ '$3.50' ], |
| 775 |
|
| 776 |
|
| 777 |
[ '€ 2,99' ] |
| 778 |
] ); |
| 779 |
} |
| 780 |
); |
| 781 |
|
| 782 |
QUnit.test( |
| 783 |
'Handling of .sortbottom', |
| 784 |
( assert ) => { |
| 785 |
const $table = tableCreate( planetHeader, planets.concat( planetsTotal ) ); |
| 786 |
$table.find( 'tr' ).last().addClass( 'sortbottom' ); |
| 787 |
$table.tablesorter(); |
| 788 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 789 |
|
| 790 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 791 |
} |
| 792 |
); |
| 793 |
|
| 794 |
QUnit.test( |
| 795 |
'Handling of .sorttop', |
| 796 |
( assert ) => { |
| 797 |
const $table = tableCreate( planetHeader, planetsTotal.concat( planets ) ); |
| 798 |
$table.find( 'tbody > tr' ).first().addClass( 'sorttop' ); |
| 799 |
$table.tablesorter(); |
| 800 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 801 |
|
| 802 |
assert.deepEqual( tableExtract( $table ), planetsAscName ); |
| 803 |
} |
| 804 |
); |
| 805 |
|
| 806 |
QUnit.test( 'Rowspan invalid value (T265503)', ( assert ) => { |
| 807 |
const rowspanText = 'Row 1 col 3, Row 2 col 3, row 3 col 3 (but there is no row 3)'; |
| 808 |
const $table = $( |
| 809 |
'<table class="sortable">' + |
| 810 |
'<thead>' + |
| 811 |
'<tr><th>table heading 1</th><th>table heading 2</th><th>table heading 3</th></tr>' + |
| 812 |
'</thead>' + |
| 813 |
'<tr><td>Row 1 col 1</td><td>Row 1 col 2</td>' + |
| 814 |
'<td rowspan="3">' + rowspanText + '</td>' + |
| 815 |
'</tr>' + |
| 816 |
'<tr><td>Row 2 col 1</td><td>Row 2 col 2</td></tr>' + |
| 817 |
'</table>' |
| 818 |
); |
| 819 |
$table.tablesorter(); |
| 820 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 821 |
assert.strictEqual( |
| 822 |
$table.find( 'tr' ).eq( 1 ).find( 'td' ).eq( 2 ).text(), |
| 823 |
rowspanText, |
| 824 |
'The invalid rowspan didn\'t throw an error and was setup correctly' |
| 825 |
); |
| 826 |
} ); |
| 827 |
|
| 828 |
QUnit.test( 'Test sort buttons not added to .sorttop row', ( assert ) => { |
| 829 |
const $table = $( |
| 830 |
'<table class="sortable">' + |
| 831 |
'<tr><th>Data</th></tr>' + |
| 832 |
'<tr class="sorttop"><th>2</th></tr>' + |
| 833 |
'<tr><td>1</td></tr>' + |
| 834 |
'<tr><td>1</td></tr>' + |
| 835 |
'</table>' |
| 836 |
); |
| 837 |
$table.tablesorter(); |
| 838 |
assert.strictEqual( |
| 839 |
$table.find( '.headerSort' ).eq( 0 ).text(), |
| 840 |
'Data', |
| 841 |
'Sort buttons are added to a header row without class sorttop' |
| 842 |
); |
| 843 |
} ); |
| 844 |
|
| 845 |
QUnit.test( 'Test detection routine', ( assert ) => { |
| 846 |
const $table = $( |
| 847 |
'<table class="sortable">' + |
| 848 |
'<caption>CAPTION</caption>' + |
| 849 |
'<tr><th>THEAD</th></tr>' + |
| 850 |
'<tr><td>1</td></tr>' + |
| 851 |
'<tr class="sortbottom"><td>text</td></tr>' + |
| 852 |
'</table>' |
| 853 |
); |
| 854 |
$table.tablesorter(); |
| 855 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 856 |
|
| 857 |
assert.strictEqual( |
| 858 |
$table.data( 'tablesorter' ).config.parsers[ 0 ].id, |
| 859 |
'number', |
| 860 |
'Correctly detected column content skipping sortbottom' |
| 861 |
); |
| 862 |
} ); |
| 863 |
|
| 864 |
|
| 865 |
QUnit.test( 'T34047 - caption must be before thead', ( assert ) => { |
| 866 |
const $table = $( |
| 867 |
'<table class="sortable">' + |
| 868 |
'<caption>CAPTION</caption>' + |
| 869 |
'<tr><th>THEAD</th></tr>' + |
| 870 |
'<tr><td>A</td></tr>' + |
| 871 |
'<tr><td>B</td></tr>' + |
| 872 |
'<tr class="sortbottom"><td>TFOOT</td></tr>' + |
| 873 |
'</table>' |
| 874 |
); |
| 875 |
$table.tablesorter(); |
| 876 |
|
| 877 |
assert.strictEqual( |
| 878 |
$table.children().get( 0 ).nodeName, |
| 879 |
'CAPTION', |
| 880 |
'First element after <thead> must be <caption> (T34047)' |
| 881 |
); |
| 882 |
} ); |
| 883 |
|
| 884 |
QUnit.test( 'data-sort-value attribute, when available, should override sorting position', ( assert ) => { |
| 885 |
|
| 886 |
|
| 887 |
let $table = $( |
| 888 |
'<table class="sortable"><thead><tr><th>Data</th></tr></thead>' + |
| 889 |
'<tbody>' + |
| 890 |
'<tr><td>Cheetah</td></tr>' + |
| 891 |
'<tr><td data-sort-value="Apple">Bird</td></tr>' + |
| 892 |
'<tr><td data-sort-value="Bananna">Ferret</td></tr>' + |
| 893 |
'<tr><td data-sort-value="Drupe">Elephant</td></tr>' + |
| 894 |
'<tr><td data-sort-value="Cherry">Dolphin</td></tr>' + |
| 895 |
'</tbody></table>' |
| 896 |
); |
| 897 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 898 |
|
| 899 |
let data = []; |
| 900 |
$table.find( 'tbody > tr' ).each( ( i, tr ) => { |
| 901 |
$( tr ).find( 'td' ).each( ( j, td ) => { |
| 902 |
data.push( { |
| 903 |
data: $( td ).data( 'sortValue' ), |
| 904 |
text: $( td ).text() |
| 905 |
} ); |
| 906 |
} ); |
| 907 |
} ); |
| 908 |
|
| 909 |
assert.deepEqual( data, [ |
| 910 |
{ |
| 911 |
data: 'Apple', |
| 912 |
text: 'Bird' |
| 913 |
}, |
| 914 |
{ |
| 915 |
data: 'Bananna', |
| 916 |
text: 'Ferret' |
| 917 |
}, |
| 918 |
{ |
| 919 |
data: undefined, |
| 920 |
text: 'Cheetah' |
| 921 |
}, |
| 922 |
{ |
| 923 |
data: 'Cherry', |
| 924 |
text: 'Dolphin' |
| 925 |
}, |
| 926 |
{ |
| 927 |
data: 'Drupe', |
| 928 |
text: 'Elephant' |
| 929 |
} |
| 930 |
], 'Order matches expected order (based on data-sort-value attribute values)' ); |
| 931 |
|
| 932 |
|
| 933 |
$table = $( |
| 934 |
'<table class="sortable"><thead><tr><th>Data</th></tr></thead>' + |
| 935 |
'<tbody>' + |
| 936 |
'<tr><td>D</td></tr>' + |
| 937 |
'<tr><td data-sort-value="E">A</td></tr>' + |
| 938 |
'<tr><td>B</td></tr>' + |
| 939 |
'<tr><td>G</td></tr>' + |
| 940 |
'<tr><td data-sort-value="F">C</td></tr>' + |
| 941 |
'<tr><td><span data-sort-value="D">H</span></td></tr>' + |
| 942 |
'</tbody></table>' |
| 943 |
); |
| 944 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 945 |
|
| 946 |
data = []; |
| 947 |
$table.find( 'tbody > tr' ).each( ( i, tr ) => { |
| 948 |
$( tr ).find( 'td' ).each( ( j, td ) => { |
| 949 |
data.push( { |
| 950 |
data: $( td ).data( 'sortValue' ), |
| 951 |
text: $( td ).text() |
| 952 |
} ); |
| 953 |
} ); |
| 954 |
} ); |
| 955 |
|
| 956 |
assert.deepEqual( data, [ |
| 957 |
{ |
| 958 |
data: undefined, |
| 959 |
text: 'B' |
| 960 |
}, |
| 961 |
{ |
| 962 |
data: undefined, |
| 963 |
text: 'D' |
| 964 |
}, |
| 965 |
{ |
| 966 |
data: undefined, |
| 967 |
text: 'H' |
| 968 |
}, |
| 969 |
{ |
| 970 |
data: 'E', |
| 971 |
text: 'A' |
| 972 |
}, |
| 973 |
{ |
| 974 |
data: 'F', |
| 975 |
text: 'C' |
| 976 |
}, |
| 977 |
{ |
| 978 |
data: undefined, |
| 979 |
text: 'G' |
| 980 |
} |
| 981 |
], 'Order matches expected order (based on data-sort-value attribute values)' ); |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
$table = $( |
| 986 |
'<table class="sortable"><thead><tr><th>Data</th></tr></thead>' + |
| 987 |
'<tbody>' + |
| 988 |
'<tr><td>D</td></tr>' + |
| 989 |
'<tr><td data-sort-value="1">A</td></tr>' + |
| 990 |
'<tr><td>B</td></tr>' + |
| 991 |
'<tr><td data-sort-value="2">G</td></tr>' + |
| 992 |
'<tr><td>C</td></tr>' + |
| 993 |
'</tbody></table>' |
| 994 |
); |
| 995 |
|
| 996 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
$table.find( 'td:contains(A)' ).data( 'sortValue', 3 ); |
| 1001 |
|
| 1002 |
$table.find( 'td:contains(B)' ).data( 'sortValue', 1 ); |
| 1003 |
|
| 1004 |
$table.find( 'td:contains(G)' ).removeData( 'sortValue' ); |
| 1005 |
|
| 1006 |
|
| 1007 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1008 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1009 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1010 |
|
| 1011 |
data = []; |
| 1012 |
$table.find( 'tbody > tr' ).each( ( i, tr ) => { |
| 1013 |
$( tr ).find( 'td' ).each( ( j, td ) => { |
| 1014 |
data.push( { |
| 1015 |
data: $( td ).data( 'sortValue' ), |
| 1016 |
text: $( td ).text() |
| 1017 |
} ); |
| 1018 |
} ); |
| 1019 |
} ); |
| 1020 |
|
| 1021 |
assert.deepEqual( data, [ |
| 1022 |
{ |
| 1023 |
data: 1, |
| 1024 |
text: 'B' |
| 1025 |
}, |
| 1026 |
{ |
| 1027 |
data: 2, |
| 1028 |
text: 'G' |
| 1029 |
}, |
| 1030 |
{ |
| 1031 |
data: 3, |
| 1032 |
text: 'A' |
| 1033 |
}, |
| 1034 |
{ |
| 1035 |
data: undefined, |
| 1036 |
text: 'C' |
| 1037 |
}, |
| 1038 |
{ |
| 1039 |
data: undefined, |
| 1040 |
text: 'D' |
| 1041 |
} |
| 1042 |
], 'Order matches expected order, using the current sortValue in $.data()' ); |
| 1043 |
} ); |
| 1044 |
|
| 1045 |
const numbers = [ |
| 1046 |
[ '12' ], |
| 1047 |
[ '7' ], |
| 1048 |
[ '13,000' ], |
| 1049 |
[ '9' ], |
| 1050 |
[ '14' ], |
| 1051 |
[ '8.0' ] |
| 1052 |
]; |
| 1053 |
const numbersAsc = [ |
| 1054 |
[ '7' ], |
| 1055 |
[ '8.0' ], |
| 1056 |
[ '9' ], |
| 1057 |
[ '12' ], |
| 1058 |
[ '14' ], |
| 1059 |
[ '13,000' ] |
| 1060 |
]; |
| 1061 |
QUnit.test( 'T10115: sort numbers with commas (ascending)', |
| 1062 |
( assert ) => { |
| 1063 |
const $table = tableCreate( [ 'Numbers' ], numbers ); |
| 1064 |
$table.tablesorter(); |
| 1065 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1066 |
|
| 1067 |
assert.deepEqual( tableExtract( $table ), numbersAsc ); |
| 1068 |
} |
| 1069 |
); |
| 1070 |
|
| 1071 |
QUnit.test( 'T10115: sort numbers with commas (descending)', |
| 1072 |
( assert ) => { |
| 1073 |
const $table = tableCreate( [ 'Numbers' ], numbers ); |
| 1074 |
$table.tablesorter(); |
| 1075 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ).trigger( 'click' ); |
| 1076 |
|
| 1077 |
assert.deepEqual( tableExtract( $table ), reversed( numbersAsc ) ); |
| 1078 |
} |
| 1079 |
); |
| 1080 |
|
| 1081 |
|
| 1082 |
QUnit.test( 'T34888 - Tables inside a tableheader cell', ( assert ) => { |
| 1083 |
const $table = $( |
| 1084 |
'<table class="sortable" id="mw-bug-32888">' + |
| 1085 |
'<tr><th>header<table id="mw-bug-32888-2">' + |
| 1086 |
'<tr><th>1</th><th>2</th></tr>' + |
| 1087 |
'</table></th></tr>' + |
| 1088 |
'<tr><td>A</td></tr>' + |
| 1089 |
'<tr><td>B</td></tr>' + |
| 1090 |
'</table>' |
| 1091 |
); |
| 1092 |
$table.tablesorter(); |
| 1093 |
|
| 1094 |
assert.strictEqual( |
| 1095 |
$table.find( '> thead > tr > th.headerSort' ).length, |
| 1096 |
1, |
| 1097 |
'Child tables inside a headercell should not interfere with sortable headers (T34888)' |
| 1098 |
); |
| 1099 |
assert.strictEqual( |
| 1100 |
$( '#mw-bug-32888-2' ).find( 'th.headerSort' ).length, |
| 1101 |
0, |
| 1102 |
'The headers of child tables inside a headercell should not be sortable themselves (T34888)' |
| 1103 |
); |
| 1104 |
} ); |
| 1105 |
|
| 1106 |
QUnit.test( |
| 1107 |
'Correct date sorting I', |
| 1108 |
( assert ) => { |
| 1109 |
const $table = tableCreate( [ 'Date' ], [ |
| 1110 |
[ '01 January 2010' ], |
| 1111 |
[ '05 February 2010' ], |
| 1112 |
[ '16 January 2010' ] |
| 1113 |
] ); |
| 1114 |
mw.config.set( 'wgDefaultDateFormat', 'mdy' ); |
| 1115 |
|
| 1116 |
$table.tablesorter(); |
| 1117 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1118 |
|
| 1119 |
assert.deepEqual( tableExtract( $table ), [ |
| 1120 |
[ '01 January 2010' ], |
| 1121 |
[ '16 January 2010' ], |
| 1122 |
[ '05 February 2010' ] |
| 1123 |
] ); |
| 1124 |
} |
| 1125 |
); |
| 1126 |
|
| 1127 |
QUnit.test( |
| 1128 |
'Correct date sorting II', |
| 1129 |
( assert ) => { |
| 1130 |
const $table = tableCreate( [ 'Date' ], [ |
| 1131 |
[ 'January 01 2010' ], |
| 1132 |
[ 'February 05 2010' ], |
| 1133 |
[ 'January 16 2010' ] |
| 1134 |
] ); |
| 1135 |
mw.config.set( 'wgDefaultDateFormat', 'dmy' ); |
| 1136 |
|
| 1137 |
$table.tablesorter(); |
| 1138 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1139 |
|
| 1140 |
assert.deepEqual( tableExtract( $table ), [ |
| 1141 |
[ 'January 01 2010' ], |
| 1142 |
[ 'January 16 2010' ], |
| 1143 |
[ 'February 05 2010' ] |
| 1144 |
] ); |
| 1145 |
} |
| 1146 |
); |
| 1147 |
|
| 1148 |
QUnit.test( |
| 1149 |
'ISO date sorting', |
| 1150 |
( assert ) => { |
| 1151 |
const $table = tableCreate( [ 'ISO date' ], [ |
| 1152 |
[ '2010-02-01' ], |
| 1153 |
[ '2009-12-25T12:30:45.001Z' ], |
| 1154 |
[ '2010-01-31' ], |
| 1155 |
[ '2009' ], |
| 1156 |
[ '2009-12-25T12:30:45' ], |
| 1157 |
[ '2009-12-25T12:30:45.111' ], |
| 1158 |
[ '2009-12-25T12:30:45+01:00' ] |
| 1159 |
] ); |
| 1160 |
mw.config.set( 'wgDefaultDateFormat', 'dmy' ); |
| 1161 |
|
| 1162 |
$table.tablesorter(); |
| 1163 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1164 |
|
| 1165 |
assert.deepEqual( tableExtract( $table ), [ |
| 1166 |
[ '2009' ], |
| 1167 |
[ '2009-12-25T12:30:45' ], |
| 1168 |
[ '2009-12-25T12:30:45.001Z' ], |
| 1169 |
[ '2009-12-25T12:30:45.111' ], |
| 1170 |
|
| 1171 |
[ '2009-12-25T12:30:45+01:00' ], |
| 1172 |
[ '2010-01-31' ], |
| 1173 |
[ '2010-02-01' ] |
| 1174 |
] ); |
| 1175 |
} |
| 1176 |
); |
| 1177 |
|
| 1178 |
QUnit.test( 'Sorting images using alt text', ( assert ) => { |
| 1179 |
const $table = $( |
| 1180 |
'<table class="sortable">' + |
| 1181 |
'<tr><th>THEAD</th></tr>' + |
| 1182 |
'<tr><td><img alt="2"/></td></tr>' + |
| 1183 |
'<tr><td>1</td></tr>' + |
| 1184 |
'</table>' |
| 1185 |
); |
| 1186 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1187 |
|
| 1188 |
assert.strictEqual( |
| 1189 |
$table.find( 'td' ).first().text(), |
| 1190 |
'1', |
| 1191 |
'Applied correct sorting order' |
| 1192 |
); |
| 1193 |
} ); |
| 1194 |
|
| 1195 |
QUnit.test( 'Sorting images using alt text (complex)', ( assert ) => { |
| 1196 |
const $table = $( |
| 1197 |
'<table class="sortable">' + |
| 1198 |
'<tr><th>THEAD</th></tr>' + |
| 1199 |
'<tr><td><img alt="D" />A</td></tr>' + |
| 1200 |
'<tr><td>CC</td></tr>' + |
| 1201 |
'<tr><td><a><img alt="A" /></a>F</tr>' + |
| 1202 |
'<tr><td><img alt="A" /><strong>E</strong></tr>' + |
| 1203 |
'<tr><td><strong><img alt="A" />D</strong></tr>' + |
| 1204 |
'<tr><td><img alt="A" />C</tr>' + |
| 1205 |
'</table>' |
| 1206 |
); |
| 1207 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1208 |
|
| 1209 |
assert.strictEqual( |
| 1210 |
$table.find( 'td' ).text(), |
| 1211 |
'CDEFCCA', |
| 1212 |
'Applied correct sorting order' |
| 1213 |
); |
| 1214 |
} ); |
| 1215 |
|
| 1216 |
QUnit.test( 'Sorting images using alt text (with format autodetection)', ( assert ) => { |
| 1217 |
const $table = $( |
| 1218 |
'<table class="sortable">' + |
| 1219 |
'<tr><th>THEAD</th></tr>' + |
| 1220 |
'<tr><td><img alt="1" />7</td></tr>' + |
| 1221 |
'<tr><td>1<img alt="6" /></td></tr>' + |
| 1222 |
'<tr><td>5</td></tr>' + |
| 1223 |
'<tr><td>4</td></tr>' + |
| 1224 |
'</table>' |
| 1225 |
); |
| 1226 |
$table.tablesorter().find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1227 |
|
| 1228 |
assert.strictEqual( |
| 1229 |
$table.find( 'td' ).text(), |
| 1230 |
'4517', |
| 1231 |
'Applied correct sorting order' |
| 1232 |
); |
| 1233 |
} ); |
| 1234 |
|
| 1235 |
QUnit.test( 'T40911 - The row with the largest amount of columns should receive the sort indicators', ( assert ) => { |
| 1236 |
const $table = $( |
| 1237 |
'<table class="sortable">' + |
| 1238 |
'<thead>' + |
| 1239 |
'<tr><th rowspan="2" id="A1">A1</th><th colspan="2">B2a</th></tr>' + |
| 1240 |
'<tr><th id="B2b">B2b</th><th id="C2b">C2b</th></tr>' + |
| 1241 |
'</thead>' + |
| 1242 |
'<tr><td>A</td><td>Aa</td><td>Ab</td></tr>' + |
| 1243 |
'<tr><td>B</td><td>Ba</td><td>Bb</td></tr>' + |
| 1244 |
'</table>' |
| 1245 |
); |
| 1246 |
$table.tablesorter(); |
| 1247 |
|
| 1248 |
assert.strictEqual( |
| 1249 |
$table.find( '#A1' ).attr( 'class' ), |
| 1250 |
'headerSort', |
| 1251 |
'The first column of the first row should be sortable' |
| 1252 |
); |
| 1253 |
assert.strictEqual( |
| 1254 |
$table.find( '#B2b' ).attr( 'class' ), |
| 1255 |
'headerSort', |
| 1256 |
'The th element of the 2nd row of the 2nd column should be sortable' |
| 1257 |
); |
| 1258 |
assert.strictEqual( |
| 1259 |
$table.find( '#C2b' ).attr( 'class' ), |
| 1260 |
'headerSort', |
| 1261 |
'The th element of the 2nd row of the 3rd column should be sortable' |
| 1262 |
); |
| 1263 |
} ); |
| 1264 |
|
| 1265 |
QUnit.test( 'rowspans in table headers should prefer the last row when rows are equal in length', ( assert ) => { |
| 1266 |
const $table = $( |
| 1267 |
'<table class="sortable">' + |
| 1268 |
'<thead>' + |
| 1269 |
'<tr><th rowspan="2" id="A1">A1</th><th>B2a</th></tr>' + |
| 1270 |
'<tr><th id="B2b">B2b</th></tr>' + |
| 1271 |
'</thead>' + |
| 1272 |
'<tr><td>A</td><td>Aa</td></tr>' + |
| 1273 |
'<tr><td>B</td><td>Ba</td></tr>' + |
| 1274 |
'</table>' |
| 1275 |
); |
| 1276 |
$table.tablesorter(); |
| 1277 |
|
| 1278 |
assert.strictEqual( |
| 1279 |
$table.find( '#A1' ).attr( 'class' ), |
| 1280 |
'headerSort', |
| 1281 |
'The first column of the first row should be sortable' |
| 1282 |
); |
| 1283 |
assert.strictEqual( |
| 1284 |
$table.find( '#B2b' ).attr( 'class' ), |
| 1285 |
'headerSort', |
| 1286 |
'The th element of the 2nd row of the 2nd column should be sortable' |
| 1287 |
); |
| 1288 |
} ); |
| 1289 |
|
| 1290 |
QUnit.test( 'holes in the table headers should not throw JS errors', ( assert ) => { |
| 1291 |
const $table = $( |
| 1292 |
'<table class="sortable">' + |
| 1293 |
'<thead>' + |
| 1294 |
'<tr><th id="A1">A1</th><th>B1</th><th id="C1" rowspan="2">C1</th></tr>' + |
| 1295 |
'<tr><th id="A2">A2</th></tr>' + |
| 1296 |
'</thead>' + |
| 1297 |
'<tr><td>A</td><td>Aa</td><td>Aaa</td></tr>' + |
| 1298 |
'<tr><td>B</td><td>Ba</td><td>Bbb</td></tr>' + |
| 1299 |
'</table>' |
| 1300 |
); |
| 1301 |
$table.tablesorter(); |
| 1302 |
assert.strictEqual( $table.find( '#A2' ).data( 'headerIndex' ), |
| 1303 |
undefined, |
| 1304 |
'A2 should not be a sort header' |
| 1305 |
); |
| 1306 |
assert.strictEqual( $table.find( '#C1' ).data( 'headerIndex' ), |
| 1307 |
2, |
| 1308 |
'C1 should be a sort header' |
| 1309 |
); |
| 1310 |
} ); |
| 1311 |
|
| 1312 |
|
| 1313 |
QUnit.test( 'td cells in thead should not be taken into account for longest row calculation', ( assert ) => { |
| 1314 |
const $table = $( |
| 1315 |
'<table class="sortable">' + |
| 1316 |
'<thead>' + |
| 1317 |
'<tr><th id="A1">A1</th><th>B1</th><td id="C1">C1</td></tr>' + |
| 1318 |
'<tr><th id="A2">A2</th><th>B2</th><th id="C2">C2</th></tr>' + |
| 1319 |
'</thead>' + |
| 1320 |
'</table>' |
| 1321 |
); |
| 1322 |
$table.tablesorter(); |
| 1323 |
assert.strictEqual( $table.find( '#C2' ).data( 'headerIndex' ), |
| 1324 |
2, |
| 1325 |
'C2 should be a sort header' |
| 1326 |
); |
| 1327 |
assert.strictEqual( $table.find( '#C1' ).data( 'headerIndex' ), |
| 1328 |
undefined, |
| 1329 |
'C1 should not be a sort header' |
| 1330 |
); |
| 1331 |
} ); |
| 1332 |
|
| 1333 |
|
| 1334 |
tableTestHTML( |
| 1335 |
'Rowspan exploding with row headers', |
| 1336 |
'<table class="sortable">' + |
| 1337 |
'<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' + |
| 1338 |
'<tbody>' + |
| 1339 |
'<tr><td>1</td><th rowspan="2">foo</th><td rowspan="2">bar</td><td>baz</td></tr>' + |
| 1340 |
'<tr><td>2</td><td>baz</td></tr>' + |
| 1341 |
'</tbody></table>', |
| 1342 |
[ |
| 1343 |
[ '1', 'foo', 'bar', 'baz' ], |
| 1344 |
[ '2', 'foo', 'bar', 'baz' ] |
| 1345 |
] |
| 1346 |
); |
| 1347 |
|
| 1348 |
|
| 1349 |
QUnit.test( |
| 1350 |
'Rowspan exploding with row headers and colspans', ( assert ) => { |
| 1351 |
const $table = $( '<table class="sortable">' + |
| 1352 |
'<thead><tr><th rowspan="2">n</th><th colspan="2">foo</th><th rowspan="2">baz</th></tr>' + |
| 1353 |
'<tr><th>foo</th><th>bar</th></tr></thead>' + |
| 1354 |
'<tbody>' + |
| 1355 |
'<tr><td>1</td><td>foo</td><td>bar</td><td>baz</td></tr>' + |
| 1356 |
'<tr><td>2</td><td>foo</td><td>bar</td><td>baz</td></tr>' + |
| 1357 |
'</tbody></table>' ); |
| 1358 |
|
| 1359 |
$table.tablesorter(); |
| 1360 |
assert.strictEqual( $table.find( 'tr' ).eq( 1 ).find( 'th' ).eq( 1 ).data( 'headerIndex' ), |
| 1361 |
2, |
| 1362 |
'Incorrect index of sort header' |
| 1363 |
); |
| 1364 |
} |
| 1365 |
); |
| 1366 |
|
| 1367 |
tableTestHTML( |
| 1368 |
'Rowspan exploding with colspanned cells', |
| 1369 |
'<table class="sortable">' + |
| 1370 |
'<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' + |
| 1371 |
'<tbody>' + |
| 1372 |
'<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td></tr>' + |
| 1373 |
'<tr><td>2</td><td colspan="2">foobar</td></tr>' + |
| 1374 |
'</tbody></table>', |
| 1375 |
[ |
| 1376 |
[ '1', 'foo', 'bar', 'baz' ], |
| 1377 |
[ '2', 'foobar', 'baz' ] |
| 1378 |
] |
| 1379 |
); |
| 1380 |
|
| 1381 |
tableTestHTML( |
| 1382 |
'Rowspan exploding with colspanned cells (2)', |
| 1383 |
'<table class="sortable">' + |
| 1384 |
'<thead><tr><th>n</th><th>foo</th><th>bar</th><th>baz</th><th id="sortme">n2</th></tr></thead>' + |
| 1385 |
'<tbody>' + |
| 1386 |
'<tr><td>1</td><td>foo</td><td>bar</td><td rowspan="2">baz</td><td>2</td></tr>' + |
| 1387 |
'<tr><td>2</td><td colspan="2">foobar</td><td>1</td></tr>' + |
| 1388 |
'</tbody></table>', |
| 1389 |
[ |
| 1390 |
[ '2', 'foobar', 'baz', '1' ], |
| 1391 |
[ '1', 'foo', 'bar', 'baz', '2' ] |
| 1392 |
] |
| 1393 |
); |
| 1394 |
|
| 1395 |
tableTestHTML( |
| 1396 |
'Rowspan exploding with rightmost rows spanning most', |
| 1397 |
'<table class="sortable">' + |
| 1398 |
'<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th></tr></thead>' + |
| 1399 |
'<tbody>' + |
| 1400 |
'<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td></tr>' + |
| 1401 |
'<tr><td>2</td></tr>' + |
| 1402 |
'<tr><td>3</td><td rowspan="2">foo</td></tr>' + |
| 1403 |
'<tr><td>4</td></tr>' + |
| 1404 |
'</tbody></table>', |
| 1405 |
[ |
| 1406 |
[ '1', 'foo', 'bar' ], |
| 1407 |
[ '2', 'foo', 'bar' ], |
| 1408 |
[ '3', 'foo', 'bar' ], |
| 1409 |
[ '4', 'foo', 'bar' ] |
| 1410 |
] |
| 1411 |
); |
| 1412 |
|
| 1413 |
tableTestHTML( |
| 1414 |
'Rowspan exploding with rightmost rows spanning most (2)', |
| 1415 |
'<table class="sortable">' + |
| 1416 |
'<thead><tr><th id="sortme">n</th><th>foo</th><th>bar</th><th>baz</th></tr></thead>' + |
| 1417 |
'<tbody>' + |
| 1418 |
'<tr><td>1</td><td rowspan="2">foo</td><td rowspan="4">bar</td><td>baz</td></tr>' + |
| 1419 |
'<tr><td>2</td><td>baz</td></tr>' + |
| 1420 |
'<tr><td>3</td><td rowspan="2">foo</td><td>baz</td></tr>' + |
| 1421 |
'<tr><td>4</td><td>baz</td></tr>' + |
| 1422 |
'</tbody></table>', |
| 1423 |
[ |
| 1424 |
[ '1', 'foo', 'bar', 'baz' ], |
| 1425 |
[ '2', 'foo', 'bar', 'baz' ], |
| 1426 |
[ '3', 'foo', 'bar', 'baz' ], |
| 1427 |
[ '4', 'foo', 'bar', 'baz' ] |
| 1428 |
] |
| 1429 |
); |
| 1430 |
|
| 1431 |
tableTestHTML( |
| 1432 |
'Rowspan exploding with row-and-colspanned cells', |
| 1433 |
'<table class="sortable">' + |
| 1434 |
'<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>bar</th><th>baz</th></tr></thead>' + |
| 1435 |
'<tbody>' + |
| 1436 |
'<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="4">bar</td><td>baz</td></tr>' + |
| 1437 |
'<tr><td>2</td><td>baz</td></tr>' + |
| 1438 |
'<tr><td>3</td><td colspan="2" rowspan="2">foo</td><td>baz</td></tr>' + |
| 1439 |
'<tr><td>4</td><td>baz</td></tr>' + |
| 1440 |
'</tbody></table>', |
| 1441 |
[ |
| 1442 |
[ '1', 'foo1', 'foo2', 'bar', 'baz' ], |
| 1443 |
[ '2', 'foo1', 'foo2', 'bar', 'baz' ], |
| 1444 |
[ '3', 'foo', 'bar', 'baz' ], |
| 1445 |
[ '4', 'foo', 'bar', 'baz' ] |
| 1446 |
] |
| 1447 |
); |
| 1448 |
|
| 1449 |
tableTestHTML( |
| 1450 |
'Rowspan exploding with uneven rowspan layout', |
| 1451 |
'<table class="sortable">' + |
| 1452 |
'<thead><tr><th id="sortme">n</th><th>foo1</th><th>foo2</th><th>foo3</th><th>bar</th><th>baz</th></tr></thead>' + |
| 1453 |
'<tbody>' + |
| 1454 |
'<tr><td>1</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>bar</td><td>baz</td></tr>' + |
| 1455 |
'<tr><td>2</td><td rowspan="3">bar</td><td>baz</td></tr>' + |
| 1456 |
'<tr><td>3</td><td rowspan="2">foo1</td><td rowspan="2">foo2</td><td rowspan="2">foo3</td><td>baz</td></tr>' + |
| 1457 |
'<tr><td>4</td><td>baz</td></tr>' + |
| 1458 |
'</tbody></table>', |
| 1459 |
[ |
| 1460 |
[ '1', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ], |
| 1461 |
[ '2', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ], |
| 1462 |
[ '3', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ], |
| 1463 |
[ '4', 'foo1', 'foo2', 'foo3', 'bar', 'baz' ] |
| 1464 |
] |
| 1465 |
); |
| 1466 |
|
| 1467 |
QUnit.test( 'T105731 - incomplete rows in table body', ( assert ) => { |
| 1468 |
const $table = $( |
| 1469 |
'<table class="sortable">' + |
| 1470 |
'<tr><th>A</th><th>B</th></tr>' + |
| 1471 |
'<tr><td>3</td></tr>' + |
| 1472 |
'<tr><td>1</td><td>2</td></tr>' + |
| 1473 |
'</table>' |
| 1474 |
); |
| 1475 |
$table.tablesorter(); |
| 1476 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1477 |
|
| 1478 |
$table.find( '.headerSort' ).eq( 1 ).trigger( 'click' ); |
| 1479 |
|
| 1480 |
const parsers = $table.data( 'tablesorter' ).config.parsers; |
| 1481 |
|
| 1482 |
assert.strictEqual( |
| 1483 |
parsers.length, |
| 1484 |
2, |
| 1485 |
'detectParserForColumn() detect 2 parsers' |
| 1486 |
); |
| 1487 |
|
| 1488 |
assert.strictEqual( |
| 1489 |
parsers[ 1 ].id, |
| 1490 |
'number', |
| 1491 |
'detectParserForColumn() detect parser.id "number" for second column' |
| 1492 |
); |
| 1493 |
|
| 1494 |
assert.strictEqual( |
| 1495 |
parsers[ 1 ].format( $table.find( 'tbody > tr > td' ).eq( 1 ).text() ), |
| 1496 |
-Infinity, |
| 1497 |
'empty cell is sorted as number -Infinity' |
| 1498 |
); |
| 1499 |
} ); |
| 1500 |
|
| 1501 |
QUnit.test( 'bug T114721 - use of expand-child class', ( assert ) => { |
| 1502 |
const $table = $( |
| 1503 |
'<table class="sortable">' + |
| 1504 |
'<tr><th>A</th><th>B</th></tr>' + |
| 1505 |
'<tr><td>b</td><td>4</td></tr>' + |
| 1506 |
'<tr class="expand-child"><td colspan="2">some text follow b</td></tr>' + |
| 1507 |
'<tr><td>a</td><td>2</td></tr>' + |
| 1508 |
'<tr class="expand-child"><td colspan="2">some text follow a</td></tr>' + |
| 1509 |
'<tr class="expand-child"><td colspan="2">more text</td></tr>' + |
| 1510 |
'</table>' |
| 1511 |
); |
| 1512 |
$table.tablesorter(); |
| 1513 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1514 |
|
| 1515 |
assert.deepEqual( |
| 1516 |
tableExtract( $table ), |
| 1517 |
[ |
| 1518 |
[ 'a', '2' ], |
| 1519 |
[ 'some text follow a' ], |
| 1520 |
[ 'more text' ], |
| 1521 |
[ 'b', '4' ], |
| 1522 |
[ 'some text follow b' ] |
| 1523 |
], |
| 1524 |
'row with expand-child class follow above row' |
| 1525 |
); |
| 1526 |
|
| 1527 |
const parsers = $table.data( 'tablesorter' ).config.parsers; |
| 1528 |
assert.strictEqual( |
| 1529 |
parsers[ 1 ].id, |
| 1530 |
'number', |
| 1531 |
'detectParserForColumn() detect parser.id "number" for second column' |
| 1532 |
); |
| 1533 |
} ); |
| 1534 |
QUnit.test( 'T29745 - References ignored in sortkey', ( assert ) => { |
| 1535 |
const $table = $( |
| 1536 |
'<table class="sortable">' + |
| 1537 |
'<tr><th>A</th></tr>' + |
| 1538 |
'<tr><td>10</td></tr>' + |
| 1539 |
'<tr><td>2<sup class="reference"><a href="#cite_note-1">[1]</a></sup></td></tr>' + |
| 1540 |
'</table>' |
| 1541 |
); |
| 1542 |
$table.tablesorter(); |
| 1543 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1544 |
|
| 1545 |
assert.deepEqual( |
| 1546 |
tableExtract( $table ), |
| 1547 |
[ |
| 1548 |
[ '2[1]' ], |
| 1549 |
[ '10' ] |
| 1550 |
], |
| 1551 |
'References ignored in sortkey' |
| 1552 |
); |
| 1553 |
|
| 1554 |
const parsers = $table.data( 'tablesorter' ).config.parsers; |
| 1555 |
assert.strictEqual( |
| 1556 |
parsers[ 0 ].id, |
| 1557 |
'number', |
| 1558 |
'detectParserForColumn() detect parser.id "number"' |
| 1559 |
); |
| 1560 |
} ); |
| 1561 |
|
| 1562 |
QUnit.test( 'T311145 - style tags ignored in sortkey', ( assert ) => { |
| 1563 |
const $table = $( |
| 1564 |
'<table class="sortable">' + |
| 1565 |
'<tr><th>A</th></tr>' + |
| 1566 |
'<tr><td>10</td></tr>' + |
| 1567 |
'<tr><td>2<style>.sortable { display:none; }</style></td></tr>' + |
| 1568 |
'</table>' |
| 1569 |
); |
| 1570 |
$table.tablesorter(); |
| 1571 |
$table.find( '.headerSort' ).eq( 0 ).trigger( 'click' ); |
| 1572 |
|
| 1573 |
assert.deepEqual( |
| 1574 |
tableExtract( $table ), |
| 1575 |
[ |
| 1576 |
|
| 1577 |
[ '2.sortable { display:none; }' ], |
| 1578 |
[ '10' ] |
| 1579 |
], |
| 1580 |
'style tags in sortkey' |
| 1581 |
); |
| 1582 |
|
| 1583 |
const parsers = $table.data( 'tablesorter' ).config.parsers; |
| 1584 |
assert.strictEqual( |
| 1585 |
parsers[ 0 ].id, |
| 1586 |
'number', |
| 1587 |
'detectParserForColumn() detect parser.id "number"' |
| 1588 |
); |
| 1589 |
} ); |
| 1590 |
|
| 1591 |
QUnit.module( 'parsers', ( hooks ) => { |
| 1592 |
hooks.beforeEach( function () { |
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
this.parser = function assertParser( assert, parserId, data ) { |
| 1605 |
const parser = $.tablesorter.getParser( parserId ); |
| 1606 |
data.forEach( ( testcase ) => { |
| 1607 |
const extractedR = parser.is( testcase[ 0 ] ); |
| 1608 |
const extractedF = parser.format( testcase[ 0 ] ); |
| 1609 |
|
| 1610 |
assert.strictEqual( extractedR, testcase[ 1 ], 'Detect: ' + testcase[ 3 ] ); |
| 1611 |
assert.strictEqual( extractedF, testcase[ 2 ], 'Sortkey: ' + testcase[ 3 ] ); |
| 1612 |
} ); |
| 1613 |
}; |
| 1614 |
} ); |
| 1615 |
|
| 1616 |
QUnit.test( 'Textual keys', function ( assert ) { |
| 1617 |
this.parser( assert, 'text', [ |
| 1618 |
[ 'Mars', true, 'Mars', 'Simple text' ], |
| 1619 |
[ 'Mẘas', true, 'Mẘas', 'Non ascii character' ], |
| 1620 |
[ 'A sentence', true, 'A sentence', 'A sentence with space chars' ] |
| 1621 |
] ); |
| 1622 |
} ); |
| 1623 |
|
| 1624 |
QUnit.test( 'IPv4', function ( assert ) { |
| 1625 |
this.parser( assert, 'IPAddress', [ |
| 1626 |
|
| 1627 |
[ '0.0.0.0', true, 0, 'An IP address' ], |
| 1628 |
[ '255.255.255.255', true, 255255255255, 'An IP address' ], |
| 1629 |
[ '45.238.27.109', true, 45238027109, 'An IP address' ], |
| 1630 |
[ '1.238.27.1', true, 1238027001, 'An IP address with small numbers' ], |
| 1631 |
[ '238.27.1', false, 238027001, 'A malformed IP Address' ], |
| 1632 |
[ '1', false, 1, 'A super malformed IP Address' ], |
| 1633 |
[ 'Just text', false, -Infinity, 'A line with just text' ], |
| 1634 |
[ '45.238.27.109Postfix', false, 45238027109, 'An IP address with a connected postfix' ], |
| 1635 |
[ '45.238.27.109 postfix', false, 45238027109, 'An IP address with a separated postfix' ] |
| 1636 |
] ); |
| 1637 |
} ); |
| 1638 |
|
| 1639 |
QUnit.test( 'MDY Dates using mdy content language', function ( assert ) { |
| 1640 |
this.parser( assert, 'date', [ |
| 1641 |
[ 'January 17, 2010', true, 20100117, 'Long middle endian date' ], |
| 1642 |
[ 'Jan 17, 2010', true, 20100117, 'Short middle endian date' ], |
| 1643 |
[ '1/17/2010', true, 20100117, 'Numeric middle endian date' ], |
| 1644 |
[ '01/17/2010', true, 20100117, 'Numeric middle endian date with padding on month' ], |
| 1645 |
[ '01/07/2010', true, 20100107, 'Numeric middle endian date with padding on day' ], |
| 1646 |
[ '01/07/0010', true, 20100107, 'Numeric middle endian date with padding on year' ], |
| 1647 |
[ '5.12.1990', true, 19900512, 'Numeric middle endian date with . separator' ] |
| 1648 |
] ); |
| 1649 |
} ); |
| 1650 |
|
| 1651 |
QUnit.test( 'MDY Dates using dmy content language', function ( assert ) { |
| 1652 |
mw.config.set( { |
| 1653 |
wgDefaultDateFormat: 'dmy', |
| 1654 |
wgPageViewLanguage: 'de' |
| 1655 |
} ); |
| 1656 |
this.parser( assert, 'date', [ |
| 1657 |
[ 'January 17, 2010', true, 20100117, 'Long middle endian date' ], |
| 1658 |
[ 'Jan 17, 2010', true, 20100117, 'Short middle endian date' ], |
| 1659 |
[ '1/17/2010', true, 20101701, 'Numeric middle endian date' ], |
| 1660 |
[ '01/17/2010', true, 20101701, 'Numeric middle endian date with padding on month' ], |
| 1661 |
[ '01/07/2010', true, 20100701, 'Numeric middle endian date with padding on day' ], |
| 1662 |
[ '01/07/0010', true, 20100701, 'Numeric middle endian date with padding on year' ], |
| 1663 |
[ '5.12.1990', true, 19901205, 'Numeric middle endian date with . separator' ] |
| 1664 |
] ); |
| 1665 |
} ); |
| 1666 |
|
| 1667 |
QUnit.test( 'Very old MDY dates', function ( assert ) { |
| 1668 |
this.parser( assert, 'date', [ |
| 1669 |
[ 'January 19, 1400 BC', false, '99999999', 'BC' ], |
| 1670 |
[ 'January 19, 1400BC', false, '99999999', 'Connected BC' ], |
| 1671 |
[ 'January, 19 1400 B.C.', false, '99999999', 'B.C.' ], |
| 1672 |
[ 'January 19, 1400 AD', false, '99999999', 'AD' ], |
| 1673 |
[ 'January, 19 10', true, 20100119, 'AD' ], |
| 1674 |
[ 'January, 19 1', false, '99999999', 'AD' ] |
| 1675 |
] ); |
| 1676 |
} ); |
| 1677 |
|
| 1678 |
QUnit.test( 'MDY Dates', function ( assert ) { |
| 1679 |
this.parser( assert, 'date', [ |
| 1680 |
[ 'January, 19 2010', true, 20100119, 'Comma after month' ], |
| 1681 |
[ 'January 19, 2010', true, 20100119, 'Comma after day' ], |
| 1682 |
[ 'January/19/2010', true, 20100119, 'Forward slash separator' ], |
| 1683 |
[ '04 22 1991', true, 19910422, 'Month with 0 padding' ], |
| 1684 |
[ 'April 21 1991', true, 19910421, 'Space separation' ], |
| 1685 |
[ '04 22 1991', true, 19910422, 'Month with 0 padding' ], |
| 1686 |
[ 'December 12 \'10', true, 20101212, '' ], |
| 1687 |
[ 'Dec 12 \'10', true, 20101212, '' ], |
| 1688 |
[ 'Dec. 12 \'10', true, 20101212, '' ] |
| 1689 |
] ); |
| 1690 |
} ); |
| 1691 |
|
| 1692 |
QUnit.test( 'DMY Dates', function ( assert ) { |
| 1693 |
mw.config.set( { |
| 1694 |
wgDefaultDateFormat: 'dmy', |
| 1695 |
wgPageViewLanguage: 'it' |
| 1696 |
} ); |
| 1697 |
this.parser( assert, 'date', [ |
| 1698 |
[ '1º January 2010', true, 20100101, 'T305375 - dates with the ordinal indicator º' ] |
| 1699 |
] ); |
| 1700 |
} ); |
| 1701 |
|
| 1702 |
QUnit.test( 'Clobbered Dates', function ( assert ) { |
| 1703 |
this.parser( assert, 'date', [ |
| 1704 |
[ 'January, 19 2010 - January, 20 2010', false, '99999999', 'Date range with hyphen' ], |
| 1705 |
[ 'January, 19 2010 — January, 20 2010', false, '99999999', 'Date range with mdash' ], |
| 1706 |
[ 'prefixJanuary, 19 2010', false, '99999999', 'Connected prefix' ], |
| 1707 |
[ 'prefix January, 19 2010', false, '99999999', 'Prefix' ], |
| 1708 |
[ 'December 12 2010postfix', false, '99999999', 'ConnectedPostfix' ], |
| 1709 |
[ 'December 12 2010 postfix', false, '99999999', 'Postfix' ], |
| 1710 |
[ 'A simple text', false, '99999999', 'Plain text in date sort' ], |
| 1711 |
[ '04l22l1991', false, '99999999', 'l char as separator' ], |
| 1712 |
[ 'January\\19\\2010', false, '99999999', 'backslash as date separator' ] |
| 1713 |
] ); |
| 1714 |
} ); |
| 1715 |
|
| 1716 |
QUnit.test( 'MY Dates', function ( assert ) { |
| 1717 |
this.parser( assert, 'date', [ |
| 1718 |
[ 'December 2010', false, '99999999', 'Plain month year' ], |
| 1719 |
[ 'Dec 2010', false, '99999999', 'Abreviated month year' ], |
| 1720 |
[ '12 2010', false, '99999999', 'Numeric month year' ] |
| 1721 |
] ); |
| 1722 |
} ); |
| 1723 |
|
| 1724 |
QUnit.test( 'Y Dates', function ( assert ) { |
| 1725 |
this.parser( assert, 'date', [ |
| 1726 |
[ '2010', false, '99999999', 'Plain 4-digit year' ], |
| 1727 |
[ '876', false, '99999999', '3-digit year' ], |
| 1728 |
[ '76', false, '99999999', '2-digit year' ], |
| 1729 |
[ '\'76', false, '99999999', '2-digit millenium bug year' ], |
| 1730 |
[ '2010 BC', false, '99999999', '4-digit year BC' ] |
| 1731 |
] ); |
| 1732 |
} ); |
| 1733 |
|
| 1734 |
QUnit.test( 'Currency', function ( assert ) { |
| 1735 |
this.parser( assert, 'currency', [ |
| 1736 |
[ '1.02 $', true, 1.02, '' ], |
| 1737 |
[ '$ 3.00', true, 3, '' ], |
| 1738 |
[ '€ 2,99', true, 299, '' ], |
| 1739 |
[ '$ 1.00', true, 1, '' ], |
| 1740 |
[ '$3.50', true, 3.50, '' ], |
| 1741 |
[ '$ 1.50', true, 1.50, '' ], |
| 1742 |
[ '€ 0.99', true, 0.99, '' ], |
| 1743 |
[ '$ 299.99', true, 299.99, '' ], |
| 1744 |
[ '$ 2,299.99', true, 2299.99, '' ], |
| 1745 |
[ '$ 2,989', true, 2989, '' ], |
| 1746 |
[ '$ 2 299.99', true, 2299.99, '' ], |
| 1747 |
[ '$ 2 989', true, 2989, '' ], |
| 1748 |
[ '$ 2.989', true, 2.989, '' ] |
| 1749 |
] ); |
| 1750 |
} ); |
| 1751 |
|
| 1752 |
QUnit.test( 'Currency with european separators', function ( assert ) { |
| 1753 |
mw.config.set( { |
| 1754 |
|
| 1755 |
|
| 1756 |
wgSeparatorTransformTable: [ ',\t.\t,', '\'\t,\t.' ], |
| 1757 |
wgDigitTransformTable: [ '', '' ] |
| 1758 |
} ); |
| 1759 |
this.parser( assert, 'currency', [ |
| 1760 |
[ '1.02 $', true, 102, '' ], |
| 1761 |
[ '$ 3.00', true, 300, '' ], |
| 1762 |
[ '€ 2,99', true, 2.99, '' ], |
| 1763 |
[ '$ 1.00', true, 100, '' ], |
| 1764 |
[ '$3.50', true, 350, '' ], |
| 1765 |
[ '$ 1.50', true, 150, '' ], |
| 1766 |
[ '€ 0.99', true, 99, '' ], |
| 1767 |
[ '$ 299.99', true, 29999, '' ], |
| 1768 |
[ '$ 2\'299,99', true, 2299.99, '' ], |
| 1769 |
[ '$ 2,989', true, 2.989, '' ], |
| 1770 |
[ '$ 2 299.99', true, 229999, '' ], |
| 1771 |
[ '2 989 $', true, 2989, '' ], |
| 1772 |
[ '299.99 $', true, 29999, '' ], |
| 1773 |
[ '2\'299,99 $', true, 2299.99, '' ], |
| 1774 |
[ '2,989 $', true, 2.989, '' ], |
| 1775 |
[ '2 299.99 $', true, 229999, '' ], |
| 1776 |
[ '2 989 $', true, 2989, '' ] |
| 1777 |
] ); |
| 1778 |
} ); |
| 1779 |
|
| 1780 |
QUnit.test( 'T114604 - Breaking tfoot with rowspans', ( assert ) => { |
| 1781 |
const $table = $( |
| 1782 |
'<table class="sortable">' + |
| 1783 |
'<tr><th>A1</th><th>A2</th></tr>' + |
| 1784 |
'<tr><td>B1</td><td>B2</td></tr>' + |
| 1785 |
'<tr><th>C1</th><th>C2</th></tr>' + |
| 1786 |
'<tr><td>D1</td><td rowspan="2">D2</td></tr>' + |
| 1787 |
'<tr><th>E1</th></tr>' + |
| 1788 |
'<tr><th>F1</th><th>F2</th></tr>' + |
| 1789 |
'</table>' |
| 1790 |
), |
| 1791 |
data = { |
| 1792 |
THEAD: [], |
| 1793 |
TBODY: [], |
| 1794 |
TFOOT: [] |
| 1795 |
}; |
| 1796 |
|
| 1797 |
$table.tablesorter(); |
| 1798 |
|
| 1799 |
$table.find( 'thead,tbody,tfoot' ).find( 'tr' ).each( function () { |
| 1800 |
const row = [], |
| 1801 |
group = $( this ).parent().prop( 'nodeName' ); |
| 1802 |
|
| 1803 |
$( this ).find( 'td,th' ).each( function () { |
| 1804 |
row.push( $( this ).text() ); |
| 1805 |
} ); |
| 1806 |
|
| 1807 |
data[ group ].push( row ); |
| 1808 |
} ); |
| 1809 |
|
| 1810 |
assert.deepEqual( |
| 1811 |
data, |
| 1812 |
{ |
| 1813 |
THEAD: [ |
| 1814 |
[ 'A1', 'A2' ] |
| 1815 |
], |
| 1816 |
TBODY: [ |
| 1817 |
[ 'B1', 'B2' ], |
| 1818 |
[ 'C1', 'C2' ], |
| 1819 |
[ 'D1', 'D2' ], |
| 1820 |
[ 'E1' ] |
| 1821 |
], |
| 1822 |
TFOOT: [ |
| 1823 |
[ 'F1', 'F2' ] |
| 1824 |
] |
| 1825 |
}, |
| 1826 |
'Row with rowspan td not added to tfoot' |
| 1827 |
); |
| 1828 |
} ); |
| 1829 |
|
| 1830 |
|
| 1831 |
} ); |
| 1832 |
|
| 1833 |
} ); |