1
YUI.add('datatable-column-widths-tests', function(Y) {
3
var suite = new Y.Test.Suite("datatable-column-widths");
5
suite.add(new Y.Test.Case({
6
name: "lifecycle and instantiation",
8
"Y.DataTable should be augmented": function () {
10
new Y.DataTable().hasImpl(Y.DataTable.ColumnWidths));
13
"Y.DataTable.Base should not be augmented": function () {
15
new Y.DataTable.Base().hasImpl(Y.DataTable.ColumnWidths));
18
"Y.DataTable constructor should not error": function () {
19
var table = new Y.DataTable({
24
Y.Assert.isInstanceOf(Y.DataTable, table);
25
Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
27
table = new Y.DataTable({
28
columns: [{ key: 'a', width: '100px' }],
32
Y.Assert.isInstanceOf(Y.DataTable, table);
33
Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
37
suite.add(new Y.Test.Case({
41
this.plain = new Y.DataTable({
42
columns: ['a', 'b', 'c'],
43
data: [{ a: 'a', b: 'b', c: 'c' }]
46
this.withWidths = new Y.DataTable({
48
{ key: 'a', width: '100px' },
50
{ key: 'c', width: 200 }
52
data: [{ a: 'a', b: 'b', c: 'c' }]
56
tearDown: function () {
58
this.withWidths.destroy();
61
"colgroup should be added for all DataTables": function () {
64
Y.Assert.areSame(1, this.plain._tableNode.all('colgroup').size());
65
Y.Assert.isInstanceOf(Y.Node, this.plain._colgroupNode);
66
Y.Assert.areSame(3, this.plain._colgroupNode.all('col').size());
68
this.withWidths.render();
70
Y.Assert.areSame(1, this.withWidths._tableNode.all('colgroup').size());
71
Y.Assert.isInstanceOf(Y.Node, this.withWidths._colgroupNode);
72
Y.Assert.areSame(3, this.withWidths._colgroupNode.all('col').size());
75
"col width should be set from configuration": function () {
76
var cols, cssText, width;
78
this.withWidths.render();
80
cols = this.withWidths._colgroupNode.all('col');
82
cssText = cols.item(0)._node.style.cssText;
83
width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
85
// isString is sufficient to test that the regex matched numbers
86
Y.Assert.isString(width);
88
Y.Assert.isFalse(/width/i.test(cols.item(1)._node.style.cssText));
90
cssText = cols.item(2)._node.style.cssText;
91
width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
93
// isString is sufficient to test that the regex matched numbers
94
Y.Assert.isString(width);
97
"column changes should propagate to the <col>s": function () {
100
this.withWidths.render();
102
cols = this.withWidths._colgroupNode.all('col');
103
width = cols.item(0).getStyle('width');
105
this.withWidths.set('columns', [
106
{ key: 'a', width: '200px' },
110
cols = this.withWidths._colgroupNode.all('col');
112
Y.Assert.areSame(2, cols.size());
113
Y.Assert.areNotEqual(width, cols.item(0).getStyle('width'));
118
Y.Test.Runner.add(suite);
119
suite.add(new Y.Test.Case({
120
name: "setColumnWidth",
122
"test setColumnWidth": function () {
123
var table = new Y.DataTable({
124
columns: ['a', { key: 'b', width: '100px' }],
125
data: [{ a: 'a', b: 'b' }]
128
Y.Assert.isUndefined(table.get('columns.a.width'));
129
Y.Assert.areSame('100px', table.get('columns.b.width'));
131
table.setColumnWidth('a', '200px');
132
table.setColumnWidth('b', 300);
134
Y.Assert.areSame('200px', table.get('columns.a.width'));
135
Y.Assert.areSame('300px', table.get('columns.b.width'));
138
"setColumnWidth should be chainable": function () {
139
var table = new Y.DataTable({
140
columns: ['a', { key: 'b', width: '100px' }],
141
data: [{ a: 'a', b: 'b' }]
144
Y.Assert.areSame(table, table.setColumnWidth('a', '100px'));
149
Y.Test.Runner.add(suite);
152
}, '@VERSION@' ,{requires:['datatable-column-widths', 'test']});