OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 |
| 11 <html> |
| 12 <head> |
| 13 |
| 14 <title>iron-icon</title> |
| 15 <meta charset="utf-8"> |
| 16 <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 17 |
| 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 19 <script src="../../web-component-tester/browser.js"></script> |
| 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 21 |
| 22 <link rel="import" href="../iron-icon.html"> |
| 23 <link rel="import" href="../../iron-iconset/iron-iconset.html"> |
| 24 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 25 |
| 26 </head> |
| 27 <body> |
| 28 |
| 29 <test-fixture id="TrivialIcon"> |
| 30 <template> |
| 31 <iron-icon src="../demo/location.png"></iron-icon> |
| 32 </template> |
| 33 </test-fixture> |
| 34 |
| 35 <test-fixture id="IconFromIconset"> |
| 36 <template> |
| 37 <iron-iconset name="example" icons="location blank" src="location.png" siz
e="24" width="48"></iron-iconset> |
| 38 <iron-icon icon="example:location"></iron-icon> |
| 39 </template> |
| 40 </test-fixture> |
| 41 |
| 42 <test-fixture id="WithoutAnIconSource"> |
| 43 <template> |
| 44 <iron-icon icon=""></iron-icon> |
| 45 <iron-icon></iron-icon> |
| 46 <iron-icon src=""></iron-icon> |
| 47 </template> |
| 48 </test-fixture> |
| 49 |
| 50 <script> |
| 51 function iconElementFor (node) { |
| 52 var nodes = Polymer.dom(node.root).childNodes; |
| 53 |
| 54 for (var i = 0; i < nodes.length; ++i) { |
| 55 if (nodes[i].nodeName.match(/DIV|IMG/)) { |
| 56 return nodes[i]; |
| 57 } |
| 58 } |
| 59 } |
| 60 |
| 61 function hasIcon (node) { |
| 62 return /png/.test(node.style.backgroundImage); |
| 63 } |
| 64 |
| 65 suite('<iron-icon>', function() { |
| 66 suite('basic behavior', function() { |
| 67 var icon; |
| 68 |
| 69 setup(function() { |
| 70 icon = fixture('TrivialIcon'); |
| 71 }); |
| 72 |
| 73 test('can be assigned an icon with the src attribute', function() { |
| 74 expect(iconElementFor(icon)).to.be.ok; |
| 75 expect(iconElementFor(icon).src).to.match(/demo\/location\.png/); |
| 76 }); |
| 77 |
| 78 test('can change its src dynamically', function() { |
| 79 icon.src = 'foo.png'; |
| 80 |
| 81 expect(iconElementFor(icon).src).to.match(/foo\.png/); |
| 82 }); |
| 83 }); |
| 84 |
| 85 suite('when paired with an iconset', function() { |
| 86 var icon; |
| 87 |
| 88 setup(function() { |
| 89 var elements = fixture('IconFromIconset'); |
| 90 |
| 91 icon = elements[1]; |
| 92 }); |
| 93 |
| 94 test('can be assigned an icon from the iconset', function() { |
| 95 expect(hasIcon(icon)).to.be.ok; |
| 96 }); |
| 97 |
| 98 test('can change its icon dynamically', function() { |
| 99 var style = icon.style; |
| 100 |
| 101 expect(style.backgroundPositionX).to.be.eql('0px'); |
| 102 |
| 103 icon.icon = "example:blank"; |
| 104 |
| 105 expect(style.backgroundPositionX).to.be.eql('-24px'); |
| 106 }); |
| 107 }); |
| 108 |
| 109 suite('when no icon source is provided', function() { |
| 110 test('will politely wait for an icon source without throwing', function() { |
| 111 document.createElement('iron-icon'); |
| 112 fixture('WithoutAnIconSource'); |
| 113 }); |
| 114 }) |
| 115 }); |
| 116 </script> |
| 117 |
| 118 </body> |
| 119 </html> |
OLD | NEW |