Add datatables-1.9.4 and jquery-1.10.2 libraries
[proteocache.git] / webapp / resources / datatables-1.9.4 / media / unit_testing / tests_onhold / 3_ajax / fnCreatedRow.js
1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "fnCreatedRow tests" );
3
4 $(document).ready( function () {
5         var tmp = 0;
6         var complete = false;
7
8         $('#example').dataTable( {
9                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
10                 fnCreatedRow: function () {
11                         tmp++;
12                 }
13         } );
14         
15         oTest.fnWaitTest( 
16                 "Row created is called once for each row on init",
17                 null,
18                 function () { return tmp===57; }
19         );
20         
21         oTest.fnTest( 
22                 "Created isn't called back on other draws",
23                 function () { $('#example th:eq(1)').click(); },
24                 function () { return tmp===57; }
25         );
26
27         oTest.fnWaitTest(
28                 "Three arguments for the function",
29                 function () { 
30                         oSession.fnRestore();
31                         tmp = true;
32                         complete = false;
33
34                         $('#example').dataTable( {
35                                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
36                                 fnCreatedRow: function () {
37                                         if ( arguments.length !== 3 ) {
38                                                 tmp = false;
39                                         }
40                                 },
41                                 fnInitComplete: function () {
42                                         complete = true;
43                                 }
44                         } );
45                 },
46                 function () { return (tmp && complete); }
47         );
48
49         oTest.fnWaitTest(
50                 "First argument is a TR element",
51                 function () { 
52                         oSession.fnRestore();
53                         tmp = true;
54                         complete = false;
55
56                         $('#example').dataTable( {
57                                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
58                                 fnCreatedRow: function () {
59                                         if ( arguments[0].nodeName !== "TR" ) {
60                                                 tmp = false;
61                                         }
62                                 },
63                                 fnInitComplete: function () {
64                                         complete = true;
65                                 }
66                         } );
67                 },
68                 function () { return (tmp && complete); }
69         );
70
71         oTest.fnWaitTest(
72                 "Second argument is an array with 5 elements",
73                 function () { 
74                         oSession.fnRestore();
75                         tmp = true;
76                         complete = false;
77
78                         $('#example').dataTable( {
79                                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
80                                 fnCreatedRow: function () {
81                                         if ( arguments[1].length !== 5 ) {
82                                                 tmp = false;
83                                         }
84                                 },
85                                 fnInitComplete: function () {
86                                         complete = true;
87                                 }
88                         } );
89                 },
90                 function () { return (tmp && complete); }
91         );
92
93         oTest.fnWaitTest(
94                 "Third argument is the data source for the row",
95                 function () { 
96                         oSession.fnRestore();
97                         tmp = true;
98                         complete = false;
99
100                         $('#example').dataTable( {
101                                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
102                                 fnCreatedRow: function () {
103                                         if ( arguments[1] !== this.fnSettings().aoData[ arguments[2] ]._aData ) {
104                                                 tmp = false;
105                                         }
106                                 },
107                                 fnInitComplete: function () {
108                                         complete = true;
109                                 }
110                         } );
111                 },
112                 function () { return (tmp && complete); }
113         );
114
115         oTest.fnWaitTest(
116                 "TR element is tied to the correct data",
117                 function () { 
118                         oSession.fnRestore();
119                         tmp = false;
120                         complete = false;
121
122                         $('#example').dataTable( {
123                                 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
124                                 fnCreatedRow: function (tr, data, index) {
125                                         if ( data[1] === "Firefox 1.0" ) {
126                                                 if ( $('td:eq(3)', tr).html() == "1.7" ) {
127                                                         tmp = true;
128                                                 }
129                                         }
130                                 },
131                                 fnInitComplete: function () {
132                                         complete = true;
133                                 }
134                         } );
135                 },
136                 function () { return (tmp && complete); }
137         );
138         
139         
140         
141         oTest.fnComplete();
142 } );