1
var suite = new Y.Test.Suite("datatable-column-widths");
3
suite.add(new Y.Test.Case({
4
name: "lifecycle and instantiation",
6
"Y.DataTable should be augmented": function () {
8
new Y.DataTable().hasImpl(Y.DataTable.ColumnWidths));
11
"Y.DataTable.Base should not be augmented": function () {
13
new Y.DataTable.Base().hasImpl(Y.DataTable.ColumnWidths));
16
"Y.DataTable constructor should not error": function () {
17
var table = new Y.DataTable({
22
Y.Assert.isInstanceOf(Y.DataTable, table);
23
Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
25
table = new Y.DataTable({
26
columns: [{ key: 'a', width: '100px' }],
30
Y.Assert.isInstanceOf(Y.DataTable, table);
31
Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
35
suite.add(new Y.Test.Case({
39
this.plain = new Y.DataTable({
40
columns: ['a', 'b', 'c'],
41
data: [{ a: 'a', b: 'b', c: 'c' }]
44
this.withWidths = new Y.DataTable({
46
{ key: 'a', width: '100px' },
48
{ key: 'c', width: 200 }
50
data: [{ a: 'a', b: 'b', c: 'c' }]
54
tearDown: function () {
56
this.withWidths.destroy();
59
"colgroup should be added for all DataTables": function () {
62
Y.Assert.areSame(1, this.plain._tableNode.all('colgroup').size());
63
Y.Assert.isInstanceOf(Y.Node, this.plain._colgroupNode);
64
Y.Assert.areSame(3, this.plain._colgroupNode.all('col').size());
66
this.withWidths.render();
68
Y.Assert.areSame(1, this.withWidths._tableNode.all('colgroup').size());
69
Y.Assert.isInstanceOf(Y.Node, this.withWidths._colgroupNode);
70
Y.Assert.areSame(3, this.withWidths._colgroupNode.all('col').size());
73
"col width should be set from configuration": function () {
74
var cols, cssText, width;
76
this.withWidths.render();
78
cols = this.withWidths._colgroupNode.all('col');
80
cssText = cols.item(0)._node.style.cssText;
81
width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
83
// isString is sufficient to test that the regex matched numbers
84
Y.Assert.isString(width);
86
Y.Assert.isFalse(/width/i.test(cols.item(1)._node.style.cssText));
88
cssText = cols.item(2)._node.style.cssText;
89
width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
91
// isString is sufficient to test that the regex matched numbers
92
Y.Assert.isString(width);
95
"column changes should propagate to the <col>s": function () {
98
this.withWidths.render();
100
cols = this.withWidths._colgroupNode.all('col');
101
width = cols.item(0).getStyle('width');
103
this.withWidths.set('columns', [
104
{ key: 'a', width: '200px' },
108
cols = this.withWidths._colgroupNode.all('col');
110
Y.Assert.areSame(2, cols.size());
111
Y.Assert.areNotEqual(width, cols.item(0).getStyle('width'));
116
Y.Test.Runner.add(suite);
117
suite.add(new Y.Test.Case({
118
name: "setColumnWidth",
120
"test setColumnWidth": function () {
121
var table = new Y.DataTable({
122
columns: ['a', { key: 'b', width: '100px' }],
123
data: [{ a: 'a', b: 'b' }]
126
Y.Assert.isUndefined(table.get('columns.a.width'));
127
Y.Assert.areSame('100px', table.get('columns.b.width'));
129
table.setColumnWidth('a', '200px');
130
table.setColumnWidth('b', 300);
132
Y.Assert.areSame('200px', table.get('columns.a.width'));
133
Y.Assert.areSame('300px', table.get('columns.b.width'));
136
"setColumnWidth should be chainable": function () {
137
var table = new Y.DataTable({
138
columns: ['a', { key: 'b', width: '100px' }],
139
data: [{ a: 'a', b: 'b' }]
142
Y.Assert.areSame(table, table.setColumnWidth('a', '100px'));
147
Y.Test.Runner.add(suite);