4
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
Code distributed by Google as part of the polymer project is also
9
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
13
<meta charset="UTF-8">
14
<title>paper-fab basic tests</title>
15
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
17
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
18
<script src="../../web-component-tester/browser.js"></script>
20
<link rel="import" href="../../iron-icons/iron-icons.html">
21
<link rel="import" href="../paper-fab.html">
26
<test-fixture id="TrivialFab">
28
<div style="line-height:30px;">
29
<paper-fab id="fab1" icon="add"></paper-fab>
34
<test-fixture id="SrcFab">
36
<paper-fab src="add.png"></paper-fab>
40
<test-fixture id="icon-fab">
42
<paper-fab icon="favorite" label="favorite icon"></paper-fab>
46
<test-fixture id="icon-src-fab">
48
<paper-fab src="add.png" label="add icon"></paper-fab>
52
<test-fixture id="label-fab">
54
<paper-fab label="HTML"></paper-fab>
65
function centerOf(element) {
66
var rect = element.getBoundingClientRect();
67
return {left: rect.left + rect.width / 2, top: rect.top + rect.height / 2};
70
function approxEqual(p1, p2) {
71
return Math.round(p1.left) == Math.round(p2.left) && Math.round(p1.top) == Math.round(p2.top);
74
function isHidden(element) {
75
var rect = element.getBoundingClientRect();
76
return (rect.width == 0 && rect.height == 0);
80
f1 = fixture('TrivialFab').querySelector('#fab1');
81
f2 = fixture('SrcFab');
82
f3 = fixture('icon-fab');
83
f4 = fixture('icon-src-fab');
84
f5 = fixture('label-fab');
87
test('applies an icon specified by the `icon` attribute', function() {
88
assert.isFalse(!!f1.$.icon.usesSrcAttribute);
89
assert.ok(Polymer.dom(f1.$.icon.root).querySelector('svg'));
92
test('applies an icon specified by the `src` attribute', function() {
93
assert.isFalse(f2.$.icon._usesIconset());
94
assert.ok(f2.$.icon._img);
97
test('renders correctly independent of line height', function() {
98
assert.ok(approxEqual(centerOf(f1.$.icon), centerOf(f1)));
101
test('fab displays icon with `icon` and `label` attributes', function(done) {
102
Polymer.Base.async(function() {
103
var icon = f3.$$('iron-icon');
104
var text = f3.$$('span');
105
expect(icon).not.to.be.null;
106
assert.isFalse(isHidden(icon));
107
assert.isTrue(isHidden(text));
108
expect(icon.icon).to.be.equal(f3.icon);
109
expect(f3.getAttribute('aria-label')).to.be.equal(f3.label);
114
test('fab displays icon with `src` and `label` attributes', function(done) {
115
Polymer.Base.async(function() {
116
var icon = f4.$$('iron-icon');
117
var text = f4.$$('span');
118
expect(icon).not.to.be.null;
119
assert.isFalse(isHidden(icon));
120
assert.isTrue(isHidden(text));
121
expect(icon.src).to.be.equal(f4.src);
122
expect(f4.getAttribute('aria-label')).to.be.equal(f4.label);
127
test('fab displays label with `label` attribute correctly', function(done) {
128
Polymer.Base.async(function() {
129
var icon = f5.$$('iron-icon');
130
var text = f5.$$('span');
131
expect(text).not.to.be.null;
132
assert.isTrue(isHidden(icon));
133
assert.isFalse(isHidden(text));
134
expect(text.innerHTML).to.be.equal(f5.label);
135
expect(f5.getAttribute('aria-label')).to.be.equal(f5.label);