paper-submenu.html
7.85 KB
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
<!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>
<title>paper-submenu tests</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../paper-item/paper-item.html">
<link rel="import" href="../paper-menu.html">
<link rel="import" href="../paper-submenu.html">
</head>
<style>
paper-item {
font-weight: normal;
}
</style>
<body>
<test-fixture id="basic">
<template>
<paper-menu>
<paper-submenu>
<paper-item class="menu-trigger">Topic 1</paper-item>
<paper-menu class="menu-content">
<paper-item>item 1.1</paper-item>
<paper-item>item 1.2</paper-item>
<paper-item>item 1.3</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu>
<paper-item class="menu-trigger">Topic 2</paper-item>
<paper-menu class="menu-content">
<paper-item>item 2.1</paper-item>
<paper-item>item 2.2</paper-item>
<paper-item>item 2.3</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu disabled>
<paper-item class="menu-trigger">Topic 3</paper-item>
<paper-menu class="menu-content">
<paper-item>item 3.1</paper-item>
<paper-item>item 3.2</paper-item>
<paper-item>item 3.3</paper-item>
</paper-menu>
</paper-submenu>
</paper-menu>
</template>
</test-fixture>
<script>
suite('<paper-submenu>', function() {
var menu,
sub1, sub2, sub3,
collapse1, collapse2, collapse3,
trigger1, trigger2, trigger3;
setup(function() {
menu = fixture('basic');
sub1 = menu.querySelectorAll('paper-submenu')[0];
sub2 = menu.querySelectorAll('paper-submenu')[1];
sub3 = menu.querySelectorAll('paper-submenu')[2];
collapse1 = Polymer.dom(sub1.root).querySelector('iron-collapse');
collapse2 = Polymer.dom(sub2.root).querySelector('iron-collapse');
collapse3 = Polymer.dom(sub3.root).querySelector('iron-collapse');
trigger1 = sub1.querySelector('.menu-trigger');
trigger2 = sub2.querySelector('.menu-trigger');
trigger3 = sub3.querySelector('.menu-trigger');
});
test('selecting an item expands the submenu', function() {
assert.isFalse(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
MockInteractions.tap(trigger1);
assert.isTrue(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
});
test('selecting a different item closes the previously opened submenu', function() {
assert.isFalse(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
MockInteractions.tap(trigger1);
assert.isTrue(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
MockInteractions.tap(trigger2);
assert.isFalse(collapse1.opened);
assert.isTrue(collapse2.opened);
assert.isFalse(collapse3.opened);
});
test('cannot open a disabled submenu', function() {
assert.isFalse(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
MockInteractions.tap(trigger3);
assert.isFalse(collapse1.opened);
assert.isFalse(collapse2.opened);
assert.isFalse(collapse3.opened);
});
test('selecting an item styles it and the parent', function() {
var boldDiv = document.createElement('div');
boldDiv.style.fontWeight = 'bold';
document.body.appendChild(boldDiv);
var normalDiv = document.createElement('div');
normalDiv.style.fontWeight = 'normal';
document.body.appendChild(normalDiv);
assert.equal(getComputedStyle(trigger1).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger2).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger3).fontWeight, getComputedStyle(normalDiv).fontWeight);
var item1 = sub1.querySelector('.menu-content').querySelector('paper-item');
MockInteractions.tap(trigger1);
// Nothing is initially selected.
assert.equal(getComputedStyle(item1).fontWeight, getComputedStyle(normalDiv).fontWeight);
MockInteractions.tap(item1);
assert.equal(getComputedStyle(item1).fontWeight, getComputedStyle(boldDiv).fontWeight);
assert.equal(getComputedStyle(trigger1).fontWeight, getComputedStyle(boldDiv).fontWeight);
assert.equal(getComputedStyle(trigger2).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger3).fontWeight, getComputedStyle(normalDiv).fontWeight);
});
test('selecting a new item de-styles the previous one', function() {
var boldDiv = document.createElement('div');
boldDiv.style.fontWeight = 'bold';
document.body.appendChild(boldDiv);
var normalDiv = document.createElement('div');
normalDiv.style.fontWeight = 'normal';
document.body.appendChild(normalDiv);
assert.equal(getComputedStyle(trigger1).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger2).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger3).fontWeight, getComputedStyle(normalDiv).fontWeight);
var item1 = sub1.querySelector('.menu-content').querySelector('paper-item');
var item2 = sub2.querySelector('.menu-content').querySelector('paper-item');
MockInteractions.tap(trigger1);
MockInteractions.tap(item1);
MockInteractions.tap(trigger2);
MockInteractions.tap(item2);
// Both children are still selected even though the first one is hidden.
assert.equal(getComputedStyle(item1).fontWeight, getComputedStyle(boldDiv).fontWeight);
assert.equal(getComputedStyle(item2).fontWeight, getComputedStyle(boldDiv).fontWeight);
assert.equal(getComputedStyle(trigger1).fontWeight, getComputedStyle(normalDiv).fontWeight);
assert.equal(getComputedStyle(trigger2).fontWeight, getComputedStyle(boldDiv).fontWeight);
assert.equal(getComputedStyle(trigger3).fontWeight, getComputedStyle(normalDiv).fontWeight);
});
test('focus a submenu should redirect focus to the trigger', function(done) {
MockInteractions.focus(sub1);
flush(function() {
assert.equal(sub1.shadowRoot ? sub1.shadowRoot.activeElement :
document.activeElement, sub1.__trigger);
done();
});
});
});
</script>
</body>
</html>