1 |
// DATA_TEMPLATE: dom_data |
2 |
oTest.fnStart( "bAutoWidth" ); |
3 |
|
4 |
/* It's actually a little tricky to test this. We can't test absolute numbers because |
5 |
* different browsers and different platforms will render the width of the columns slightly |
6 |
* differently. However, we certainly can test the principle of what should happen (column |
7 |
* width doesn't change over pages) |
8 |
*/ |
9 |
|
10 |
$(document).ready( function () { |
11 |
/* Check the default */ |
12 |
var oTable = $('#example').dataTable(); |
13 |
var oSettings = oTable.fnSettings(); |
14 |
|
15 |
oTest.fnTest( |
16 |
"Auto width is enabled by default", |
17 |
null, |
18 |
function () { return oSettings.oFeatures.bAutoWidth; } |
19 |
); |
20 |
|
21 |
oTest.fnTest( |
22 |
"First column has a width assigned to it", |
23 |
null, |
24 |
function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } |
25 |
); |
26 |
|
27 |
/* |
28 |
This would seem like a better test - but there appear to be difficulties with tables |
29 |
which are bigger (calculated) than there is actually room for. I suspect this is actually |
30 |
a bug in datatables |
31 |
oTest.fnTest( |
32 |
"Check column widths on first page match second page", |
33 |
null, |
34 |
function () { |
35 |
var anThs = $('#example thead th'); |
36 |
var a0 = anThs[0].offsetWidth; |
37 |
var a1 = anThs[1].offsetWidth; |
38 |
var a2 = anThs[2].offsetWidth; |
39 |
var a3 = anThs[3].offsetWidth; |
40 |
var a4 = anThs[4].offsetWidth; |
41 |
$('#example_next').click(); |
42 |
var b0 = anThs[0].offsetWidth; |
43 |
var b1 = anThs[1].offsetWidth; |
44 |
var b2 = anThs[2].offsetWidth; |
45 |
var b3 = anThs[3].offsetWidth; |
46 |
var b4 = anThs[4].offsetWidth; |
47 |
console.log( a0, b0, a1, b1, a2, b2, a3, b3 ); |
48 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
49 |
return true; |
50 |
else |
51 |
return false; |
52 |
} |
53 |
); |
54 |
|
55 |
oTest.fnTest( |
56 |
"Check column widths on second page match thid page", |
57 |
null, |
58 |
function () { |
59 |
var anThs = $('#example thead th'); |
60 |
var a0 = anThs[0].offsetWidth; |
61 |
var a1 = anThs[1].offsetWidth; |
62 |
var a2 = anThs[2].offsetWidth; |
63 |
var a3 = anThs[3].offsetWidth; |
64 |
var a4 = anThs[4].offsetWidth; |
65 |
$('#example_next').click(); |
66 |
var b0 = anThs[0].offsetWidth; |
67 |
var b1 = anThs[1].offsetWidth; |
68 |
var b2 = anThs[2].offsetWidth; |
69 |
var b3 = anThs[3].offsetWidth; |
70 |
var b4 = anThs[4].offsetWidth; |
71 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
72 |
return true; |
73 |
else |
74 |
return false; |
75 |
} |
76 |
); |
77 |
*/ |
78 |
|
79 |
/* Check can disable */ |
80 |
oTest.fnTest( |
81 |
"Auto width can be disabled", |
82 |
function () { |
83 |
oSession.fnRestore(); |
84 |
oTable = $('#example').dataTable( { |
85 |
"bAutoWidth": false |
86 |
} ); |
87 |
oSettings = oTable.fnSettings(); |
88 |
}, |
89 |
function () { return oSettings.oFeatures.bAutoWidth == false; } |
90 |
); |
91 |
|
92 |
oTest.fnTest( |
93 |
"First column does not have a width assigned to it", |
94 |
null, |
95 |
function () { return $('#example thead th:eq(0)').attr('style') == null; } |
96 |
); |
97 |
|
98 |
/* |
99 |
oTest.fnTest( |
100 |
"Check column widths on first page do not match second page", |
101 |
null, |
102 |
function () { |
103 |
var anThs = $('#example thead th'); |
104 |
var a0 = anThs[0].offsetWidth; |
105 |
var a1 = anThs[1].offsetWidth; |
106 |
var a2 = anThs[2].offsetWidth; |
107 |
var a3 = anThs[3].offsetWidth; |
108 |
var a4 = anThs[4].offsetWidth; |
109 |
$('#example_next').click(); |
110 |
var b0 = anThs[0].offsetWidth; |
111 |
var b1 = anThs[1].offsetWidth; |
112 |
var b2 = anThs[2].offsetWidth; |
113 |
var b3 = anThs[3].offsetWidth; |
114 |
var b4 = anThs[4].offsetWidth; |
115 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
116 |
return false; |
117 |
else |
118 |
return true; |
119 |
} |
120 |
); |
121 |
*/ |
122 |
|
123 |
/* Enable makes no difference */ |
124 |
oTest.fnTest( |
125 |
"Auto width enabled override", |
126 |
function () { |
127 |
oSession.fnRestore(); |
128 |
oTable = $('#example').dataTable( { |
129 |
"bAutoWidth": true |
130 |
} ); |
131 |
oSettings = oTable.fnSettings(); |
132 |
}, |
133 |
function () { return oSettings.oFeatures.bAutoWidth; } |
134 |
); |
135 |
|
136 |
|
137 |
oTest.fnComplete(); |
138 |
} ); |