Skip to content

Commit

Permalink
Fix scrolling mode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Aug 24, 2017
1 parent 00de4f3 commit de481ed
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions test/scrolling-mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,14 @@

<script>
describe('scrolling mode', function() {
var scroller;
var fixedContainers;
var grid;

beforeEach(function(done) {
// The before each block times out in CI with Firefox on Polymer 2
this.timeout(30000);

beforeEach(function() {
grid = fixture('default');
grid.dataProvider = infiniteDataProvider;
scroller = grid.$.scroller;
fixedContainers = !!navigator.userAgent.match(/Edge/) && grid.$.scroller.scrollbarWidth === 0;
Polymer.dom.flush();
animationFrameFlush(function() {
done();
});
fixedContainers = !!navigator.userAgent.match(/Edge/) && grid._scrollbarWidth === 0;
flushGrid(grid);
});

function isFixed(element) {
Expand All @@ -60,8 +52,8 @@

it('should have the right amount of scrollbars/scrollers', function() {
var scrollbars = 0;
scrollbars += window.getComputedStyle(scroller.$.table).overflow === 'hidden' ? 0 : 1;
scrollbars += window.getComputedStyle(scroller.$.outerscroller).overflow === 'hidden' ? 0 : 1;
scrollbars += window.getComputedStyle(grid.$.table).overflow === 'hidden' ? 0 : 1;
scrollbars += window.getComputedStyle(grid.$.outerscroller).overflow === 'hidden' ? 0 : 1;
expect(scrollbars).to.equal(getScrollbarWidth() > 0 ? 2 : 1);
});

Expand All @@ -71,27 +63,27 @@
});

it('should have correct scroll bounds on all scroll modes', function() {
expect(scroller.$.outerscroller.scrollHeight).to.be.above(scroller.clientHeight);
expect(scroller.$.table.scrollHeight).to.equal(scroller.$.outerscroller.scrollHeight);
expect(scroller.$.table.scrollWidth).to.equal(scroller.$.outerscroller.scrollWidth);
expect(grid.$.outerscroller.scrollHeight).to.be.above(grid.clientHeight);
expect(grid.$.table.scrollHeight).to.equal(grid.$.outerscroller.scrollHeight);
expect(grid.$.table.scrollWidth).to.equal(grid.$.outerscroller.scrollWidth);
});

it('should not have the table transformed with fixed containers', function() {
// This is to ensure that a fixed body/header/footer are not positioned
// in relation to the table element but it's parent
if (fixedContainers) {
expect(window.getComputedStyle(scroller.$.table).transform).to.equal('none');
expect(window.getComputedStyle(grid.$.table).transform).to.equal('none');
}
});

it('should only cancel wheel events when scrolling is possible - vertical', function() {
expect(wheel(0, -1).defaultPrevented).to.be.false;
expect(wheel(0, 1).defaultPrevented).to.be.true;

scroller._previousMomentum = 0;
grid._previousMomentum = 0;
scrollToEnd(grid);

grid.$.scroller.flushDebouncer('ignore-new-wheel');
grid._debouncerIgnoreNewWheel.flush();

expect(wheel(0, 1).defaultPrevented).to.be.false;
expect(wheel(0, -1).defaultPrevented).to.be.true;
Expand All @@ -101,18 +93,18 @@
expect(wheel(-1, 0).defaultPrevented).to.be.false;
expect(wheel(1, 0).defaultPrevented).to.be.true;

var table = scroller.$.table;
var table = grid.$.table;
table.scrollLeft = table.scrollWidth - table.offsetWidth;
scroller._previousMomentum = 0;
grid.$.scroller.flushDebouncer('ignore-new-wheel');
grid._previousMomentum = 0;
grid._debouncerIgnoreNewWheel.flush();

expect(wheel(1, 0).defaultPrevented).to.be.false;
expect(wheel(-1, 0).defaultPrevented).to.be.true;
});

it('should not prevent wheel events when scrolled to max', function() {
scrollToEnd(grid);
grid.$.scroller.flushDebouncer('ignore-new-wheel');
flushGrid(grid);
expect(wheel(0, 1).defaultPrevented).to.be.false;
expect(wheel(0, 1).defaultPrevented).to.be.false;
});
Expand Down

0 comments on commit de481ed

Please sign in to comment.