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
|
<!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('scrolling rows', function() {
var infiniteDataSource = function(req) {
var data = [];
for (var i = req.index; i < req.index + req.count; i++) {
data.push(["foo " + i, "bar " + i]);
}
req.success(data, this.size);
};
function firstColumnContents() {
var cells = qaLocal('td');
return _.chain(cells)
.filter(function(n) {
return _.indexOf(cells, n) % 2 == 0;
})
.map(function(n) {
return n.textContent;
})
.reduce(function(result, n) {
return result + ', ' + n;
}).value();
}
before(function() {
infiniteDataSource.size = 100;
grid.data.source = infiniteDataSource;
grid.rows = 5;
return grid;
});
beforeEach(function() {
//reset position to an arbitrary row.
return grid.scrollToRow(24).then(function () {
// calling scrollToRow - scrollToRow - then seems to quite often
// run the callback in 'then' before the latter scrolling has finished.
// This is most likely caused by multiple timers being fired inside the Grid,
// and there's some gap between them - which makes grid.isWorkPending() to return
// 'false' too soon.
// Adding one 'then' in between the scrolling calls
// doesn't seem to remedy the situation. So let's add more.
return grid;
});
});
it('should throw an error when scrolling to an invalid row', function() {
expect(grid.scrollToRow.bind(grid, -1)).to.throw("Row index");
expect(grid.scrollToRow.bind(grid, 100)).to.throw("Row index");
});
it('should scroll using scrollToRow', function() {
return grid.scrollToRow(50)
.then(function() {
expect(firstColumnContents()).to.contain('foo 50');
});
});
describe('scrolling with destination', function() {
it('should scroll to start', function() {
return grid.scrollToRow(50, 'start')
.then(function() {
expect(firstColumnContents()).to.contain('foo 50');
expect(firstColumnContents()).to.contain('foo 54');
});
});
it('should scroll to end', function() {
return grid.scrollToRow(50, 'end')
.then(function() {
expect(firstColumnContents()).to.contain('foo 46');
expect(firstColumnContents()).to.contain('foo 50');
});
});
});
it('should scroll to end', function() {
return grid.scrollToEnd()
.then(function() {
expect(firstColumnContents()).to.contain('foo 99');
});
});
it('should scroll to start', function() {
return grid.scrollToStart()
.then(function() {
expect(firstColumnContents()).to.contain('foo 0');
});
});
});
</script>
</body>
</html>
|