1<!doctype html>
2<!--
3@license
4Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8Code distributed by Google as part of the polymer project is also
9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10-->
11<html>
12<head>
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">
16
17  <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
18  <script src="../../web-component-tester/browser.js"></script>
19
20  <link rel="import" href="../../iron-icons/iron-icons.html">
21  <link rel="import" href="../paper-fab.html">
22
23</head>
24<body>
25
26  <test-fixture id="TrivialFab">
27    <template>
28      <div style="line-height:30px;">
29        <paper-fab id="fab1" icon="add"></paper-fab>
30      </div>
31    </template>
32  </test-fixture>
33
34  <test-fixture id="SrcFab">
35    <template>
36      <paper-fab src="add.png"></paper-fab>
37    </template>
38  </test-fixture>
39
40  <test-fixture id="icon-fab">
41    <template>
42      <paper-fab icon="favorite" label="favorite icon"></paper-fab>
43    </template>
44  </test-fixture>
45
46  <test-fixture id="icon-src-fab">
47    <template>
48      <paper-fab src="add.png" label="add icon"></paper-fab>
49    </template>
50  </test-fixture>
51
52  <test-fixture id="label-fab">
53    <template>
54      <paper-fab label="HTML"></paper-fab>
55    </template>
56  </test-fixture>
57
58  <script>
59    var f1;
60    var f2;
61    var f3;
62    var f4;
63    var f5;
64
65    function centerOf(element) {
66      var rect = element.getBoundingClientRect();
67      return {left: rect.left + rect.width / 2, top: rect.top + rect.height / 2};
68    }
69
70    function approxEqual(p1, p2) {
71      return Math.round(p1.left) == Math.round(p2.left) && Math.round(p1.top) == Math.round(p2.top);
72    }
73
74    function isHidden(element) {
75      var rect = element.getBoundingClientRect();
76      return (rect.width == 0 && rect.height == 0);
77    }
78
79    setup(function() {
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');
85    });
86
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'));
90    });
91
92    test('applies an icon specified by the `src` attribute', function() {
93      assert.isFalse(f2.$.icon._usesIconset());
94      assert.ok(f2.$.icon._img);
95    });
96
97    test('renders correctly independent of line height', function() {
98      assert.ok(approxEqual(centerOf(f1.$.icon), centerOf(f1)));
99    });
100
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);
110        done();
111      });
112    });
113
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);
123        done();
124      });
125    });
126
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);
136        done();
137      });
138    });
139  </script>
140</body>
141</html>
142