Add datatables-1.9.4 and jquery-1.10.2 libraries
[proteocache.git] / webapp / resources / datatables-1.9.4 / media / unit_testing / tests_onhold / 2_js / _zero_config.js
1 // DATA_TEMPLATE: js_data
2 oTest.fnStart( "Sanity checks for DataTables with data from JS" );
3
4 oTest.fnTest( 
5         "jQuery.dataTable function",
6         null,
7         function () { return typeof jQuery().dataTable == "function"; }
8 );
9
10 oTest.fnTest(
11         "jQuery.dataTableSettings storage array",
12         null,
13         function () { return typeof jQuery().dataTableSettings == "object"; }
14 );
15
16 oTest.fnTest(
17         "jQuery.dataTableExt plugin object",
18         null,
19         function () { return typeof jQuery().dataTableExt == "object"; }
20 );
21
22 $(document).ready( function () {
23         var oInit = {
24                 "aaData": gaaData
25         };
26         $('#example').dataTable( oInit );
27         
28         /* Basic checks */
29         oTest.fnTest( 
30                 "Length changing div exists",
31                 null,
32                 function () { return document.getElementById('example_length') != null; }
33         );
34         
35         oTest.fnTest( 
36                 "Filtering div exists",
37                 null,
38                 function () { return document.getElementById('example_filter') != null; }
39         );
40         
41         oTest.fnTest( 
42                 "Information div exists",
43                 null,
44                 function () { return document.getElementById('example_info') != null; }
45         );
46         
47         oTest.fnTest( 
48                 "Pagination div exists",
49                 null,
50                 function () { return document.getElementById('example_paginate') != null; }
51         );
52         
53         oTest.fnTest( 
54                 "Processing div is off by default",
55                 null,
56                 function () { return document.getElementById('example_processing') == null; }
57         );
58         
59         oTest.fnTest( 
60                 "10 rows shown on the first page",
61                 null,
62                 function () { return $('#example tbody tr').length == 10; }
63         );
64         
65         oTest.fnTest( 
66                 "Initial sort occured",
67                 null,
68                 function () { return $('#example tbody td:eq(0)').html() == "Gecko"; }
69         );
70         
71         /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
72         oTest.fnTest( 
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"; }
76         );
77         
78         oTest.fnTest( 
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"; }
82         );
83         
84         oTest.fnTest( 
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"; }
88         );
89         
90         oTest.fnTest( 
91                 "Sorting (first click) on numeric column",
92                 function () { $('#example thead th:eq(3)').click(); },
93                 function () { return $('#example tbody td:eq(3)').html() == "-"; }
94         );
95         
96         oTest.fnTest( 
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"; }
100         );
101         
102         oTest.fnTest( 
103                 "Sorting multi-column (first click)",
104                 function () { 
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; }
110         );
111         
112         oTest.fnTest( 
113                 "Sorting multi-column - sorting second column only",
114                 function () { 
115                         $('#example thead th:eq(1)').click(); },
116                 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
117         );
118         
119         /* Basic paging */
120         oTest.fnTest( 
121                 "Paging to second page",
122                 function () { $('#example_next').click(); },
123                 function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; }
124         );
125         
126         oTest.fnTest( 
127                 "Paging to first page",
128                 function () { $('#example_previous').click(); },
129                 function () { return $('#example tbody td:eq(1)').html() == "All others"; }
130         );
131         
132         oTest.fnTest( 
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"; }
136         );
137         
138         /* Changing length */
139         oTest.fnTest( 
140                 "Changing table length to 25 records",
141                 function () { $("select[name=example_length]").val('25').change(); },
142                 function () { return $('#example tbody tr').length == 25; }
143         );
144         
145         oTest.fnTest( 
146                 "Changing table length to 50 records",
147                 function () { $("select[name=example_length]").val('50').change(); },
148                 function () { return $('#example tbody tr').length == 50; }
149         );
150         
151         oTest.fnTest( 
152                 "Changing table length to 100 records",
153                 function () { $("select[name=example_length]").val('100').change(); },
154                 function () { return $('#example tbody tr').length == 57; }
155         );
156         
157         oTest.fnTest( 
158                 "Changing table length to 10 records",
159                 function () { $("select[name=example_length]").val('10').change(); },
160                 function () { return $('#example tbody tr').length == 10; }
161         );
162         
163         /*
164          * Information element
165          */
166         oTest.fnTest(
167                 "Information on zero config",
168                 null,
169                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
170         );
171         
172         oTest.fnTest(
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"; }
176         );
177         
178         oTest.fnTest(
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"; }
182         );
183         
184         oTest.fnTest(
185                 "Information on last page",
186                 function () {
187                         $('#example_next').click();
188                         $('#example_next').click();
189                         $('#example_next').click();
190                 },
191                 function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; }
192         );
193         
194         oTest.fnTest(
195                 "Information back on first page",
196                 function () {
197                         $('#example_previous').click();
198                         $('#example_previous').click();
199                         $('#example_previous').click();
200                         $('#example_previous').click();
201                         $('#example_previous').click();
202                 },
203                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
204         );
205         
206         oTest.fnTest(
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"; }
210         );
211         
212         oTest.fnTest(
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"; }
216         );
217         
218         oTest.fnTest(
219                 "Information with 100 records - first page",
220                 function () {
221                         $('#example_previous').click();
222                         $("select[name=example_length]").val('100').change();
223                 },
224                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; }
225         );
226         
227         oTest.fnTest(
228                 "Information back to 10 records",
229                 function () {
230                         $('#example_previous').click();
231                         $("select[name=example_length]").val('10').change();
232                 },
233                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
234         );
235         
236         oTest.fnTest(
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)"; }
241         );
242         
243         oTest.fnTest(
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)"; }
248         );
249         
250         oTest.fnTest(
251                 "Information with filter 'Win' last page",
252                 function () {
253                         $('#example_next').click();
254                         $('#example_next').click();
255                 },
256                 function () { return document.getElementById('example_info').innerHTML == 
257                         "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; }
258         );
259         
260         oTest.fnTest(
261                 "Information with filter 'Win' back to first page",
262                 function () {
263                         $('#example_previous').click();
264                         $('#example_previous').click();
265                         $('#example_previous').click();
266                 },
267                 function () { return document.getElementById('example_info').innerHTML == 
268                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
269         );
270         
271         oTest.fnTest(
272                 "Information with filter 'Win' second page - second time",
273                 function () {
274                         $('#example_next').click();
275                 },
276                 function () { return document.getElementById('example_info').innerHTML == 
277                         "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
278         );
279         
280         oTest.fnTest(
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)"; }
285         );
286         
287         oTest.fnTest(
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)"; }
292         );
293         
294         oTest.fnTest(
295                 "Information with filter 'Win' second page - third time",
296                 function () {
297                         $('#example_next').click();
298                 },
299                 function () { return document.getElementById('example_info').innerHTML == 
300                         "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
301         );
302         
303         oTest.fnTest(
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"; }
308         );
309         
310         
311         /*
312          * Filtering
313          */
314         oTest.fnTest(
315                 "Filter 'W' - rows",
316                 function () { 
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"; }
322         );
323         
324         oTest.fnTest(
325                 "Filter 'W' - info",
326                 null,
327                 function () { return document.getElementById('example_info').innerHTML == 
328                         "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; }
329         );
330         
331         oTest.fnTest(
332                 "Filter 'Wi'",
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)"; }
336         );
337         
338         oTest.fnTest(
339                 "Filter 'Win'",
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)"; }
343         );
344         
345         oTest.fnTest(
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)"; }
349         );
350         
351         oTest.fnTest(
352                 "Filter 'Win' - sorting column 1 info",
353                 null,
354                 function () { return document.getElementById('example_info').innerHTML == 
355                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
356         );
357         
358         oTest.fnTest(
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"; }
362         );
363         
364         oTest.fnTest(
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"; }
368         );
369         
370         oTest.fnTest(
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"; }
374         );
375         
376         oTest.fnTest(
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"; }
380         );
381         
382         oTest.fnTest(
383                 "Filter 'Win' - sorting col 3 - reversed info",
384                 null,
385                 function () { return document.getElementById('example_info').innerHTML == 
386                         "Showing 1 to 6 of 6 entries (filtered from 57 total entries)"; }
387         );
388         
389         oTest.fnTest(
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"; }
394         );
395         
396         oTest.fnTest(
397                 "Filter 'nothinghere' - info",
398                 null,
399                 function () { return document.getElementById('example_info').innerHTML == 
400                         "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
401         );
402         
403         oTest.fnTest(
404                 "Filter back to blank and 1st column sorting",
405                 function () {
406                         $('#example_filter input').val("").keyup();
407                         $('#example thead th:eq(0)').click();
408                 },
409                 function () { return document.getElementById('example_info').innerHTML == 
410                         "Showing 1 to 10 of 57 entries"; }
411         );
412         
413         oTest.fnTest(
414                 "Prefixing a filter entry",
415                 function () {
416                         $('#example_filter input').val("Win").keyup();
417                         $('#example_filter input').val("GeckoWin").keyup();
418                 },
419                 function () { return document.getElementById('example_info').innerHTML == 
420                         "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
421         );
422         
423         oTest.fnTest(
424                 "Prefixing a filter entry with space",
425                 function () {
426                         $('#example_filter input').val("Gecko Win").keyup();
427                 },
428                 function () { return document.getElementById('example_info').innerHTML == 
429                         "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; }
430         );
431         
432         
433         
434         
435         
436         
437         
438         
439         oTest.fnComplete();
440 } );