~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/datatable/tests/datatable-column-widths-tests.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('datatable-column-widths-tests', function(Y) {
2
 
 
3
 
var suite = new Y.Test.Suite("datatable-column-widths");
4
 
 
5
 
suite.add(new Y.Test.Case({
6
 
    name: "lifecycle and instantiation",
7
 
 
8
 
    "Y.DataTable should be augmented": function () {
9
 
        Y.Assert.isTrue(
10
 
            new Y.DataTable().hasImpl(Y.DataTable.ColumnWidths));
11
 
    },
12
 
 
13
 
    "Y.DataTable.Base should not be augmented": function () {
14
 
        Y.Assert.isFalse(
15
 
            new Y.DataTable.Base().hasImpl(Y.DataTable.ColumnWidths));
16
 
    },
17
 
 
18
 
    "Y.DataTable constructor should not error": function () {
19
 
        var table = new Y.DataTable({
20
 
            columns: ['a'],
21
 
            data: [{a:1}]
22
 
        });
23
 
 
24
 
        Y.Assert.isInstanceOf(Y.DataTable, table);
25
 
        Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
26
 
 
27
 
        table = new Y.DataTable({
28
 
            columns: [{ key: 'a', width: '100px' }],
29
 
            data: [{a:1}]
30
 
        });
31
 
 
32
 
        Y.Assert.isInstanceOf(Y.DataTable, table);
33
 
        Y.Assert.isTrue(table.hasImpl(Y.DataTable.ColumnWidths));
34
 
    }
35
 
}));
36
 
 
37
 
suite.add(new Y.Test.Case({
38
 
    name: "render",
39
 
 
40
 
    setUp: function () {
41
 
        this.plain = new Y.DataTable({
42
 
            columns: ['a', 'b', 'c'],
43
 
            data: [{ a: 'a', b: 'b', c: 'c' }]
44
 
        });
45
 
 
46
 
        this.withWidths = new Y.DataTable({
47
 
            columns: [
48
 
                { key: 'a', width: '100px' },
49
 
                { key: 'b' },
50
 
                { key: 'c', width: 200 }
51
 
            ],
52
 
            data: [{ a: 'a', b: 'b', c: 'c' }]
53
 
        });
54
 
    },
55
 
 
56
 
    tearDown: function () {
57
 
        this.plain.destroy();
58
 
        this.withWidths.destroy();
59
 
    },
60
 
 
61
 
    "colgroup should be added for all DataTables": function () {
62
 
       this.plain.render();
63
 
 
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());
67
 
 
68
 
        this.withWidths.render();
69
 
 
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());
73
 
    },
74
 
 
75
 
    "col width should be set from configuration": function () {
76
 
        var cols, cssText, width;
77
 
 
78
 
        this.withWidths.render();
79
 
 
80
 
        cols = this.withWidths._colgroupNode.all('col');
81
 
 
82
 
        cssText = cols.item(0)._node.style.cssText;
83
 
        width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
84
 
 
85
 
        // isString is sufficient to test that the regex matched numbers
86
 
        Y.Assert.isString(width);
87
 
 
88
 
        Y.Assert.isFalse(/width/i.test(cols.item(1)._node.style.cssText));
89
 
 
90
 
        cssText = cols.item(2)._node.style.cssText;
91
 
        width = (cssText.match(/\bwidth:\s*(\d+)px/i) || [])[1];
92
 
 
93
 
        // isString is sufficient to test that the regex matched numbers
94
 
        Y.Assert.isString(width);
95
 
    },
96
 
 
97
 
    "column changes should propagate to the <col>s": function () {
98
 
        var cols, width;
99
 
 
100
 
        this.withWidths.render();
101
 
 
102
 
        cols = this.withWidths._colgroupNode.all('col');
103
 
        width = cols.item(0).getStyle('width');
104
 
 
105
 
        this.withWidths.set('columns', [
106
 
            { key: 'a', width: '200px' },
107
 
            { key: 'b' }
108
 
        ]);
109
 
 
110
 
        cols = this.withWidths._colgroupNode.all('col');
111
 
 
112
 
        Y.Assert.areSame(2, cols.size());
113
 
        Y.Assert.areNotEqual(width, cols.item(0).getStyle('width'));
114
 
    }
115
 
 
116
 
}));
117
 
 
118
 
Y.Test.Runner.add(suite);
119
 
suite.add(new Y.Test.Case({
120
 
    name: "setColumnWidth",
121
 
 
122
 
    "test setColumnWidth": function () {
123
 
        var table = new Y.DataTable({
124
 
            columns: ['a', { key: 'b', width: '100px' }],
125
 
            data: [{ a: 'a', b: 'b' }]
126
 
        });
127
 
 
128
 
        Y.Assert.isUndefined(table.get('columns.a.width'));
129
 
        Y.Assert.areSame('100px', table.get('columns.b.width'));
130
 
 
131
 
        table.setColumnWidth('a', '200px');
132
 
        table.setColumnWidth('b', 300);
133
 
 
134
 
        Y.Assert.areSame('200px', table.get('columns.a.width'));
135
 
        Y.Assert.areSame('300px', table.get('columns.b.width'));
136
 
    },
137
 
 
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' }]
142
 
        });
143
 
 
144
 
        Y.Assert.areSame(table, table.setColumnWidth('a', '100px'));
145
 
    }
146
 
 
147
 
}));
148
 
 
149
 
Y.Test.Runner.add(suite);
150
 
 
151
 
 
152
 
}, '@VERSION@' ,{requires:['datatable-column-widths', 'test']});