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 / js_data_mixed_types.js
1 // DATA_TEMPLATE: js_data_mixed_types
2 oTest.fnStart( "Sanity checks for DataTables with data from JS with mixed data types" );
3
4 $(document).ready( function () {
5         var oInit = {
6                 "aaData": gaaData
7         };
8         $('#example').dataTable( oInit );
9         
10         oTest.fnTest( 
11                 "10 rows shown on the first page",
12                 null,
13                 function () { return $('#example tbody tr').length == 10; }
14         );
15         
16         oTest.fnTest( 
17                 "Initial sort occured",
18                 null,
19                 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == "" &&
20                                      $('#example tbody tr:eq(1) td:eq(0)').html() == "Gecko"; }
21         );
22         
23         /* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
24         oTest.fnTest( 
25                 "Sorting (first click) on second column",
26                 function () { $('#example thead th:eq(1)').click(); },
27                 function () { return $('#example tbody td:eq(1)').html() == ""; }
28         );
29         
30         oTest.fnTest( 
31                 "Sorting (second click) on second column",
32                 function () { $('#example thead th:eq(1)').click(); },
33                 function () { return $('#example tbody td:eq(1)').html() == "true"; }
34         );
35         
36         oTest.fnTest( 
37                 "Sorting (third click) on second column",
38                 function () { $('#example thead th:eq(1)').click(); },
39                 function () { return $('#example tbody td:eq(1)').html() == ""; }
40         );
41         
42         oTest.fnTest( 
43                 "Sorting (first click) on numeric column",
44                 function () { $('#example thead th:eq(3)').click(); },
45                 function () { return $('#example tbody td:eq(3)').html() == "-"; }
46         );
47         
48         oTest.fnTest( 
49                 "Sorting (second click) on numeric column",
50                 function () { $('#example thead th:eq(3)').click(); },
51                 function () { return $('#example tbody td:eq(3)').html() == "522.1"; }
52         );
53         
54         oTest.fnTest( 
55                 "Sorting multi-column (first click)",
56                 function () { 
57                         $('#example thead th:eq(0)').click();
58                         oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); },
59                 function () { var b = 
60                         $('#example tbody tr:eq(1) td:eq(0)').html() == "Gecko" && 
61                         $('#example tbody tr:eq(1) td:eq(1)').html() == "Camino 1.0"; return b; }
62         );
63         
64         oTest.fnTest( 
65                 "Sorting multi-column - sorting second column only",
66                 function () { 
67                         $('#example thead th:eq(1)').click(); },
68                 function () { return $('#example tbody td:eq(1)').html() == ""; }
69         );
70         
71         /* Basic paging */
72         oTest.fnTest( 
73                 "Paging to second page",
74                 function () { $('#example_next').click(); },
75                 function () { return $('#example tbody td:eq(1)').html() == "Firefox 2.0"; }
76         );
77         
78         oTest.fnTest( 
79                 "Paging to first page",
80                 function () { $('#example_previous').click(); },
81                 function () { return $('#example tbody td:eq(1)').html() == ""; }
82         );
83         
84         oTest.fnTest( 
85                 "Attempting to page back beyond the first page",
86                 function () { $('#example_previous').click(); },
87                 function () { return $('#example tbody td:eq(1)').html() == ""; }
88         );
89         
90         /* Changing length */
91         oTest.fnTest( 
92                 "Changing table length to 25 records",
93                 function () { $("select[name=example_length]").val('25').change(); },
94                 function () { return $('#example tbody tr').length == 25; }
95         );
96         
97         oTest.fnTest( 
98                 "Changing table length to 50 records",
99                 function () { $("select[name=example_length]").val('50').change(); },
100                 function () { return $('#example tbody tr').length == 50; }
101         );
102         
103         oTest.fnTest( 
104                 "Changing table length to 100 records",
105                 function () { $("select[name=example_length]").val('100').change(); },
106                 function () { return $('#example tbody tr').length == 57; }
107         );
108         
109         oTest.fnTest( 
110                 "Changing table length to 10 records",
111                 function () { $("select[name=example_length]").val('10').change(); },
112                 function () { return $('#example tbody tr').length == 10; }
113         );
114         
115         /*
116          * Information element
117          */
118         oTest.fnTest(
119                 "Information on zero config",
120                 null,
121                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
122         );
123         
124         oTest.fnTest(
125                 "Information on second page",
126                 function () { $('#example_next').click(); },
127                 function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; }
128         );
129         
130         oTest.fnTest(
131                 "Information on third page",
132                 function () { $('#example_next').click(); },
133                 function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; }
134         );
135         
136         oTest.fnTest(
137                 "Information on last page",
138                 function () {
139                         $('#example_next').click();
140                         $('#example_next').click();
141                         $('#example_next').click();
142                 },
143                 function () { return document.getElementById('example_info').innerHTML == "Showing 51 to 57 of 57 entries"; }
144         );
145         
146         oTest.fnTest(
147                 "Information back on first page",
148                 function () {
149                         $('#example_previous').click();
150                         $('#example_previous').click();
151                         $('#example_previous').click();
152                         $('#example_previous').click();
153                         $('#example_previous').click();
154                 },
155                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
156         );
157         
158         oTest.fnTest(
159                 "Information with 25 records",
160                 function () { $("select[name=example_length]").val('25').change(); },
161                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 25 of 57 entries"; }
162         );
163         
164         oTest.fnTest(
165                 "Information with 25 records - second page",
166                 function () { $('#example_next').click(); },
167                 function () { return document.getElementById('example_info').innerHTML == "Showing 26 to 50 of 57 entries"; }
168         );
169         
170         oTest.fnTest(
171                 "Information with 100 records - first page",
172                 function () {
173                         $('#example_previous').click();
174                         $("select[name=example_length]").val('100').change();
175                 },
176                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 57 of 57 entries"; }
177         );
178         
179         oTest.fnTest(
180                 "Information back to 10 records",
181                 function () {
182                         $('#example_previous').click();
183                         $("select[name=example_length]").val('10').change();
184                 },
185                 function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
186         );
187         
188         oTest.fnTest(
189                 "Information with filter 'Win'",
190                 function () { $('#example_filter input').val("Win").keyup(); },
191                 function () { return document.getElementById('example_info').innerHTML == 
192                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
193         );
194         
195         oTest.fnTest(
196                 "Information with filter 'Win' second page",
197                 function () { $('#example_next').click(); },
198                 function () { return document.getElementById('example_info').innerHTML == 
199                         "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
200         );
201         
202         oTest.fnTest(
203                 "Information with filter 'Win' last page",
204                 function () {
205                         $('#example_next').click();
206                         $('#example_next').click();
207                 },
208                 function () { return document.getElementById('example_info').innerHTML == 
209                         "Showing 31 to 31 of 31 entries (filtered from 57 total entries)"; }
210         );
211         
212         oTest.fnTest(
213                 "Information with filter 'Win' back to first page",
214                 function () {
215                         $('#example_previous').click();
216                         $('#example_previous').click();
217                         $('#example_previous').click();
218                 },
219                 function () { return document.getElementById('example_info').innerHTML == 
220                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
221         );
222         
223         oTest.fnTest(
224                 "Information with filter 'Win' second page - second time",
225                 function () {
226                         $('#example_next').click();
227                 },
228                 function () { return document.getElementById('example_info').innerHTML == 
229                         "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
230         );
231         
232         oTest.fnTest(
233                 "Information with filter increased to 'Win 98'",
234                 function () { $('#example_filter input').val("Win 98").keyup(); },
235                 function () { return document.getElementById('example_info').innerHTML == 
236                         "Showing 1 to 9 of 9 entries (filtered from 57 total entries)"; }
237         );
238         
239         oTest.fnTest(
240                 "Information with filter decreased to 'Win'",
241                 function () { $('#example_filter input').val("Win").keyup(); },
242                 function () { return document.getElementById('example_info').innerHTML == 
243                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
244         );
245         
246         oTest.fnTest(
247                 "Information with filter 'Win' second page - third time",
248                 function () {
249                         $('#example_next').click();
250                 },
251                 function () { return document.getElementById('example_info').innerHTML == 
252                         "Showing 11 to 20 of 31 entries (filtered from 57 total entries)"; }
253         );
254         
255         oTest.fnTest(
256                 "Information with filter removed",
257                 function () { $('#example_filter input').val("").keyup(); },
258                 function () { return document.getElementById('example_info').innerHTML == 
259                         "Showing 1 to 10 of 57 entries"; }
260         );
261         
262         
263         /*
264          * Filtering
265          */
266         oTest.fnTest(
267                 "Filter 'W' - rows",
268                 function () { 
269                         /* Reset the table such that the old sorting doesn't mess things up */
270                         oSession.fnRestore();
271                         $('#example').dataTable( oInit );
272                         $('#example_filter input').val("W").keyup(); },
273                 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == ""; }
274         );
275         
276         oTest.fnTest(
277                 "Filter 'W' - info",
278                 null,
279                 function () { return document.getElementById('example_info').innerHTML == 
280                         "Showing 1 to 10 of 42 entries (filtered from 57 total entries)"; }
281         );
282         
283         oTest.fnTest(
284                 "Filter 'Wi'",
285                 function () { $('#example_filter input').val("Wi").keyup(); },
286                 function () { return document.getElementById('example_info').innerHTML == 
287                         "Showing 1 to 10 of 32 entries (filtered from 57 total entries)"; }
288         );
289         
290         oTest.fnTest(
291                 "Filter 'Win'",
292                 function () { $('#example_filter input').val("Win").keyup(); },
293                 function () { return document.getElementById('example_info').innerHTML == 
294                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
295         );
296         
297         oTest.fnTest(
298                 "Filter 'Win' - sorting column 1",
299                 function () { $('#example thead th:eq(1)').click(); },
300                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == ""; }
301         );
302         
303         oTest.fnTest(
304                 "Filter 'Win' - sorting column 1 info",
305                 null,
306                 function () { return document.getElementById('example_info').innerHTML == 
307                         "Showing 1 to 10 of 31 entries (filtered from 57 total entries)"; }
308         );
309         
310         oTest.fnTest(
311                 "Filter 'Win' - sorting column 1 reverse",
312                 function () { $('#example thead th:eq(1)').click(); },
313                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "true"; }
314         );
315         
316         oTest.fnTest(
317                 "Filter 'Win XP' - maintaing reverse sorting col 1",
318                 function () { $('#example_filter input').val("Win XP").keyup(); },
319                 function () { return $('#example tbody tr:eq(0) td:eq(1)').html() == "Internet Explorer 7"; }
320         );
321         
322         oTest.fnTest(
323                 "Filter 'Win XP' - sorting col 3",
324                 function () { $('#example thead th:eq(3)').click(); },
325                 function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "5"; }
326         );
327         
328         oTest.fnTest(
329                 "Filter 'Win XP' - sorting col 3 - reversed",
330                 function () { $('#example thead th:eq(3)').click(); },
331                 function () { return $('#example tbody tr:eq(0) td:eq(3)').html() == "7"; }
332         );
333         
334         oTest.fnTest(
335                 "Filter 'Win' - sorting col 3 - reversed info",
336                 null,
337                 function () { return document.getElementById('example_info').innerHTML == 
338                         "Showing 1 to 5 of 5 entries (filtered from 57 total entries)"; }
339         );
340         
341         oTest.fnTest(
342                 "Filter 'nothinghere'",
343                 function () { $('#example_filter input').val("nothinghere").keyup(); },
344                 function () { return $('#example tbody tr:eq(0) td:eq(0)').html() == 
345                         "No matching records found"; }
346         );
347         
348         oTest.fnTest(
349                 "Filter 'nothinghere' - info",
350                 null,
351                 function () { return document.getElementById('example_info').innerHTML == 
352                         "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
353         );
354         
355         oTest.fnTest(
356                 "Filter back to blank and 1st column sorting",
357                 function () {
358                         $('#example_filter input').val("").keyup();
359                         $('#example thead th:eq(0)').click();
360                 },
361                 function () { return document.getElementById('example_info').innerHTML == 
362                         "Showing 1 to 10 of 57 entries"; }
363         );
364         
365         oTest.fnTest(
366                 "Prefixing a filter entry",
367                 function () {
368                         $('#example_filter input').val("Win").keyup();
369                         $('#example_filter input').val("GeckoWin").keyup();
370                 },
371                 function () { return document.getElementById('example_info').innerHTML == 
372                         "Showing 0 to 0 of 0 entries (filtered from 57 total entries)"; }
373         );
374         
375         oTest.fnTest(
376                 "Prefixing a filter entry with space",
377                 function () {
378                         $('#example_filter input').val("Gecko Win").keyup();
379                 },
380                 function () { return document.getElementById('example_info').innerHTML == 
381                         "Showing 1 to 10 of 17 entries (filtered from 57 total entries)"; }
382         );
383         
384         
385         
386         
387         
388         
389         
390         
391         oTest.fnComplete();
392 } );