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-badge tests</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>
|
73bcce88
luigser
COMPONENTS
|
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
|
<link rel="import" href="../paper-badge.html">
<link rel="import" href="test-button.html">
</head>
<style>
body {
margin: 0;
padding: 0;
}
#target {
width: 100px;
height: 20px;
background-color: red;
}
</style>
<body>
<test-fixture id="basic">
<template>
<div style="position:relative">
<div id="target"></div>
<paper-badge for="target" label="1"></paper-badge>
</div>
</template>
</test-fixture>
<test-fixture id="dynamic">
<template>
<div>
<div id="target"></div>
<paper-badge label="1"></paper-badge>
</div>
</template>
</test-fixture>
|
eb240478
Luigi Serra
public room cards...
|
54
55
56
57
58
59
60
61
62
63
|
<test-fixture id="nested">
<template>
<div>
<div id="target">
<paper-badge label="1"></paper-badge>
</div>
</div>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
64
65
66
67
68
69
|
<test-fixture id="custom">
<template>
<test-button></test-button>
</template>
</test-fixture>
|
a1a3bc73
Luigi Serra
graphs updates
|
70
71
72
73
74
75
76
77
78
|
<test-fixture id="icon-badge">
<template>
<div style="position:relative">
<div id="target"></div>
<paper-badge icon="favorite" label="favorite icon"></paper-badge>
</div>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
79
80
81
82
83
|
<script>
suite('basic', function() {
test('badge is positioned correctly', function(done) {
var f = fixture('basic');
var badge = f.querySelector('paper-badge');
|
a1a3bc73
Luigi Serra
graphs updates
|
84
|
var actualbadge = Polymer.dom(badge.root).querySelector('.badge');
|
73bcce88
luigser
COMPONENTS
|
85
|
|
eb240478
Luigi Serra
public room cards...
|
86
87
|
expect(badge.target.getAttribute('id')).to.be.equal('target');
|
73bcce88
luigser
COMPONENTS
|
88
89
90
|
badge.updatePosition();
Polymer.Base.async(function() {
|
a1a3bc73
Luigi Serra
graphs updates
|
91
92
|
assert.equal(actualbadge.textContent.trim(), "1");
|
73bcce88
luigser
COMPONENTS
|
93
94
95
96
97
|
var divRect = f.querySelector('#target').getBoundingClientRect();
expect(divRect.width).to.be.equal(100);
expect(divRect.height).to.be.equal(20);
var contentRect = badge.getBoundingClientRect();
|
a1a3bc73
Luigi Serra
graphs updates
|
98
99
|
expect(contentRect.width).to.be.equal(20);
expect(contentRect.height).to.be.equal(20);
|
73bcce88
luigser
COMPONENTS
|
100
101
102
|
// The target div is 100 x 20, and the badge is centered on the
// top right corner.
|
a1a3bc73
Luigi Serra
graphs updates
|
103
104
|
expect(contentRect.left).to.be.equal(100 - 10);
expect(contentRect.top).to.be.equal(0 - 10);
|
73bcce88
luigser
COMPONENTS
|
105
106
|
// Also check the math, just in case.
|
a1a3bc73
Luigi Serra
graphs updates
|
107
108
|
expect(contentRect.left).to.be.equal(divRect.width - 10);
expect(contentRect.top).to.be.equal(divRect.top - 10);
|
73bcce88
luigser
COMPONENTS
|
109
110
111
112
113
114
115
116
117
118
|
done();
});
});
test('badge is positioned correctly after being dynamically set', function(done) {
var f = fixture('dynamic');
var badge = f.querySelector('paper-badge');
badge.updatePosition();
|
eb240478
Luigi Serra
public room cards...
|
119
120
|
expect(badge.target.getAttribute('id')).to.not.be.equal('target');
|
73bcce88
luigser
COMPONENTS
|
121
122
123
124
125
|
Polymer.Base.async(function() {
var contentRect = badge.getBoundingClientRect();
expect(contentRect.left).to.not.be.equal(100 - 11);
badge.for = 'target';
|
eb240478
Luigi Serra
public room cards...
|
126
127
|
expect(badge.target.getAttribute('id')).to.be.equal('target');
|
73bcce88
luigser
COMPONENTS
|
128
129
130
131
132
133
134
135
|
badge.updatePosition();
Polymer.Base.async(function() {
var divRect = f.querySelector('#target').getBoundingClientRect();
expect(divRect.width).to.be.equal(100);
expect(divRect.height).to.be.equal(20);
var contentRect = badge.getBoundingClientRect();
|
a1a3bc73
Luigi Serra
graphs updates
|
136
137
|
expect(contentRect.width).to.be.equal(20);
expect(contentRect.height).to.be.equal(20);
|
73bcce88
luigser
COMPONENTS
|
138
139
140
|
// The target div is 100 x 20, and the badge is centered on the
// top right corner.
|
a1a3bc73
Luigi Serra
graphs updates
|
141
142
|
expect(contentRect.left).to.be.equal(100 - 10);
expect(contentRect.top).to.be.equal(0 - 10);
|
73bcce88
luigser
COMPONENTS
|
143
144
|
// Also check the math, just in case.
|
a1a3bc73
Luigi Serra
graphs updates
|
145
146
|
expect(contentRect.left).to.be.equal(divRect.width - 10);
expect(contentRect.top).to.be.equal(divRect.top - 10);
|
73bcce88
luigser
COMPONENTS
|
147
148
149
150
151
152
|
done();
});
});
});
|
a1a3bc73
Luigi Serra
graphs updates
|
153
|
test('badge is positioned correctly when nested in a target element', function(done) {
|
eb240478
Luigi Serra
public room cards...
|
154
155
156
157
158
159
160
161
162
163
164
165
166
|
var f = fixture('nested');
var badge = f.querySelector('paper-badge');
expect(badge.target.getAttribute('id')).to.be.equal('target');
badge.updatePosition();
Polymer.Base.async(function() {
var divRect = f.querySelector('#target').getBoundingClientRect();
expect(divRect.width).to.be.equal(100);
expect(divRect.height).to.be.equal(20);
var contentRect = badge.getBoundingClientRect();
|
a1a3bc73
Luigi Serra
graphs updates
|
167
168
|
expect(contentRect.width).to.be.equal(20);
expect(contentRect.height).to.be.equal(20);
|
eb240478
Luigi Serra
public room cards...
|
169
170
171
|
// The target div is 100 x 20, and the badge is centered on the
// top right corner.
|
a1a3bc73
Luigi Serra
graphs updates
|
172
173
|
expect(contentRect.left).to.be.equal(100 - 10);
expect(contentRect.top).to.be.equal(0 - 10);
|
eb240478
Luigi Serra
public room cards...
|
174
175
|
// Also check the math, just in case.
|
a1a3bc73
Luigi Serra
graphs updates
|
176
177
|
expect(contentRect.left).to.be.equal(divRect.width - 10);
expect(contentRect.top).to.be.equal(divRect.top - 10);
|
eb240478
Luigi Serra
public room cards...
|
178
179
180
181
182
|
done();
});
});
|
a1a3bc73
Luigi Serra
graphs updates
|
183
184
185
186
187
188
189
190
191
192
193
194
195
|
test('badge displays icons correctly', function(done) {
var f = fixture('icon-badge');
var badge = f.querySelector('paper-badge');
Polymer.Base.async(function() {
var icon = Polymer.dom(badge.root).querySelector('iron-icon');
expect(icon).not.to.be.null;
expect(icon.icon).to.be.equal(badge.icon);
expect(badge.getAttribute('aria-label')).to.be.equal(badge.label);
done();
});
});
|
73bcce88
luigser
COMPONENTS
|
196
197
198
199
|
suite('badge is inside a custom element', function() {
test('badge is positioned correctly', function(done) {
var f = fixture('custom');
var badge = f.$.badge;
|
a1a3bc73
Luigi Serra
graphs updates
|
200
|
var actualbadge = Polymer.dom(badge.root).querySelector('.badge');
|
73bcce88
luigser
COMPONENTS
|
201
202
203
204
|
badge.updatePosition();
Polymer.Base.async(function() {
|
a1a3bc73
Luigi Serra
graphs updates
|
205
206
|
assert.equal(actualbadge.textContent.trim(), "1");
|
73bcce88
luigser
COMPONENTS
|
207
208
209
210
211
|
var divRect = f.$.button.getBoundingClientRect();
expect(divRect.width).to.be.equal(100);
expect(divRect.height).to.be.equal(20);
var contentRect = badge.getBoundingClientRect();
|
a1a3bc73
Luigi Serra
graphs updates
|
212
213
|
expect(contentRect.width).to.be.equal(20);
expect(contentRect.height).to.be.equal(20);
|
73bcce88
luigser
COMPONENTS
|
214
215
216
|
// The target div is 100 x 20, and the badge is centered on the
// top right corner.
|
a1a3bc73
Luigi Serra
graphs updates
|
217
218
|
expect(contentRect.left).to.be.equal(100 - 10);
expect(contentRect.top).to.be.equal(0 - 10);
|
73bcce88
luigser
COMPONENTS
|
219
220
|
// Also check the math, just in case.
|
a1a3bc73
Luigi Serra
graphs updates
|
221
222
|
expect(contentRect.left).to.be.equal(divRect.width - 10);
expect(contentRect.top).to.be.equal(divRect.top - 10);
|
73bcce88
luigser
COMPONENTS
|
223
224
225
226
227
228
229
230
231
|
done();
});
});
});
});
</script>
</body>
</html>
|