~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/tests/datatable/tests/src/datatable-column-widths.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

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