4
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
Code distributed by Google as part of the polymer project is also
9
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
13
<meta charset="UTF-8">
14
<title>iron-dropdown-scroll-manager tests</title>
15
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
17
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
18
<script src="../../web-component-tester/browser.js"></script>
19
<script src="../../test-fixture/test-fixture-mocha.js"></script>
20
<script src="../../iron-test-helpers/mock-interactions.js"></script>
22
<link rel="import" href="../iron-dropdown-scroll-manager.html">
23
<link rel="import" href="../../test-fixture/test-fixture.html">
24
<link rel="import" href="x-scrollable-element.html">
28
<test-fixture id="DOMSubtree">
30
<x-scrollable-element id="Parent"></x-scrollable-element>
34
suite('IronDropdownScrollManager', function() {
43
parent = fixture('DOMSubtree');
44
childOne = parent.$$('#ChildOne');
45
childTwo = parent.$$('#ChildTwo');
46
grandChildOne = parent.$$('#GrandchildOne');
47
grandChildTwo = parent.$$('#GrandchildTwo');
48
ancestor = document.body;
51
suite('constraining scroll in the DOM', function() {
53
Polymer.IronDropdownScrollManager.pushScrollLock(childOne);
57
Polymer.IronDropdownScrollManager.removeScrollLock(childOne);
60
test('recognizes sibling as locked', function() {
61
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(childTwo))
65
test('recognizes neice as locked', function() {
66
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(grandChildTwo))
70
test('recognizes parent as locked', function() {
71
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(parent))
75
test('recognizes ancestor as locked', function() {
76
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(ancestor))
80
test('recognizes locking child as unlocked', function() {
81
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(childOne))
85
test('recognizes descendant of locking child as unlocked', function() {
86
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(grandChildOne))
90
test('unlocks locked elements when there are no locking elements', function() {
91
Polymer.IronDropdownScrollManager.removeScrollLock(childOne);
93
expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(parent))
97
test('does not check locked elements when there are no locking elements', function() {
98
sinon.spy(Polymer.IronDropdownScrollManager, 'elementIsScrollLocked');
99
childOne.dispatchEvent(new CustomEvent('wheel', {
103
expect(Polymer.IronDropdownScrollManager
104
.elementIsScrollLocked.callCount).to.be.eql(1);
105
Polymer.IronDropdownScrollManager.removeScrollLock(childOne);
106
childOne.dispatchEvent(new CustomEvent('wheel', {
110
expect(Polymer.IronDropdownScrollManager
111
.elementIsScrollLocked.callCount).to.be.eql(1);
114
suite('various scroll events', function() {
126
events = scrollEvents.map(function(scrollEvent) {
127
return new CustomEvent(scrollEvent, {
134
test('prevents wheel events from locked elements', function() {
135
events.forEach(function(event) {
136
childTwo.dispatchEvent(event);
137
expect(event.defaultPrevented).to.be.eql(true);
141
test('allows wheel events from unlocked elements', function() {
142
events.forEach(function(event) {
143
childOne.dispatchEvent(event);
144
expect(event.defaultPrevented).to.be.eql(false);