Blame view

bower_components/paper-slider/test/basic.html 5.63 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <!doctype html>
  <!--
  @license
  Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
  This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  Code distributed by Google as part of the polymer project is also
  subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  -->
  <html>
  <head>
    <meta charset="UTF-8">
    <title>paper-slider test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <script src="../../web-component-tester/browser.js"></script>
c5169e0e   Renato De Donato   a new hope
19
    <script src="../../test-fixture/test-fixture-mocha.js"></script>
73bcce88   luigser   COMPONENTS
20
21
22
    <script src="../../iron-test-helpers/mock-interactions.js"></script>
  
    <link rel="import" href="../paper-slider.html">
c5169e0e   Renato De Donato   a new hope
23
    <link rel="import" href="../../test-fixture/test-fixture.html">
73bcce88   luigser   COMPONENTS
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  </head>
  <body>
  
  
    <test-fixture id="trivialProgress">
      <template>
        <paper-slider></paper-slider>
      </template>
    </test-fixture>
  
    <script>
      suite('<paper-slider>', function() {
        var slider;
  
        setup(function() {
          slider = fixture('trivialProgress');
        });
  
        test('check default', function() {
          assert.equal(slider.min, 0);
          assert.equal(slider.max, 100);
          assert.equal(slider.value, 0);
        });
  
        test('set value', function(done) {
          slider.value = 50;
          flush(function() {
            assert.equal(slider.value, 50);
            // test clamp value
            slider.value = 60.1;
            flush(function() {
              assert.equal(slider.value, 60);
              done();
            });
          });
        });
  
        test('set max', function(done) {
          slider.max = 10;
          slider.value = 11;
          flush(function() {
            assert.equal(slider.value, slider.max);
            done();
          });
        });
  
        test('ratio', function(done) {
          slider.max = 10;
          slider.value = 5;
          flush(function() {
            assert.equal(slider.ratio, 0.5);
            done();
          });
        });
  
        test('snaps', function(done) {
          slider.snaps = true;
          slider.step = 10;
          slider.max = 100;
          slider.value = 25;
          flush(function() {
            assert.equal(slider.value, 30);
  
            slider.value = 51.1;
  
            flush(function() {
              assert.equal(slider.value, 50);
              slider.snaps = false;
              slider.step = 1;
              done();
            });
          });
        });
  
        test('secondary progress', function(done) {
          slider.max = 10;
          slider.secondaryProgress = 50;
          flush(function() {
            assert.equal(slider.secondaryProgress, slider.max);
            done();
          });
        });
  
        test('increment', function(done) {
          slider.min = 0;
          slider.max = 10;
          slider.step = 2;
          slider.value = 0;
          slider.increment();
  
          flush(function() {
            assert.equal(slider.value, slider.step);
              slider.step = 1;
              done();
          });
        });
  
        test('decrement', function(done) {
          slider.min = 0;
          slider.max = 10;
          slider.step = 2;
          slider.value = 8;
          slider.decrement();
  
          flush(function() {
            assert.equal(slider.value, 6);
              slider.step = 1;
              done();
          });
        });
  
        test('editable', function(done) {
          slider.min = 0;
          slider.max = 10;
          slider.step = 1;
          slider.editable = true;
  
          flush(function() {
            slider.value = 2;
            assert.equal(slider.$$('#input').value, slider.value);
            done();
          });
        });
  
        test('decimal values', function(done) {
          slider.min = 0;
          slider.max = 1;
          slider.value = slider.min;
          slider.step = 0.1;
  
          slider.increment();
  
          flush(function() {
            assert.equal(slider.value, slider.step);
            assert.equal(slider.$.sliderBar.value, slider.step);
            done();
          });
        });
  
        test('snap to the correct value on tapping', function(done) {
          var cursor = MockInteractions.topLeftOfNode(slider.$.sliderBar);
          cursor.x += slider.$.sliderBar.getBoundingClientRect().width * 0.9;
  
          slider.min = 0;
          slider.max = 2;
          slider.step = 1;
          slider.value = 0;
  
          MockInteractions.down(slider.$.sliderBar, cursor);
  
          flush(function() {
            assert.equal(slider.value, slider.max);
              slider.step = 1;
              done();
          });
        });
  
        test('value should notify', function(done) {
          var targetValue = 10;
  
c5169e0e   Renato De Donato   a new hope
184
185
186
187
188
          slider.addEventListener('value-changed', function(e) {
            assert.equal(e.detail.value, targetValue);
            done();
          });
          
73bcce88   luigser   COMPONENTS
189
190
191
          slider.min = 0;
          slider.max = 100;
          slider.value = targetValue;
73bcce88   luigser   COMPONENTS
192
193
194
195
196
197
198
199
200
201
        });
  
        test('immediateValue should notify', function(done) {
          var targetValue = 50;
  
          slider.addEventListener('immediate-value-changed', function(e) {
            assert.equal(e.detail.value, targetValue);
            assert.equal(slider.immediateValue, targetValue);
            done();
          });
c5169e0e   Renato De Donato   a new hope
202
          
73bcce88   luigser   COMPONENTS
203
204
205
206
207
208
209
210
          var cursor = MockInteractions.topLeftOfNode(slider.$.sliderBar);
          cursor.x += slider.$.sliderBar.getBoundingClientRect().width * targetValue/100;
  
          slider.min = 0;
          slider.max = 100;
          MockInteractions.down(slider.$.sliderBar, cursor);
        });
  
73bcce88   luigser   COMPONENTS
211
212
213
214
215
216
      });
  
    </script>
  
  </body>
  </html>