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 / fnCreatedCell.js
1 // DATA_TEMPLATE: js_data
2 oTest.fnStart( "fnCreatedCell tests" );
3
4 $(document).ready( function () {
5         var tmp = 0;
6
7         $('#example').dataTable( {
8                 "aaData": gaaData,
9                 "aoColumnDefs": [ {
10                         fnCreatedCell: function () {
11                                 tmp++;
12                         },
13                         "aTargets": ["_all"]
14                 } ]
15         } );
16         
17         oTest.fnTest( 
18                 "Cell created is called once for each cell on init",
19                 null,
20                 function () { return tmp===285; }
21         );
22         
23         oTest.fnTest( 
24                 "Created isn't called back on other draws",
25                 function () { $('#example th:eq(1)').click(); },
26                 function () { return tmp===285; }
27         );
28
29         oTest.fnTest(
30                 "Four arguments for the function",
31                 function () { 
32                         oSession.fnRestore();
33                         tmp = true;
34
35                         $('#example').dataTable( {
36                                 "aaData": gaaData,
37                                 "aoColumnDefs": [ {
38                                         fnCreatedRow: function () {
39                                                 if ( arguments.length !== 4 ) {
40                                                         tmp = false;
41                                                 }
42                                         },
43                                         "aTargets": ["_all"]
44                                 } ]
45                         } );
46                 },
47                 function () { return tmp; }
48         );
49
50         oTest.fnTest(
51                 "First argument is a TD element",
52                 function () { 
53                         oSession.fnRestore();
54                         tmp = true;
55
56                         $('#example').dataTable( {
57                                 "aaData": gaaData,
58                                 "aoColumnDefs": [ {
59                                         fnCreatedRow: function () {
60                                                 if ( arguments[0].nodeName !== "TD" ) {
61                                                         tmp = false;
62                                                 }
63                                         },
64                                         "aTargets": ["_all"]
65                                 } ]
66                         } );
67                 },
68                 function () { return tmp; }
69         );
70
71         oTest.fnTest(
72                 "Second argument is the HTML value",
73                 function () { 
74                         oSession.fnRestore();
75                         tmp = true;
76
77                         $('#example').dataTable( {
78                                 "aaData": gaaData,
79                                 "aoColumnDefs": [ {
80                                         fnCreatedRow: function () {
81                                                 if ( arguments[1] != $('td').html() ) {
82                                                         tmp = false;
83                                                 }
84                                         },
85                                         "aTargets": ["_all"]
86                                 } ]
87                         } );
88                 },
89                 function () { return tmp; }
90         );
91
92         oTest.fnTest(
93                 "Third argument is the data array",
94                 function () { 
95                         oSession.fnRestore();
96                         tmp = true;
97
98                         $('#example').dataTable( {
99                                 "aaData": gaaData,
100                                 "aoColumnDefs": [ {
101                                         fnCreatedRow: function () {
102                                                 if ( arguments[2].length !== 5 ) {
103                                                         tmp = false;
104                                                 }
105                                         },
106                                         "aTargets": ["_all"]
107                                 } ]
108                         } );
109                 },
110                 function () { return tmp; }
111         );
112
113         oTest.fnTest(
114                 "Fourth argument is the data source for the row",
115                 function () { 
116                         oSession.fnRestore();
117                         tmp = true;
118
119                         $('#example').dataTable( {
120                                 "aaData": gaaData,
121                                 "aoColumnDefs": [ {
122                                         fnCreatedRow: function () {
123                                                 if ( arguments[2] !== this.fnSettings().aoData[ arguments[2] ]._aData ) {
124                                                         tmp = false;
125                                                 }
126                                         },
127                                         "aTargets": ["_all"]
128                                 } ]
129                         } );
130                 },
131                 function () { return tmp; }
132         );
133
134         oTest.fnTest(
135                 "Fifth argument is the the col index",
136                 function () { 
137                         oSession.fnRestore();
138                         tmp = true;
139
140                         $('#example').dataTable( {
141                                 "aaData": gaaData,
142                                 "aoColumnDefs": [ {
143                                         fnCreatedRow: function () {
144                                                 if ( arguments[1] != $('td:eq('+arguments[4]+')', arguments[0].parentNode).html() ) {
145                                                         tmp = false;
146                                                 }
147                                         },
148                                         "aTargets": ["_all"]
149                                 } ]
150                         } );
151                 },
152                 function () { return tmp; }
153         );
154         
155         
156         
157         oTest.fnComplete();
158 } );