• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<!--
3@license
4Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8Code distributed by Google as part of the polymer project is also
9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10-->
11<html>
12<head>
13  <meta charset="UTF-8">
14  <title>iron-range-behavior</title>
15  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
16
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
21  <link rel="import" href="x-progressbar.html">
22  <link rel="import" href="../../test-fixture/test-fixture.html">
23</head>
24<body>
25
26  <test-fixture id="trivialRange">
27    <template>
28      <x-progressbar></x-progressbar>
29    </template>
30  </test-fixture>
31
32  <script>
33    suite('<x-progressbar>', function() {
34      var range;
35
36      setup(function() {
37        range = fixture('trivialRange');
38      });
39
40      test('check default', function() {
41        assert.equal(range.min, 0);
42        assert.equal(range.max, 100);
43        assert.equal(range.value, 0);
44      });
45
46      test('set value', function(done) {
47        range.value = 50;
48        flush(function() {
49          assert.equal(range.value, 50);
50          // test clamp value
51          range.value = 60.1;
52          flush(function() {
53            assert.equal(range.value, 60);
54            done();
55          });
56        });
57      });
58
59      test('set max', function(done) {
60        range.max = 10;
61        range.value = 11;
62        flush(function() {
63          assert.equal(range.value, range.max);
64          done();
65        });
66      });
67
68      test('test ratio', function(done) {
69        range.max = 10;
70        range.value = 5;
71        flush(function() {
72          assert.equal(range.ratio, 50);
73          done();
74        });
75      });
76
77      test('set min', function(done) {
78        range.min = 10
79        range.max = 50;
80        range.value = 30;
81        flush(function() {
82          assert.equal(range.ratio, 50);
83          range.value = 0;
84          flush(function() {
85            assert.equal(range.value, range.min);
86            done();
87          });
88        });
89      });
90
91      test('set step', function(done) {
92        range.min = 0;
93        range.max = 10;
94        range.value = 5.1;
95        flush(function() {
96          assert.equal(range.value, 5);
97          range.step = 0.1;
98          range.value = 5.1;
99          flush(function() {
100            assert.equal(range.value, 5.1);
101            done();
102          });
103        });
104      });
105
106      test('set large step', function(done) {
107        // PolymerElements/paper-slider#135
108        range.min = 0;
109        range.max = 2625;
110        range.step = 875;
111        range.value = 875;
112        flush(function() {
113          assert.equal(range.value, 875);
114          done();
115        });
116      });
117
118      test('set step with min', function(done) {
119        range.min = -0.9;
120        range.max = 1.1;
121        range.step = 0.5;
122        range.value = -0.5;
123        flush(function() {
124          assert.equal(range.value, -0.4);
125          range.value = 0.7;
126          flush(function() {
127            assert.equal(range.value, 0.6);
128            done();
129          });
130        });
131      });
132
133      test('odd values', function(done) {
134        range.min = 1;
135        range.max = 7;
136        range.step = 2;
137        range.value = 3;
138
139        flush(function() {
140          assert.equal(range.value, 3);
141
142          range.value += range.step;
143          assert.equal(range.value, 5);
144
145          range.value += range.step;
146          assert.equal(range.value, 7);
147          done();
148        });
149      });
150
151      test('negative values should round up', function(done) {
152        range.min = -10;
153        range.max = 10;
154        range.step = 0.1;
155        range.value = -8.4252;
156
157        flush(function() {
158          assert.equal(range.value, -8.4);
159          done();
160        });
161      });
162
163      test('positive values should round up', function(done) {
164        range.min = 10;
165        range.max = 100;
166        range.step = 0.25;
167        range.value = 19.34567;
168
169        flush(function() {
170          assert.equal(range.value, 19.25);
171          done();
172        });
173      });
174
175    });
176
177  </script>
178
179</body>
180</html>
181