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-meta</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-meta.html">
24
<link rel="import" href="../../test-fixture/test-fixture.html">
29
<test-fixture id="TrivialMeta">
31
<iron-meta self key="info"></iron-meta>
35
<test-fixture id="ManyMetas">
37
<iron-meta self key="default1"></iron-meta>
38
<iron-meta self key="default2"></iron-meta>
39
<iron-meta self key="default3"></iron-meta>
43
<test-fixture id="DifferentTypedMetas">
45
<iron-meta self type="foo" key="foobarKey"></iron-meta>
46
<iron-meta self type="bar" key="foobarKey"></iron-meta>
47
<iron-meta self key="defaultKey"></iron-meta>
51
<test-fixture id="ClashingMetas">
53
<iron-meta self key="baz"></iron-meta>
54
<iron-meta self key="baz"></iron-meta>
59
suite('<iron-meta>', function () {
60
suite('basic behavior', function () {
64
meta = fixture('TrivialMeta');
67
teardown(function () {
71
test('uses itself as the default value', function () {
72
expect(meta.value).to.be.equal(meta);
75
test('can be assigned alternative values', function () {
76
meta.value = 'foobar';
78
expect(meta.list[0]).to.be.equal('foobar');
81
test('can access same-type meta values by key', function () {
82
expect(meta.byKey(meta.key)).to.be.equal(meta.value);
85
test('yields a list of same-type meta data', function () {
86
expect(meta.list).to.be.ok;
87
expect(meta.list.length).to.be.equal(1);
88
expect(meta.list[0]).to.be.equal(meta);
92
suite('many same-typed metas', function () {
96
metas = fixture('ManyMetas');
99
teardown(function () {
100
metas.forEach(function (meta) {
105
test('all cache all meta values', function () {
106
metas.forEach(function (meta, index) {
107
expect(meta.list.length).to.be.equal(metas.length);
108
expect(meta.list[index].value).to.be.equal(meta.value);
112
test('can be unregistered individually', function () {
115
expect(metas[0].list.length).to.be.equal(2);
116
expect(metas[0].list).to.be.deep.equal([metas[1], metas[2]])
119
test('can access each others value by key', function () {
120
expect(metas[0].byKey('default2')).to.be.equal(metas[1].value);
124
suite('different-typed metas', function () {
128
metas = fixture('DifferentTypedMetas');
131
teardown(function () {
132
metas.forEach(function (meta) {
137
test('cache their values separately', function () {
138
var fooMeta = metas[0];
139
var barMeta = metas[1];
141
expect(fooMeta.value).to.not.be.equal(barMeta.value);
142
expect(fooMeta.byKey('foobarKey')).to.be.equal(fooMeta.value);
143
expect(barMeta.byKey('foobarKey')).to.be.equal(barMeta.value);
146
test('cannot access values of other types', function () {
147
var defaultMeta = metas[2];
149
expect(defaultMeta.byKey('foobarKey')).to.be.equal(undefined);
152
test('only list values of their type', function () {
153
metas.forEach(function (meta) {
154
expect(meta.list.length).to.be.equal(1);
155
expect(meta.list[0]).to.be.equal(meta.value);
160
suite('metas with clashing keys', function () {
164
metaPair = fixture('ClashingMetas');
167
teardown(function () {
168
metaPair.forEach(function (meta) {
173
test('let the last value win registration against the key', function () {
174
var registeredValue = metaPair[0].byKey(metaPair[0].key);
175
var firstValue = metaPair[0].value;
176
var secondValue = metaPair[1].value;
178
expect(registeredValue).to.not.be.equal(firstValue);
179
expect(registeredValue).to.be.equal(secondValue);
183
suite('singleton', function () {
185
test('only one ironmeta created', function () {
186
var first = Polymer.IronMeta.getIronMeta();
187
var second = Polymer.IronMeta.getIronMeta();
188
expect(first).to.be.equal(second);