OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 @license | 3 @license |
4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 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.g
ithub.io/LICENSE.txt | 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.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/CONTRI
BUTORS.txt | 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
8 Code distributed by Google as part of the polymer project is also | 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/PATEN
TS.txt | 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
10 --> | 10 --> |
11 | 11 |
12 <html> | 12 <html> |
13 <head> | 13 <head> |
14 | 14 |
15 <title>iron-iconset-svg</title> | 15 <title>iron-iconset-svg</title> |
16 <meta charset="utf-8"> | 16 <meta charset="utf-8"> |
17 <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 17 <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
18 | 18 |
19 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> | 19 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
20 <script src="../../web-component-tester/browser.js"></script> | 20 <script src="../../web-component-tester/browser.js"></script> |
21 <script src="../../test-fixture/test-fixture-mocha.js"></script> | 21 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
22 | 22 |
23 <link rel="import" href="../iron-iconset-svg.html"> | 23 <link rel="import" href="../iron-iconset-svg.html"> |
24 <link rel="import" href="../../iron-meta/iron-meta.html"> | 24 <link rel="import" href="../../iron-meta/iron-meta.html"> |
| 25 <link rel="import" href="../../promise-polyfill/promise-polyfill.html"> |
25 <link rel="import" href="../../test-fixture/test-fixture.html"> | 26 <link rel="import" href="../../test-fixture/test-fixture.html"> |
26 | 27 |
27 </head> | 28 </head> |
28 <body> | 29 <body> |
29 | 30 |
30 <test-fixture id="TrivialIconsetSvg"> | 31 <test-fixture id="TrivialIconsetSvg"> |
31 <template> | 32 <template> |
32 <iron-iconset-svg name="foo"></iron-iconset-svg> | 33 <iron-iconset-svg name="foo"></iron-iconset-svg> |
33 <iron-meta type="iconset"></iron-meta> | 34 <iron-meta type="iconset"></iron-meta> |
34 </template> | 35 </template> |
35 </test-fixture> | 36 </test-fixture> |
36 | 37 |
37 <test-fixture id="StandardIconsetSvg"> | 38 <test-fixture id="StandardIconsetSvg"> |
38 <template> | 39 <template> |
39 <iron-iconset-svg name="my-icons" size="20"> | 40 <iron-iconset-svg name="my-icons" size="20"> |
40 <svg> | 41 <svg> |
41 <defs> | 42 <defs> |
42 <circle id="circle" cx="20" cy="20" r="10"></circle> | 43 <circle id="circle" cx="20" cy="20" r="10"></circle> |
43 <rect id="square" x="0" y="0" width="20" height="20"></rect> | 44 <rect id="square" x="0" y="0" width="20" height="20"></rect> |
| 45 <symbol id="rect" viewBox="0 0 50 25"> |
| 46 <rect x="0" y="0" width="50" height="25"></rect> |
| 47 </symbol> |
44 </defs> | 48 </defs> |
45 </svg> | 49 </svg> |
46 </iron-iconset-svg> | 50 </iron-iconset-svg> |
47 <div></div> | 51 <div></div> |
48 </template> | 52 </template> |
49 </test-fixture> | 53 </test-fixture> |
50 | 54 |
51 <script> | 55 <script> |
52 | 56 |
53 suite('<iron-iconset>', function () { | 57 suite('<iron-iconset>', function () { |
54 | 58 |
55 suite('basic behavior', function () { | 59 suite('basic behavior', function () { |
56 var iconset; | 60 var iconset; |
57 var meta; | 61 var meta; |
| 62 var loadedPromise; |
58 | 63 |
59 setup(function () { | 64 setup(function () { |
| 65 loadedPromise = new Promise(function(resolve) { |
| 66 window.addEventListener('iron-iconset-added', function(ev) { |
| 67 if (ev && ev.detail === iconset) { |
| 68 resolve(); |
| 69 } |
| 70 }); |
| 71 }); |
60 var elements = fixture('TrivialIconsetSvg'); | 72 var elements = fixture('TrivialIconsetSvg'); |
61 iconset = elements[0]; | 73 iconset = elements[0]; |
62 meta = elements[1]; | 74 meta = elements[1]; |
63 }); | 75 }); |
64 | 76 |
65 test('it can be accessed via iron-meta', function () { | 77 test('it can be accessed via iron-meta', function () { |
66 expect(meta.byKey('foo')).to.be.equal(iconset); | 78 expect(meta.byKey('foo')).to.be.equal(iconset); |
67 }); | 79 }); |
| 80 |
| 81 test('it does not have a size', function () { |
| 82 var rect = iconset.getBoundingClientRect(); |
| 83 expect(rect.width).to.be.equal(0); |
| 84 expect(rect.height).to.be.equal(0); |
| 85 }); |
| 86 |
| 87 test('it fires an iron-iconset-added event on the window', function() { |
| 88 return loadedPromise; |
| 89 }); |
68 }); | 90 }); |
69 | 91 |
70 suite('when paired with a size and SVG definition', function () { | 92 suite('when paired with a size and SVG definition', function () { |
71 var iconset; | 93 var iconset; |
72 var div; | 94 var div; |
73 | 95 |
74 setup(function () { | 96 setup(function () { |
75 var elements = fixture('StandardIconsetSvg'); | 97 var elements = fixture('StandardIconsetSvg'); |
76 iconset = elements[0]; | 98 iconset = elements[0]; |
77 div = elements[1]; | 99 div = elements[1]; |
78 }); | 100 }); |
79 | 101 |
| 102 test('it does not have a size', function () { |
| 103 var rect = iconset.getBoundingClientRect(); |
| 104 expect(rect.width).to.be.equal(0); |
| 105 expect(rect.height).to.be.equal(0); |
| 106 }); |
| 107 |
80 test('appends a child to the target element', function () { | 108 test('appends a child to the target element', function () { |
81 expect(div.firstElementChild).to.not.be.ok; | 109 expect(div.firstElementChild).to.not.be.ok; |
82 iconset.applyIcon(div, 'circle'); | 110 iconset.applyIcon(div, 'circle'); |
83 expect(div.firstElementChild).to.be.ok; | 111 expect(div.firstElementChild).to.be.ok; |
84 }); | 112 }); |
85 | 113 |
86 test('can be queried for all available icons', function () { | 114 test('can be queried for all available icons', function () { |
87 expect(iconset.getIconNames()).to.deep.eql(['my-icons:circle', 'my-ico
ns:square']); | 115 expect(iconset.getIconNames()).to.deep.eql(['my-icons:circle', 'my-ico
ns:square', 'my-icons:rect']); |
88 }); | 116 }); |
89 | 117 |
90 test('supports any icon defined in the svg', function () { | 118 test('supports any icon defined in the svg', function () { |
91 var lastSvgIcon; | 119 var lastSvgIcon; |
92 | 120 |
93 iconset.getIconNames().forEach(function (iconName) { | 121 iconset.getIconNames().forEach(function (iconName) { |
94 iconset.applyIcon(div, iconName.split(':').pop()); | 122 iconset.applyIcon(div, iconName.split(':').pop()); |
95 expect(div.firstElementChild).to.not.be.equal(lastSvgIcon); | 123 expect(div.firstElementChild).to.not.be.equal(lastSvgIcon); |
96 lastSvgIcon = div.firstElementChild; | 124 lastSvgIcon = div.firstElementChild; |
97 }); | 125 }); |
98 }); | 126 }); |
99 | 127 |
| 128 test('prefers a viewBox attribute over the iconset size', function () { |
| 129 iconset.applyIcon(div, 'rect'); |
| 130 expect(div.firstElementChild.getAttribute('viewBox')).to.be.equal('0 0
50 25'); |
| 131 }); |
| 132 |
| 133 test('uses the iconset size when viewBox is not defined on the element',
function () { |
| 134 iconset.applyIcon(div, 'circle'); |
| 135 expect(div.firstElementChild.getAttribute('viewBox')).to.be.equal('0 0
20 20'); |
| 136 }); |
| 137 |
100 }); | 138 }); |
101 | 139 |
102 }); | 140 }); |
103 | 141 |
104 </script> | 142 </script> |
105 | 143 |
106 </body> | 144 </body> |
107 </html> | 145 </html> |
OLD | NEW |