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-swipeable-container 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="../../iron-test-helpers/mock-interactions.js"></script>
21
<link rel="import" href="../iron-swipeable-container.html">
22
<link rel="import" href="test-element.html">
29
background-color: blue;
34
<test-fixture id="basic">
36
<iron-swipeable-container>
37
<div id="native">Hello</div>
38
<test-element id="custom"></test-element>
39
</iron-swipeable-container>
43
<test-fixture id="child-no-swipe">
45
<iron-swipeable-container>
46
<div id="native" class="disable-swipe">Hello</div>
47
<test-element id="custom" class="disable-swipe"></test-element>
48
</iron-swipeable-container>
53
<test-fixture id="no-swipe">
55
<iron-swipeable-container disabled>
56
<div id="native">Hello</div>
57
<test-element id="custom"></test-element>
58
</iron-swipeable-container>
64
suite('native elements', function() {
65
test('dragging less than halfway does not swipe', function(done) {
66
var container = fixture('basic');
67
var element = container.querySelector('#native');
69
Polymer.Base.async(function() {
70
var swipeEventHandler = sinon.spy();
71
container.addEventListener('iron-swipe', swipeEventHandler);
73
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
74
MockInteractions.track(element, 10, 0);
76
Polymer.Base.async(function(){
77
expect(swipeEventHandler.callCount).to.be.equal(0);
78
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
84
test('dragging more than halfway swipes it', function(done) {
85
var container = fixture('basic');
86
var element = container.querySelector('#native');
88
Polymer.Base.async(function() {
89
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
91
container.addEventListener('iron-swipe', function(event) {
92
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(1);
96
MockInteractions.track(element, 60, 0);
100
test('an element with disable-swipe cannot be swiped', function(done) {
101
var container = fixture('child-no-swipe');
102
var element = container.querySelector('#native');
104
Polymer.Base.async(function() {
105
var swipeEventHandler = sinon.spy();
106
container.addEventListener('iron-swipe', swipeEventHandler);
108
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
109
MockInteractions.track(element, 60, 0); // this amount would normally swipe.
111
Polymer.Base.async(function(){
112
expect(swipeEventHandler.callCount).to.be.equal(0);
113
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
120
suite('custom elements', function() {
121
test('dragging less than halfway does not swipe', function(done) {
122
var container = fixture('basic');
123
var element = container.querySelector('#custom');
125
var swipeEventHandler = sinon.spy();
126
container.addEventListener('iron-swipe', swipeEventHandler);
128
Polymer.Base.async(function() {
129
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
130
MockInteractions.track(element, 10, 0);
132
Polymer.Base.async(function(){
133
expect(swipeEventHandler.callCount).to.be.equal(0);
134
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
140
test('dragging more than halfway swipes it', function(done) {
141
var container = fixture('basic');
142
var element = container.querySelector('#custom');
144
Polymer.Base.async(function() {
145
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
147
container.addEventListener('iron-swipe', function(event) {
148
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(1);
152
MockInteractions.track(element, 60, 0);
156
test('an element with disable-swipe cannot be swiped', function(done) {
157
var container = fixture('child-no-swipe');
158
var element = container.querySelector('#custom');
160
Polymer.Base.async(function() {
161
var swipeEventHandler = sinon.spy();
162
container.addEventListener('iron-swipe', swipeEventHandler);
164
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
165
MockInteractions.track(element, 60, 0); // this amount would normally swipe.
167
Polymer.Base.async(function(){
168
expect(swipeEventHandler.callCount).to.be.equal(0);
169
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
176
suite('no swipe', function() {
177
test('dragging a native element more than halfway does not swipe', function(done) {
178
var container = fixture('no-swipe');
179
var element = container.querySelector('#native');
181
var swipeEventHandler = sinon.spy();
182
container.addEventListener('iron-swipe', swipeEventHandler);
184
Polymer.Base.async(function() {
185
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
186
MockInteractions.track(element, 60, 0);
188
Polymer.Base.async(function(){
189
expect(swipeEventHandler.callCount).to.be.equal(0);
190
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
196
test('dragging a custom element more than halfway does not swipe', function(done) {
197
var container = fixture('no-swipe');
198
var element = container.querySelector('#custom');
200
var swipeEventHandler = sinon.spy();
201
container.addEventListener('iron-swipe', swipeEventHandler);
203
Polymer.Base.async(function() {
204
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);
205
MockInteractions.track(element, 60, 0);
207
Polymer.Base.async(function(){
208
expect(swipeEventHandler.callCount).to.be.equal(0);
209
expect(Polymer.dom(container).queryDistributedElements('*').length).to.be.equal(2);