forked from PolymerElements/paper-swatch-picker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic.html
259 lines (217 loc) · 8.47 KB
/
basic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!doctype html>
<!--
@license
Copyright (c) 2016 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-swatch-picker basic tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../../@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../../../wct-browser-legacy/browser.js"></script>
<script src="../../../@polymer/iron-test-helpers/mock-interactions.js" type="module"></script>
<script src="../../../@polymer/iron-test-helpers/test-helpers.js" type="module"></script>
<script type="module" src="../../../@polymer/neon-animation/web-animations.js"></script>
<script type="module" src="../paper-swatch-picker.js"></script>
</head>
<body>
<custom-style>
<style is="custom-style">
paper-swatch-picker.custom {
--paper-swatch-picker-color-size: 10px;
}
</style>
</custom-style>
<test-fixture id="basic">
<template>
<paper-swatch-picker></paper-swatch-picker>
</template>
</test-fixture>
<test-fixture id="preselected">
<template>
<paper-swatch-picker class="preselected" color="#ffcdd2"></paper-swatch-picker>
</template>
</test-fixture>
<test-fixture id="custom">
<template>
<paper-swatch-picker class="custom" column-count="5" color-list='["#ff0000", "#00ff00", "#0000ff", "#000", "#fff"]'></paper-swatch-picker>
</template>
</test-fixture>
<test-fixture id="dynamic">
<template>
<paper-swatch-picker></paper-swatch-picker>
</template>
</test-fixture>
<script type="module">
import '../../../@polymer/neon-animation/web-animations.js';
import '../paper-swatch-picker.js';
import { flush as flush$0 } from '../../../@polymer/polymer/lib/legacy/polymer.dom.js';
import { Base } from '../../../@polymer/polymer/polymer-legacy.js';
suite('basic', function() {
var picker, container;
setup(function() {
picker = fixture('basic');
container = picker.$.container;
});
test('clicking the button opens a rendered menu', function(done) {
flush$0();
// No color is selected.
assert.equal(picker.color, undefined);
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// There are 18 default columns, and each column is 20px wide.
assert.equal(container.style.width, 18 * 20 +'px');
// There are 10 default rows, and each row is 20px wide.
assert.equal(container.style.height, 10 * 20 +'px');
// The colors have been filled in. The first box is #ffebee.
var box = container.querySelector('.color');
assert.equal('#ffebee', picker._rgbToHex(box.style.color));
done();
}, 1);
});
test('clicking a color selects it', function(done) {
flush$0();
// No color is selected.
assert.equal(picker.color, undefined);
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// The colors have been filled in. The first box is #ffebee.
var box = container.querySelector('.color');
MockInteractions.tap(box);
Base.async(function() {
assert.equal('#ffebee', picker.color);
assert.equal('#ffebee', picker._rgbToHex(picker.$.iconButton.style.color));
done();
}, 1);
});
});
});
suite('initial selection', function() {
var picker, container;
setup(function() {
picker = fixture('preselected');
container = picker.$.container;
});
test('the picker can have an initially selected color', function() {
flush$0();
assert.equal(picker.color, '#ffcdd2');
assert.equal('#ffcdd2', picker._rgbToHex(picker.$.iconButton.style.color));
});
test('selecting a different color updates the button color', function(done) {
flush$0();
assert.equal(picker.color, '#ffcdd2');
assert.equal('#ffcdd2', picker._rgbToHex(picker.$.iconButton.style.color));
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// Select a different color. The first box is #ffebee.
var box = container.querySelector('.color');
MockInteractions.tap(box);
Base.async(function() {
assert.equal('#ffebee', picker.color);
assert.equal('#ffebee', picker._rgbToHex(picker.$.iconButton.style.color));
done();
}, 1);
}, 1);
});
});
suite('custom color list', function() {
var picker, container;
setup(function() {
picker = fixture('custom');
container = picker.$.container;
});
test('the picker shows the right colors', function(done) {
flush$0();
assert.equal(picker.colorList.length, 5);
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// There are 5 default columns, and each column is 10px wide.
assert.equal(container.style.width, 5 * 10 +'px');
// There is 1 default row, and each row is 10px wide.
assert.equal(container.style.height, 10 +'px');
// The colors have been filled in correctly
var boxes = container.querySelectorAll('.color');
assert.equal('#ff0000', picker._rgbToHex(boxes[0].style.color));
assert.equal('#00ff00', picker._rgbToHex(boxes[1].style.color));
assert.equal('#0000ff', picker._rgbToHex(boxes[2].style.color));
assert.equal('#000000', picker._rgbToHex(boxes[3].style.color));
assert.equal('#ffffff', picker._rgbToHex(boxes[4].style.color));
done();
}, 1);
});
});
suite('dynamic', function () {
var picker, container;
setup(function () {
picker = fixture('dynamic');
container = picker.$.container;
});
test('changing the number of columns updates the layout', function (done) {
flush$0();
Base.async(function () {
// There are 18 default columns, and each column is 20px wide.
assert.equal(container.style.width, 18 * 20 + 'px');
// There is 10 default rows, and each row is 20px wide.
assert.equal(container.style.height, 10 * 20 + 'px');
// Now change the number of columns from 18 to 9
picker.columnCount = 9;
assert.equal(picker.columnCount, 9);
// Now we have 9 columns, and each column is 20px wide.
assert.equal(container.style.width, 9 * 20 + 'px');
// Now we have 20 rows, and each column is 20px wide.
assert.equal(container.style.height, 20 * 20 + 'px');
done();
}, 1);
});
test('changing the colors updates the colors and the layout', function (done) {
flush$0();
// There are 18 default columns, and each column is 20px wide.
assert.equal(container.style.width, 18 * 20 + 'px');
// There is 10 default rows, and each row is 20px wide.
assert.equal(container.style.height, 10 * 20 + 'px');
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// Select the first color (#ffebee).
var box = container.querySelector('.color');
MockInteractions.tap(box);
Base.async(function() {
// Now change the colors
picker.colorList = [
'#ffcdd2', '#f44336', '#b71c1c',
'#c5cae9', '#3f51b5', '#1a237e',
'#b2dfdb', '#009688', '#004d40',
'#fff9c4', '#ffeb3b', '#f57f17',
'#d7ccc8', '#795548', '#3e2723',
'#f5f5f5', '#9e9e9e', '#212121'
];
flush(function() {
assert.equal(picker.colorList.length, 18);
// Now we have 1 row, and each column is 20px wide.
assert.equal(container.style.height, 20 + 'px');
// Since the old selected color is not in the new list,
// it has been adjusted to the fallback color (first color: #ffcdd2)
assert.equal('#ffcdd2', picker.color);
assert.equal('#ffcdd2', picker._rgbToHex(picker.$.iconButton.style.color));
MockInteractions.tap(picker.$.iconButton);
Base.async(function() {
// The colors have been filled in correctly
var boxes = container.querySelectorAll('.color');
picker.colorList.forEach(function(color, index) {
assert.equal(color, picker._rgbToHex(boxes[index].style.color))
});
done();
}, 1);
});
}, 1);
}, 1);
});
});
</script>
</body>
</html>