| 1 |
// DATA_TEMPLATE: empty_table |
| 2 |
/* |
| 3 |
* NOTE: There are some differences in this zero config script for server-side |
| 4 |
* processing compared to the other data sources. The main reason for this is the |
| 5 |
* difference in how the server-side processing does it's filtering. Also the |
| 6 |
* sorting state is always reset on each draw. |
| 7 |
*/ |
| 8 |
oTest.fnStart( "Sanity checks for DataTables with data from JS" ); |
| 9 |
|
| 10 |
oTest.fnWaitTest( |
| 11 |
"jQuery.dataTable function", |
| 12 |
null, |
| 13 |
function () { return typeof jQuery().dataTable == "function"; } |
| 14 |
); |
| 15 |
|
| 16 |
oTest.fnWaitTest( |
| 17 |
"jQuery.dataTableSettings storage array", |
| 18 |
null, |
| 19 |
function () { return typeof jQuery().dataTableSettings == "object"; } |
| 20 |
); |
| 21 |
|
| 22 |
oTest.fnWaitTest( |
| 23 |
"jQuery.dataTableExt plugin object", |
| 24 |
null, |
| 25 |
function () { return typeof jQuery().dataTableExt == "object"; } |
| 26 |
); |
| 27 |
|
| 28 |
$(document).ready( function () { |
| 29 |
$('#example').dataTable( { |
| 30 |
"bServerSide": true, |
| 31 |
"sAjaxSource": "../../../examples/server_side/scripts/server_processing.php" |
| 32 |
} ); |
| 33 |
|
| 34 |
/* Basic checks */ |
| 35 |
oTest.fnWaitTest( |
| 36 |
"Length changing div exists", |
| 37 |
null, |
| 38 |
function () { return document.getElementById('example_length') != null; } |
| 39 |
); |
| 40 |
|
| 41 |
oTest.fnWaitTest( |
| 42 |
"Filtering div exists", |
| 43 |
null, |
| 44 |
function () { return document.getElementById('example_filter') != null; } |
| 45 |
); |
| 46 |
|
| 47 |
oTest.fnWaitTest( |
| 48 |
"Information div exists", |
| 49 |
null, |
| 50 |
function () { return document.getElementById('example_info') != null; } |
| 51 |
); |
| 52 |
|
| 53 |
oTest.fnWaitTest( |
| 54 |
"Pagination div exists", |
| 55 |
null, |
| 56 |
function () { return document.getElementById('example_paginate') != null; } |
| 57 |
); |
| 58 |
|
| 59 |
oTest.fnWaitTest( |
| 60 |
"Processing div is off by default", |
| 61 |
null, |
| 62 |
function () { return document.getElementById('example_processing') == null; } |
| 63 |
); |
| 64 |
|
| 65 |
oTest.fnWaitTest( |
| 66 |
"10 rows shown on the first page", |
| 67 |
null, |
| 68 |
function () { return $('#example tbody tr').length == 10; } |
| 69 |
); |
| 70 |
|
| 71 |
oTest.fnWaitTest( |
| 72 |
"Initial sort occurred", |
| 73 |
null, |
| 74 |
function () { return $('#example tbody td:eq(0)').html() == "Gecko"; } |
| 75 |
); |
| 76 |
|
| 77 |
/* Need to use the WaitTest for sorting due to the setTimeout datatables uses */ |
| 78 |
oTest.fnWaitTest( |
| 79 |
"Sorting (first click) on second column", |
| 80 |
function () { $('#example thead th:eq(1)').click(); }, |
| 81 |
function () { return $('#example tbody td:eq(1)').html() == "All others"; } |
| 82 |
); |
| 83 |
|
| 84 |
oTest.fnWaitTest( |
| 85 |
"Sorting (second click) on second column", |
| 86 |
function () { $('#example thead th:eq(1)').click(); }, |
| 87 |
function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; } |
| 88 |
); |
| 89 |
|
| 90 |
oTest.fnWaitTest( |
| 91 |
"Sorting (third click) on second column", |
| 92 |
function () { $('#example thead th:eq(1)').click(); }, |
| 93 |
function () { return $('#example tbody td:eq(1)').html() == "All others"; } |
| 94 |
); |
| 95 |
|
| 96 |
oTest.fnWaitTest( |
| 97 |
"Sorting (first click) on numeric column", |
| 98 |
function () { $('#example thead th:eq(3)').click(); }, |
| 99 |
function () { return $('#example tbody td:eq(3)').html() == "-"; } |
| 100 |
); |
| 101 |
|
| 102 |
oTest.fnWaitTest( |
| 103 |
"Sorting (second click) on numeric column", |
| 104 |
function () { $('#example thead th:eq(3)').click(); }, |
| 105 |
function () { return $('#example tbody td:eq(3)').html() == "522.1"; } |
| 106 |
); |
| 107 |
|
| 108 |
oTest.fnWaitTest( |
| 109 |
"Sorting multi-column (first click)", |
| 110 |
function () { |
| 111 |
$('#example thead th:eq(0)').click(); |
| 112 |
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); }, |
| 113 |
function () { var b = |
| 114 |
$('#example tbody td:eq(0)').html() == "Gecko" && |
| 115 |
$('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; } |
| 116 |
); |
| 117 |
|
| 118 |
oTest.fnWaitTest( |
| 119 |
"Sorting multi-column - sorting first column only", |
| 120 |
function () { |
| 121 |
$('#example thead th:eq(0)').click(); }, |
| 122 |
function () { var b = |
| 123 |
$('#example tbody td:eq(0)').html() == "Gecko" && |
| 124 |
$('#example tbody td:eq(1)').html() == "Firefox 1.0"; return b; } |
| 125 |
); |
| 126 |
|
| 127 |
/* Basic paging */ |
| 128 |
oTest.fnWaitTest( |
| 129 |
"Paging to second page", |
| 130 |
function () { $('#example_next').click(); }, |
| 131 |
function () { return $('#example tbody td:eq(1)').html() == "Mozilla 1.1"; } |
| 132 |
); |
| 133 |
|
| 134 |
oTest.fnWaitTest( |
| 135 |
"Paging to first page", |
| 136 |
function () { $('#example_previous').click(); }, |
| 137 |
function () { return $('#example tbody td:eq(1)').html() == "Firefox 1.0"; } |
| 138 |
); |
| 139 |
|
| 140 |
oTest.fnWaitTest( |
| 141 |
"Attempting to page back beyond the first page", |
| 142 |
function () { $('#example_previous').click(); }, |
| 143 |
function () { return $('#example tbody td:eq(1)').html() == "Firefox 1.0"; } |
| 144 |
); |
| 145 |
|
| 146 |
/* Changing length */ |
| 147 |
oTest.fnWaitTest( |
| 148 |
"Changing table length to 25 records", |
| 149 |
function () { $("select[name=example_length]").val('25').change(); }, |
| 150 |
function () { return $('#example tbody tr').length == 25; } |
| 151 |
); |
| 152 |
|
| 153 |
oTest.fnWaitTest( |
| 154 |
"Changing table length to 50 records", |
| 155 |
function () { $("select[name=example_length]").val('50').change(); }, |
| 156 |
function () { return $('#example tbody tr').length == 50; } |
| 157 |
); |
| 158 |
|
| 159 |
oTest.fnWaitTest( |
| 160 |
"Changing table length to 100 records", |
| 161 |
function () { $("select[name=example_length]").val('100').change(); }, |
| 162 |
function () { return $('#example tbody tr').length == 57; } |
| 163 |
); |
| 164 |
|
| 165 |
oTest.fnWaitTest( |
| 166 |
"Changing table length to 10 records", |
| 167 |
function () { $("select[name=example_length]").val('10').change(); }, |
| 168 |
function () { return $('#example tbody tr').length == 10; } |
| 169 |
); |
| 170 |
|
| 171 |
/* |
| 172 |
* Information element |
| 173 |
*/ |
| 174 |
oTest.fnWaitTest( |
| 175 |
"Information on zero config", |
| 176 |
null, |
| 177 |
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } |
| 178 |
); |
| 179 |
|
| 180 |
oTest.fnWaitTest( |
| 181 |
"Information on second page", |
| 182 |
function () { $('#example_next').click(); }, |
| 183 |
function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; } |
| 184 |
); |
| 185 |
|
| 186 |
oTest.fnWaitTest( |
| 187 |
"Information on third page", |
| 188 |
function () { $('#example_next').click(); }, |
| 189 |
function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; } |
| 190 |
); |
| 191 |
|
| 192 |
oTest.fnWaitTest( |
| 193 |
"Information on last page", |
| 194 |
function () { |
| 195 |
$('#example_next').click(); |
| 196 |
$('#example_next').click(); |
| 197 |
$('#example_next').click(); |
| 198 |
}, |
| 199 |
function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; } |
| 200 |
); |
| 201 |
|
| 202 |
oTest.fnWaitTest( |
| 203 |
"Information back on first page", |
| 204 |
function () { |
| 205 |
$('#example_previous').click(); |
| 206 |
$('#example_previous').click(); |
| 207 |
$('#example_previous').click(); |
| 208 |
$('#example_previous').click(); |
| 209 |
$('#example_previous').click(); |
| 210 |
}, |
| 211 |
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } |
| 212 |
); |
| 213 |
|
| 214 |
oTest.fnWaitTest( |
| 215 |
"Information with 25 records", |
| 216 |
function () { $("select[name=example_length]").val('25').change(); }, |
| 217 |
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; } |
| 218 |
); |
| 219 |
|
| 220 |
oTest.fnWaitTest( |
| 221 |
"Information with 25 records - second page", |
| 222 |
function () { $('#example_next').click(); }, |
| 223 |
function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; } |
| 224 |
); |
| 225 |
|
| 226 |
oTest.fnWaitTest( |
| 227 |
"Information with 100 records - first page", |
| 228 |
function () { |
| 229 |
$('#example_previous').click(); |
| 230 |
$("select[name=example_length]").val('100').change(); |
| 231 |
}, |
| 232 |
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; } |
| 233 |
); |
| 234 |
|
| 235 |
oTest.fnWaitTest( |
| 236 |
"Information back to 10 records", |
| 237 |
function () { |
| 238 |
$('#example_previous').click(); |
| 239 |
$("select[name=example_length]").val('10').change(); |
| 240 |
}, |
| 241 |
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; } |
| 242 |
); |
| 243 |
|
| 244 |
oTest.fnWaitTest( |
| 245 |
"Information with filter 'Win'", |
| 246 |
function () { $('#example_filter input').val("Win").keyup(); }, |
| 247 |
function () { return document.getElementById('example_info').innerHTML == |
| 248 |
"Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } |
| 249 |
); |
| 250 |
|
| 251 |
oTest.fnWaitTest( |
| 252 |
"Information with filter 'Win' second page", |
| 253 |
function () { $('#example_next').click(); }, |
| 254 |
function () { return document.getElementById('example_info').innerHTML == |
| 255 |
"Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } |
| 256 |
); |
| 257 |
|
| 258 |
oTest.fnWaitTest( |
| 259 |
"Information with filter 'Win' last page", |
| 260 |
function () { |
| 261 |
$('#example_next').click(); |
| 262 |
$('#example_next').click(); |
| 263 |
}, |
| 264 |
function () { return document.getElementById('example_info').innerHTML == |
| 265 |
"Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; } |
| 266 |
); |
| 267 |
|
| 268 |
oTest.fnWaitTest( |
| 269 |
"Information with filter 'Win' back to first page", |
| 270 |
function () { |
| 271 |
$('#example_previous').click(); |
| 272 |
$('#example_previous').click(); |
| 273 |
$('#example_previous').click(); |
| 274 |
}, |
| 275 |
function () { return document.getElementById('example_info').innerHTML == |
| 276 |
"Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } |
| 277 |
); |
| 278 |
|
| 279 |
oTest.fnWaitTest( |
| 280 |
"Information with filter 'Win' second page - second time", |
| 281 |
function () { |
| 282 |
$('#example_next').click(); |
| 283 |
}, |
| 284 |
function () { return document.getElementById('example_info').innerHTML == |
| 285 |
"Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } |
| 286 |
); |
| 287 |
|
| 288 |
oTest.fnWaitTest( |
| 289 |
"Information with filter increased to 'Win 98'", |
| 290 |
function () { $('#example_filter input').val("Win 98").keyup(); }, |
| 291 |
function () { return document.getElementById('example_info').innerHTML == |
| 292 |
"Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; } |
| 293 |
); |
| 294 |
|
| 295 |
oTest.fnWaitTest( |
| 296 |
"Information with filter decreased to 'Win'", |
| 297 |
function () { $('#example_filter input').val("Win").keyup(); }, |
| 298 |
function () { return document.getElementById('example_info').innerHTML == |
| 299 |
"Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } |
| 300 |
); |
| 301 |
|
| 302 |
oTest.fnWaitTest( |
| 303 |
"Information with filter 'Win' second page - third time", |
| 304 |
function () { |
| 305 |
$('#example_next').click(); |
| 306 |
}, |
| 307 |
function () { return document.getElementById('example_info').innerHTML == |
| 308 |
"Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; } |
| 309 |
); |
| 310 |
|
| 311 |
oTest.fnWaitTest( |
| 312 |
"Information with filter removed", |
| 313 |
function () { $('#example_filter input').val("").keyup(); }, |
| 314 |
function () { return document.getElementById('example_info').innerHTML == |
| 315 |
"Showing 1 to 10 of 57 entries"; } |
| 316 |
); |
| 317 |
|
| 318 |
|
| 319 |
/* |
| 320 |
* Filtering |
| 321 |
*/ |
| 322 |
oTest.fnWaitTest( |
| 323 |
"Filter 'W' - rows", |
| 324 |
function () { |
| 325 |
$('#example_filter input').val("W").keyup(); }, |
| 326 |
function () { return $('#example tbody tr:eq(4) td:eq(1)').html() == "Netscape 7.2"; } |
| 327 |
); |
| 328 |
|
| 329 |
oTest.fnWaitTest( |
| 330 |
"Filter 'W' - info", |
| 331 |
null, |
| 332 |
function () { return document.getElementById('example_info').innerHTML == |
| 333 |
"Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; } |
| 334 |
); |
| 335 |
|
| 336 |
oTest.fnWaitTest( |
| 337 |
"Filter 'Wi'", |
| 338 |
function () { $('#example_filter input').val("Wi").keyup(); }, |
| 339 |
function () { return document.getElementById('example_info').innerHTML == |
| 340 |
"Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; } |
| 341 |
); |
| 342 |
|
| 343 |
oTest.fnWaitTest( |
| 344 |
"Filter 'Win'", |
| 345 |
function () { $('#example_filter input').val("Win").keyup(); }, |
| 346 |
function () { return document.getElementById('example_info').innerHTML == |
| 347 |
"Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } |
| 348 |
); |
| 349 |
|
| 350 |
oTest.fnWaitTest( |
| 351 |
"Filter 'Win' - sorting column 1", |
| 352 |
function () { $('#example thead th:eq(1)').click(); }, |
| 353 |
function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; } |
| 354 |
); |
| 355 |
|
| 356 |
oTest.fnWaitTest( |
| 357 |
"Filter 'Win' - sorting column 1 info", |
| 358 |
null, |
| 359 |
function () { return document.getElementById('example_info').innerHTML == |
| 360 |
"Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; } |
| 361 |
); |
| 362 |
|
| 363 |
oTest.fnWaitTest( |
| 364 |
"Filter 'Win' - sorting column 1 reverse", |
| 365 |
function () { $('#example thead th:eq(1)').click(); }, |
| 366 |
function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; } |
| 367 |
); |
| 368 |
|
| 369 |
oTest.fnWaitTest( |
| 370 |
"Filter 'Win XP' - maintaining reverse sorting col 1", |
| 371 |
function () { $('#example_filter input').val("Win XP").keyup(); }, |
| 372 |
function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; } |
| 373 |
); |
| 374 |
|
| 375 |
oTest.fnWaitTest( |
| 376 |
"Filter 'Win XP' - sorting col 3", |
| 377 |
function () { $('#example thead th:eq(3)').click(); }, |
| 378 |
function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "6"; } |
| 379 |
); |
| 380 |
|
| 381 |
/* Note the filtering is different from the DOM since the server doesn't do |
| 382 |
* "smart filtering" like the client side does |
| 383 |
*/ |
| 384 |
oTest.fnWaitTest( |
| 385 |
"Filter 'Win XP' - sorting col 3 - reversed", |
| 386 |
function () { $('#example thead th:eq(3)').click(); }, |
| 387 |
function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; } |
| 388 |
); |
| 389 |
|
| 390 |
oTest.fnWaitTest( |
| 391 |
"Filter 'Win' - sorting col 3 - reversed info", |
| 392 |
null, |
| 393 |
function () { return document.getElementById('example_info').innerHTML == |
| 394 |
"Showing 1 to 2 of 2 entries (filtered from 57 total entries)"; } |
| 395 |
); |
| 396 |
|
| 397 |
oTest.fnWaitTest( |
| 398 |
"Filter 'nothinghere'", |
| 399 |
function () { $('#example_filter input').val("nothinghere").keyup(); }, |
| 400 |
function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == |
| 401 |
"No matching records found"; } |
| 402 |
); |
| 403 |
|
| 404 |
oTest.fnWaitTest( |
| 405 |
"Filter 'nothinghere' - info", |
| 406 |
null, |
| 407 |
function () { return document.getElementById('example_info').innerHTML == |
| 408 |
"Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; } |
| 409 |
); |
| 410 |
|
| 411 |
oTest.fnWaitTest( |
| 412 |
"Filter back to blank and 1st column sorting", |
| 413 |
function () { |
| 414 |
$('#example_filter input').val("").keyup(); |
| 415 |
$('#example thead th:eq(0)').click(); |
| 416 |
}, |
| 417 |
function () { return document.getElementById('example_info').innerHTML == |
| 418 |
"Showing 1 to 10 of 57 entries"; } |
| 419 |
); |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
oTest.fnComplete(); |
| 424 |
} ); |