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-meta</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-meta.html"> |
| 23 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 24 |
| 25 </head> |
| 26 <body> |
| 27 |
| 28 <test-fixture id="TrivialMeta"> |
| 29 <template> |
| 30 <iron-meta self key="info"></iron-meta> |
| 31 </template> |
| 32 </test-fixture> |
| 33 |
| 34 <test-fixture id="ManyMetas"> |
| 35 <template> |
| 36 <iron-meta self key="default1"></iron-meta> |
| 37 <iron-meta self key="default2"></iron-meta> |
| 38 <iron-meta self key="default3"></iron-meta> |
| 39 </template> |
| 40 </test-fixture> |
| 41 |
| 42 <test-fixture id="DifferentTypedMetas"> |
| 43 <template> |
| 44 <iron-meta self type="foo" key="foobarKey"></iron-meta> |
| 45 <iron-meta self type="bar" key="foobarKey"></iron-meta> |
| 46 <iron-meta self key="defaultKey"></iron-meta> |
| 47 </template> |
| 48 </test-fixture> |
| 49 |
| 50 <test-fixture id="ClashingMetas"> |
| 51 <template> |
| 52 <iron-meta self key="baz"></iron-meta> |
| 53 <iron-meta self key="baz"></iron-meta> |
| 54 </template> |
| 55 </test-fixture> |
| 56 |
| 57 <script> |
| 58 suite('<iron-meta>', function () { |
| 59 suite('basic behavior', function () { |
| 60 var meta; |
| 61 |
| 62 setup(function () { |
| 63 meta = fixture('TrivialMeta'); |
| 64 }); |
| 65 |
| 66 teardown(function () { |
| 67 meta.key = null; |
| 68 }); |
| 69 |
| 70 test('uses itself as the default value', function () { |
| 71 expect(meta.value).to.be.equal(meta); |
| 72 }); |
| 73 |
| 74 test('can be assigned alternative values', function () { |
| 75 meta.value = 'foobar'; |
| 76 |
| 77 expect(meta.list[0]).to.be.equal('foobar'); |
| 78 }); |
| 79 |
| 80 test('can access same-type meta values by key', function () { |
| 81 expect(meta.byKey(meta.key)).to.be.equal(meta.value); |
| 82 }); |
| 83 |
| 84 test('yields a list of same-type meta data', function () { |
| 85 expect(meta.list).to.be.ok; |
| 86 expect(meta.list.length).to.be.equal(1); |
| 87 expect(meta.list[0]).to.be.equal(meta); |
| 88 }); |
| 89 }); |
| 90 |
| 91 suite('many same-typed metas', function () { |
| 92 var metas; |
| 93 |
| 94 setup(function () { |
| 95 metas = fixture('ManyMetas'); |
| 96 }); |
| 97 |
| 98 teardown(function () { |
| 99 metas.forEach(function (meta) { |
| 100 meta.key = null; |
| 101 }); |
| 102 }); |
| 103 |
| 104 test('all cache all meta values', function () { |
| 105 metas.forEach(function (meta, index) { |
| 106 expect(meta.list.length).to.be.equal(metas.length); |
| 107 expect(meta.list[index].value).to.be.equal(meta.value); |
| 108 }); |
| 109 }); |
| 110 |
| 111 test('can be unregistered individually', function () { |
| 112 metas[0].key = null; |
| 113 |
| 114 expect(metas[0].list.length).to.be.equal(2); |
| 115 expect(metas[0].list).to.be.deep.equal([metas[1], metas[2]]) |
| 116 }); |
| 117 |
| 118 test('can access each others value by key', function () { |
| 119 expect(metas[0].byKey('default2')).to.be.equal(metas[1].value); |
| 120 }); |
| 121 }); |
| 122 |
| 123 suite('different-typed metas', function () { |
| 124 var metas; |
| 125 |
| 126 setup(function () { |
| 127 metas = fixture('DifferentTypedMetas'); |
| 128 }); |
| 129 |
| 130 teardown(function () { |
| 131 metas.forEach(function (meta) { |
| 132 meta.key = null; |
| 133 }); |
| 134 }); |
| 135 |
| 136 test('cache their values separately', function () { |
| 137 var fooMeta = metas[0]; |
| 138 var barMeta = metas[1]; |
| 139 |
| 140 expect(fooMeta.value).to.not.be.equal(barMeta.value); |
| 141 expect(fooMeta.byKey('foobarKey')).to.be.equal(fooMeta.value); |
| 142 expect(barMeta.byKey('foobarKey')).to.be.equal(barMeta.value); |
| 143 }); |
| 144 |
| 145 test('cannot access values of other types', function () { |
| 146 var defaultMeta = metas[2]; |
| 147 |
| 148 expect(defaultMeta.byKey('foobarKey')).to.be.equal(undefined); |
| 149 }); |
| 150 |
| 151 test('only list values of their type', function () { |
| 152 metas.forEach(function (meta) { |
| 153 expect(meta.list.length).to.be.equal(1); |
| 154 expect(meta.list[0]).to.be.equal(meta.value); |
| 155 }) |
| 156 }); |
| 157 }); |
| 158 |
| 159 suite('metas with clashing keys', function () { |
| 160 var metaPair; |
| 161 |
| 162 setup(function () { |
| 163 metaPair = fixture('ClashingMetas'); |
| 164 }); |
| 165 |
| 166 teardown(function () { |
| 167 metaPair.forEach(function (meta) { |
| 168 meta.key = null; |
| 169 }); |
| 170 }); |
| 171 |
| 172 test('let the last value win registration against the key', function () { |
| 173 var registeredValue = metaPair[0].byKey(metaPair[0].key); |
| 174 var firstValue = metaPair[0].value; |
| 175 var secondValue = metaPair[1].value; |
| 176 |
| 177 expect(registeredValue).to.not.be.equal(firstValue); |
| 178 expect(registeredValue).to.be.equal(secondValue); |
| 179 }); |
| 180 }); |
| 181 }); |
| 182 </script> |
| 183 |
| 184 </body> |
| 185 </html> |
OLD | NEW |