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</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.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="TrivialIconset">
33
<iron-iconset name="foo" src="../demo/my-icons.png"></iron-iconset>
34
<iron-meta type="iconset"></iron-meta>
38
<test-fixture id="StandardIconset">
40
<iron-iconset name="my-icons"
41
src="../demo/my-icons.png"
44
icons="location place starta stopb bus car train walk"></iron-iconset>
49
<test-fixture id="ThemedIconset">
51
<iron-iconset name="my-icons"
52
src="../demo/my-icons.png"
55
icons="location place starta stopb bus car train walk">
56
<property theme="large" offset-x="10" offset-y="10"></property>
63
suite('<iron-iconset>', function () {
64
suite('basic behavior', function () {
70
loadedPromise = new Promise(function(resolve) {
71
window.addEventListener('iron-iconset-added', function(ev) {
72
if (ev && ev.detail === iconset) {
78
var elements = fixture('TrivialIconset');
80
iconset = elements[0];
84
test('it can be accessed via iron-meta', function () {
85
expect(meta.byKey('foo')).to.be.equal(iconset);
88
test('it fires an iron-iconset-added event on the window', function() {
93
suite('when src, width, iconSize and icons are assigned', function () {
98
var elements = fixture('StandardIconset');
100
iconset = elements[0];
105
test('appends a child to the target element', function () {
106
expect(div.firstElementChild).to.not.be.ok;
108
iconset.applyIcon(div, 'location');
110
expect(div.firstElementChild).to.be.ok;
114
test('sets the background image of the target element', function () {
117
iconset.applyIcon(div, 'location');
118
iconStyle = window.getComputedStyle(div);
120
expect(iconStyle.backgroundImage).to.match(/url\(.*demo\/my-icons.png["']?\)/);
123
test('offsets the background image to the icon\'s position', function () {
126
iconset.applyIcon(div, 'bus');
127
iconStyle = window.getComputedStyle(div);
129
expect(iconStyle.backgroundPosition).to.match(/0(px|%) -24px/);
133
suite('when an iconset is themed', function () {
138
var elements = fixture('ThemedIconset');
140
iconset = elements[0];
144
test('can use a theme when applying icon', function () {
145
iconset.applyIcon(div, 'bus', 'large');
147
expect(div).to.be.ok;
150
test('adjusts the icon by the theme offset', function () {
153
iconset.applyIcon(div, 'bus', 'large');
154
iconStyle = window.getComputedStyle(div);
156
expect(iconStyle.backgroundPosition).to.match(/-10px -34px/);