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
15
<title>iron-iconset-svg</title>
16
<meta charset="utf-8">
17
<meta name="viewport" content="width=device-width, initial-scale=1.0">
19
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
20
<script src="../../web-component-tester/browser.js"></script>
21
<script src="../../test-fixture/test-fixture-mocha.js"></script>
23
<link rel="import" href="../iron-iconset-svg.html">
24
<link rel="import" href="../../iron-meta/iron-meta.html">
25
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
26
<link rel="import" href="../../test-fixture/test-fixture.html">
31
<test-fixture id="TrivialIconsetSvg">
33
<iron-iconset-svg name="foo"></iron-iconset-svg>
34
<iron-meta type="iconset"></iron-meta>
38
<test-fixture id="StandardIconsetSvg">
40
<iron-iconset-svg name="my-icons" size="20">
43
<circle id="circle" cx="20" cy="20" r="10"></circle>
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>
57
suite('<iron-iconset>', function () {
59
suite('basic behavior', function () {
65
loadedPromise = new Promise(function(resolve) {
66
window.addEventListener('iron-iconset-added', function(ev) {
67
if (ev && ev.detail === iconset) {
72
var elements = fixture('TrivialIconsetSvg');
73
iconset = elements[0];
77
test('it can be accessed via iron-meta', function () {
78
expect(meta.byKey('foo')).to.be.equal(iconset);
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);
87
test('it fires an iron-iconset-added event on the window', function() {
92
suite('when paired with a size and SVG definition', function () {
97
var elements = fixture('StandardIconsetSvg');
98
iconset = elements[0];
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);
108
test('appends a child to the target element', function () {
109
expect(div.firstElementChild).to.not.be.ok;
110
iconset.applyIcon(div, 'circle');
111
expect(div.firstElementChild).to.be.ok;
114
test('can be queried for all available icons', function () {
115
expect(iconset.getIconNames()).to.deep.eql(['my-icons:circle', 'my-icons:square', 'my-icons:rect']);
118
test('supports any icon defined in the svg', function () {
121
iconset.getIconNames().forEach(function (iconName) {
122
iconset.applyIcon(div, iconName.split(':').pop());
123
expect(div.firstElementChild).to.not.be.equal(lastSvgIcon);
124
lastSvgIcon = div.firstElementChild;
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');
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');