1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../../webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="common.js"></script>
<link rel="import" href="../vaadin-grid.html">
</head>
<body>
<div id="gridwrapper"></div>
<script>
describe.feature('static sections', function() {
function removeHeaders() {
for(var i = grid.header.rowCount;i>0;i--) {
grid.header.removeRow();
}
}
function removeFooters() {
for(var i = grid.footer.rowCount;i>0;i--) {
grid.footer.removeRow();
}
}
beforeEach(function() {
removeHeaders();
removeFooters();
grid.header.addRow(0, ['Name', 'Value']);
grid.footer.addRow(0, ['Name', 'Value']);
grid.header.hidden = false;
grid.footer.hidden = false;
return grid;
});
describe('header.defaultRow', function() {
it('should be 0 by default', function() {
expect(grid.header.defaultRow).to.equal(0);
});
it('should fail when set to a nonexisting row', function() {
expect(function() {
grid.header.defaultRow = 1;
}).to.throw('Row with index 1 does not exist');
});
it('should set the defaultRow', function() {
grid.header.addRow();
// sorting indicator moves to the default row, so we'll
// use that to assert that default row has changed.
grid.columns[0].sortable = true;
grid.data.sortOrder = [{column: 0, direction: 'asc'}];
grid.header.defaultRow = 1;
var cells = qaLocal('.v-grid-header .v-grid-cell');
expect(cells[2].classList.toString()).to.contain('sort-asc');
});
it('should have content in sync with column.headerContent', function() {
var column = grid.columns[0];
var headerCell = grid.header.getCell(grid.header.defaultRow, 0);
column.headerContent = "foo";
expect(headerCell.content).to.eql("foo");
headerCell.content = "bar";
expect(column.headerContent).to.eql("bar");
});
});
['header', 'footer'].forEach(function(section) {
describe(section, function() {
it('should be readonly', function() {
var originalValue = grid[section];
grid[section] = undefined;
expect(grid[section]).to.equal(originalValue);
});
describe('getCell', function() {
it('should return correct cell using indeces', function() {
var cell = grid[section].getCell(0,0);
expect(cell.content).to.equal('Name');
});
it('should return correct cell using identifier', function() {
grid.columns[0].name = 'foo';
var cell = grid[section].getCell(0, 'foo');
expect(cell.content).to.equal('Name');
});
it('should return correct cell from appended row', function() {
grid[section].addRow(1, [section + 'foo']);
var cell = grid[section].getCell(1, 0);
expect(cell.content).to.equal(section + 'foo');
});
});
describe('cell', function() {
describe('content', function() {
it('should set content', function() {
var cell = grid[section].getCell(0,0);
cell.content = 'foo';
expect(grid[section].getCell(0,0).content).to.equal('foo');
});
it('should set html content', function() {
var cell = grid[section].getCell(0, 0);
var input = document.createElement('input');
cell.content = input;
expect(qLocal('.v-grid-' + section + ' .v-grid-cell > input')).to.not.be.undefined;
});
});
describe('hidden', function() {
it('should clear innerHTML', function() {
grid[section].hidden = true;
expect(qLocal('.v-grid-' + section).innerHTML).to.be.empty;
});
});
describe('colspan', function() {
it('should hide spanned cells', function() {
var cell = grid[section].getCell(0, 0);
cell.colspan = 2;
return grid.then(function() {
expect(qaLocal(".v-grid-" + section + " .v-grid-cell")[1].style.display).to.equal('none');
});
});
});
});
describe('addRow', function() {
it('should append new row', function() {
grid[section].addRow();
grid[section].getCell(1,0).content = 'foo';
grid[section].getCell(1,1).content = 'bar';
var cells = qaLocal('.v-grid-' + section + ' .v-grid-cell');
expect(cells[0].innerHTML).to.equal('Name');
expect(cells[1].innerHTML).to.equal('Value');
expect(cells[2].innerHTML).to.equal('foo');
expect(cells[3].innerHTML).to.equal('bar');
});
it('should insert new row to correct index', function() {
grid[section].addRow(0);
grid[section].getCell(0,0).content = 'foo';
grid[section].getCell(0,1).content = 'bar';
var cells = qaLocal('.v-grid-' + section + ' .v-grid-cell');
expect(cells[0].innerHTML).to.equal('foo');
expect(cells[1].innerHTML).to.equal('bar');
expect(cells[2].innerHTML).to.equal('Name');
expect(cells[3].innerHTML).to.equal('Value');
});
it('should insert content to a new row', function() {
grid[section].addRow(0, ['foo', 'bar']);
var cells = qaLocal(".v-grid-" + section + " .v-grid-cell");
expect(cells[0].innerHTML).to.equal('foo');
expect(cells[1].innerHTML).to.equal('bar');
});
});
describe('removeRow', function() {
it('should remove first row', function() {
grid[section].removeRow();
expect(qaLocal('.v-grid-' + section + ' .v-grid-cell')).to.be.empty;
});
it('should remove a specific row', function() {
grid[section].addRow(0, ['foo', 'bar']);
grid[section].removeRow(1);
expect(qaLocal('.v-grid-' + section + ' .v-grid-cell')).to.have.length(2);
});
});
describe('setRowClassName', function() {
it('should set the classname of a specific row', function() {
grid[section].addRow();
grid[section].setRowClassName(1, 'second');
var rows = qaLocal(".v-grid-" + section + " .v-grid-row");
expect(rows[1].classList.toString()).to.contain('second');
});
});
});
});
});
</script>
</body>
</html>
|