This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
forked from dreammmr/paper-fab-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-fab-menu-test.html
252 lines (218 loc) · 7.39 KB
/
paper-fab-menu-test.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<title>paper-fab-menu test</title>
<script src="../../../@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../../@polymer/test-fixture/test-fixture.js"></script>
<script src="../../../mocha/mocha.js"></script>
<script src="../../../chai/chai.js"></script>
<script src="../../../wct-mocha/wct-mocha.js"></script>
<script src="../../../sinon/pkg/sinon.js"></script>
</head>
<body>
<test-fixture id="Simple">
<template>
<paper-fab-menu icon="add">
<paper-fab-menu-item tooltip-position="right" color="red" tooltip="Polymer" icon="polymer"></paper-fab-menu-item>
<paper-fab-menu-item tooltip-position="right" color="#9C27B0" tooltip="Favorites" icon="star"></paper-fab-menu-item>
</paper-fab-menu>
</template>
</test-fixture>
<script type="module">
import '../paper-fab-menu.js';
import '../paper-fab-menu-item.js';
import {tap} from '../../../@polymer/iron-test-helpers/mock-interactions.js';
suite('paper-fab-menu', () => {
test('Children are hidden', (done) => {
const element = fixture('Simple');
flush(() => {
const nodes = element.querySelectorAll('paper-fab-menu-item');
const container = nodes[0].shadowRoot.querySelector('.menu-item');
assert.equal(container.className.indexOf('opened'), -1);
done();
});
});
suite('toggle()', () => {
let element;
setup(() => {
element = fixture('Simple');
});
test('Toggles "opened" state', () => {
element.toggle();
assert.isTrue(element.opened);
});
});
suite('_testOpen()', () => {
let element;
setup(() => {
element = fixture('Simple');
});
test('Clears __closingDebouncer', () => {
element.opened = true; // it's just for coverage
element.__closingDebouncer = 123;
element._testOpen();
assert.isUndefined(element.__closingDebouncer);
});
test('Clears timeout', () => {
element.__closingDebouncer = 123;
const spy = sinon.spy(window, 'clearTimeout');
element._testOpen();
window.clearTimeout.restore();
assert.isTrue(spy.called);
});
test('Opens the menu', () => {
element._testOpen();
assert.isTrue(element.opened);
});
});
suite('_testClose()', () => {
let element;
setup(() => {
element = fixture('Simple');
});
test('Sets __closingDebouncer', (done) => {
element.opened = true;
element._testClose();
assert.typeOf(element.__closingDebouncer, 'number');
setTimeout(() => done(), 20);
});
test('Does nothing when __closingDebouncer is already set', () => {
element.__closingDebouncer = 1;
element._testClose();
assert.equal(element.__closingDebouncer, 1);
});
test('Closes the menu', (done) => {
element.opened = true;
element._testClose();
setTimeout(() => {
assert.isFalse(element.opened);
done();
}, 21);
});
test('Clears __closingDebouncer', (done) => {
element.opened = true;
element._testClose();
setTimeout(() => {
assert.isUndefined(element.__closingDebouncer);
done();
}, 21);
});
});
suite('_detectClick()', () => {
let element;
setup((done) => {
element = fixture('Simple');
flush(() => done());
});
test('Opens the element when the click is on the element', () => {
tap(element);
assert.isTrue(element.opened);
});
test('Closes the element when opened and click is outside the element', () => {
element.opened = true;
tap(document.body);
assert.isFalse(element.opened);
});
test('Does nothing when not opened (outside click)', () => {
tap(document.body);
assert.isFalse(element.opened);
});
test('Does nothing when opened (element click)', () => {
element.opened = true;
tap(element);
assert.isTrue(element.opened);
});
test('Does nothing when clicked on child element', () => {
element.opened = true;
tap(element.querySelector('paper-fab-menu-item'));
assert.isTrue(element.opened);
});
});
suite('_colorChanged()', () => {
let element;
setup((done) => {
element = fixture('Simple');
flush(() => done());
});
test('Updates style of the element', () => {
element._colorChanged('green');
assert.equal(element.$.paperFab.style.backgroundColor, 'green');
});
test('Calls updateStyles()', () => {
const spy = sinon.spy(element, 'updateStyles');
element._colorChanged('green');
assert.isTrue(spy.called);
assert.equal(spy.args[0][0]['--paper-fab-background'], 'green');
});
});
suite('__ensureMenuItem()', () => {
let element;
setup((done) => {
element = fixture('Simple');
flush(() => done());
});
test('Returns undefined when no argument', () => {
const result = element.__ensureMenuItem();
assert.isUndefined(result);
});
test('Returns undefined when no nodeName', () => {
const result = element.__ensureMenuItem({});
assert.isUndefined(result);
});
test('Returns the node', () => {
const node = document.createElement('span');
const result = element.__ensureMenuItem(node);
assert.isTrue(result === node);
});
test('Returns undefined anchor has no children', () => {
const node = document.createElement('a');
const result = element.__ensureMenuItem(node);
assert.isUndefined(result);
});
test('Returns undefined anchor has no paper-fab-menu-item children', () => {
const node = document.createElement('a');
const child = document.createTextNode('test');
node.appendChild(child);
const result = element.__ensureMenuItem(node);
assert.isUndefined(result);
});
test('Returns paper-fab-menu-item from anchor', () => {
const node = document.createElement('a');
const child = document.createElement('paper-fab-menu-item');
node.appendChild(child);
const result = element.__ensureMenuItem(node);
assert.isTrue(result === child);
});
});
suite('_updateDelay()', () => {
let element;
let children;
setup((done) => {
element = fixture('Simple');
flush(() => {
children = element.querySelectorAll('paper-fab-menu-item');
done();
});
});
test('Sets transitionDelay on each child', () => {
element._updateDelay(children);
assert.equal(children[0].transitionDelay, 50);
assert.equal(children[1].transitionDelay, 0);
});
test('Sets _delayTime', () => {
element._updateDelay(children);
assert.equal(element._delayTime, 100);
});
test('Ignores non-menu items', () => {
const nodes = Array.from(children);
nodes.push({});
element._updateDelay(nodes);
assert.equal(element._delayTime, 100);
});
});
});
</script>
</body>
</html>