1 // DATA_TEMPLATE: js_data
2 oTest.fnStart( "Sanity checks for DataTables with data from JS" );
5 "jQuery.dataTable function",
7 function () { return typeof jQuery().dataTable == "function"; }
11 "jQuery.dataTableSettings storage array",
13 function () { return typeof jQuery().dataTableSettings == "object"; }
17 "jQuery.dataTableExt plugin object",
19 function () { return typeof jQuery().dataTableExt == "object"; }
22 $(document).ready( function () {
26 $('#example').dataTable( oInit );
30 "Length changing div exists",
32 function () { return document.getElementById('example_length') != null; }
36 "Filtering div exists",
38 function () { return document.getElementById('example_filter') != null; }
42 "Information div exists",
44 function () { return document.getElementById('example_info') != null; }
48 "Pagination div exists",
50 function () { return document.getElementById('example_paginate') != null; }
54 "Processing div is off by default",
56 function () { return document.getElementById('example_processing') == null; }
60 "10 rows shown on the first page",
62 function () { return $('#example tbody tr').length == 10; }
66 "Initial sort occured",
68 function () { return $('#example tbody td:eq(0)').html() == "Gecko"; }
71 /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
73 "Sorting (first click) on second column",
74 function () { $('#example thead th:eq(1)').click(); },
75 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
79 "Sorting (second click) on second column",
80 function () { $('#example thead th:eq(1)').click(); },
81 function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; }
85 "Sorting (third click) on second column",
86 function () { $('#example thead th:eq(1)').click(); },
87 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
91 "Sorting (first click) on numeric column",
92 function () { $('#example thead th:eq(3)').click(); },
93 function () { return $('#example tbody td:eq(3)').html() == "-"; }
97 "Sorting (second click) on numeric column",
98 function () { $('#example thead th:eq(3)').click(); },
99 function () { return $('#example tbody td:eq(3)').html() == "522.1"; }
103 "Sorting multi-column (first click)",
105 $('#example thead th:eq(0)').click();
106 oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); },
107 function () { var b =
108 $('#example tbody td:eq(0)').html() == "Gecko" &&
109 $('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; }
113 "Sorting multi-column - sorting second column only",
115 $('#example thead th:eq(1)').click(); },
116 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
121 "Paging to second page",
122 function () { $('#example_next').click(); },
123 function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; }
127 "Paging to first page",
128 function () { $('#example_previous').click(); },
129 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
133 "Attempting to page back beyond the first page",
134 function () { $('#example_previous').click(); },
135 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
138 /* Changing length */
140 "Changing table length to 25 records",
141 function () { $("select[name=example_length]").val('25').change(); },
142 function () { return $('#example tbody tr').length == 25; }
146 "Changing table length to 50 records",
147 function () { $("select[name=example_length]").val('50').change(); },
148 function () { return $('#example tbody tr').length == 50; }
152 "Changing table length to 100 records",
153 function () { $("select[name=example_length]").val('100').change(); },
154 function () { return $('#example tbody tr').length == 57; }
158 "Changing table length to 10 records",
159 function () { $("select[name=example_length]").val('10').change(); },
160 function () { return $('#example tbody tr').length == 10; }
164 * Information element
167 "Information on zero config",
169 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
173 "Information on second page",
174 function () { $('#example_next').click(); },
175 function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; }
179 "Information on third page",
180 function () { $('#example_next').click(); },
181 function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; }
185 "Information on last page",
187 $('#example_next').click();
188 $('#example_next').click();
189 $('#example_next').click();
191 function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; }
195 "Information back on first page",
197 $('#example_previous').click();
198 $('#example_previous').click();
199 $('#example_previous').click();
200 $('#example_previous').click();
201 $('#example_previous').click();
203 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
207 "Information with 25 records",
208 function () { $("select[name=example_length]").val('25').change(); },
209 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; }
213 "Information with 25 records - second page",
214 function () { $('#example_next').click(); },
215 function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; }
219 "Information with 100 records - first page",
221 $('#example_previous').click();
222 $("select[name=example_length]").val('100').change();
224 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; }
228 "Information back to 10 records",
230 $('#example_previous').click();
231 $("select[name=example_length]").val('10').change();
233 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
237 "Information with filter 'Win'",
238 function () { $('#example_filter input').val("Win").keyup(); },
239 function () { return document.getElementById('example_info').innerHTML ==
240 "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
244 "Information with filter 'Win' second page",
245 function () { $('#example_next').click(); },
246 function () { return document.getElementById('example_info').innerHTML ==
247 "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
251 "Information with filter 'Win' last page",
253 $('#example_next').click();
254 $('#example_next').click();
256 function () { return document.getElementById('example_info').innerHTML ==
257 "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; }
261 "Information with filter 'Win' back to first page",
263 $('#example_previous').click();
264 $('#example_previous').click();
265 $('#example_previous').click();
267 function () { return document.getElementById('example_info').innerHTML ==
268 "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
272 "Information with filter 'Win' second page - second time",
274 $('#example_next').click();
276 function () { return document.getElementById('example_info').innerHTML ==
277 "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
281 "Information with filter increased to 'Win 98'",
282 function () { $('#example_filter input').val("Win 98").keyup(); },
283 function () { return document.getElementById('example_info').innerHTML ==
284 "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; }
288 "Information with filter decreased to 'Win'",
289 function () { $('#example_filter input').val("Win").keyup(); },
290 function () { return document.getElementById('example_info').innerHTML ==
291 "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
295 "Information with filter 'Win' second page - third time",
297 $('#example_next').click();
299 function () { return document.getElementById('example_info').innerHTML ==
300 "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
304 "Information with filter removed",
305 function () { $('#example_filter input').val("").keyup(); },
306 function () { return document.getElementById('example_info').innerHTML ==
307 "Showing 1 to 10 of 57 entries"; }
317 /* Reset the table such that the old sorting doesn't mess things up */
318 oSession.fnRestore();
319 $('#example').dataTable( oInit );
320 $('#example_filter input').val("W").keyup(); },
321 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "Gecko"; }
327 function () { return document.getElementById('example_info').innerHTML ==
328 "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; }
333 function () { $('#example_filter input').val("Wi").keyup(); },
334 function () { return document.getElementById('example_info').innerHTML ==
335 "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; }
340 function () { $('#example_filter input').val("Win").keyup(); },
341 function () { return document.getElementById('example_info').innerHTML ==
342 "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
346 "Filter 'Win' - sorting column 1",
347 function () { $('#example thead th:eq(1)').click(); },
348 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "AOL browser (AOL desktop)"; }
352 "Filter 'Win' - sorting column 1 info",
354 function () { return document.getElementById('example_info').innerHTML ==
355 "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
359 "Filter 'Win' - sorting column 1 reverse",
360 function () { $('#example thead th:eq(1)').click(); },
361 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Seamonkey 1.1"; }
365 "Filter 'Win XP' - maintaing reverse sorting col 1",
366 function () { $('#example_filter input').val("Win XP").keyup(); },
367 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; }
371 "Filter 'Win XP' - sorting col 3",
372 function () { $('#example thead th:eq(3)').click(); },
373 function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "4"; }
377 "Filter 'Win XP' - sorting col 3 - reversed",
378 function () { $('#example thead th:eq(3)').click(); },
379 function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; }
383 "Filter 'Win' - sorting col 3 - reversed info",
385 function () { return document.getElementById('example_info').innerHTML ==
386 "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; }
390 "Filter 'nothinghere'",
391 function () { $('#example_filter input').val("nothinghere").keyup(); },
392 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() ==
393 "No matching records found"; }
397 "Filter 'nothinghere' - info",
399 function () { return document.getElementById('example_info').innerHTML ==
400 "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
404 "Filter back to blank and 1st column sorting",
406 $('#example_filter input').val("").keyup();
407 $('#example thead th:eq(0)').click();
409 function () { return document.getElementById('example_info').innerHTML ==
410 "Showing 1 to 10 of 57 entries"; }
414 "Prefixing a filter entry",
416 $('#example_filter input').val("Win").keyup();
417 $('#example_filter input').val("GeckoWin").keyup();
419 function () { return document.getElementById('example_info').innerHTML ==
420 "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
424 "Prefixing a filter entry with space",
426 $('#example_filter input').val("Gecko Win").keyup();
428 function () { return document.getElementById('example_info').innerHTML ==
429 "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; }