aboutsummaryrefslogtreecommitdiffstats
path: root/vaadin-grid/test/grid-scrolling-rows.html
diff options
context:
space:
mode:
Diffstat (limited to 'vaadin-grid/test/grid-scrolling-rows.html')
-rw-r--r--vaadin-grid/test/grid-scrolling-rows.html114
1 files changed, 114 insertions, 0 deletions
diff --git a/vaadin-grid/test/grid-scrolling-rows.html b/vaadin-grid/test/grid-scrolling-rows.html
new file mode 100644
index 0000000..a0ff781
--- /dev/null
+++ b/vaadin-grid/test/grid-scrolling-rows.html
@@ -0,0 +1,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>