• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<!--
3@license
4Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8Code distributed by Google as part of the polymer project is also
9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10-->
11
12<html>
13  <head>
14
15    <title>iron-meta</title>
16    <meta charset="utf-8">
17    <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
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>
22
23    <link rel="import" href="../iron-meta.html">
24    <link rel="import" href="../../test-fixture/test-fixture.html">
25
26  </head>
27  <body>
28
29    <test-fixture id="TrivialMeta">
30      <template>
31        <iron-meta self key="info"></iron-meta>
32      </template>
33    </test-fixture>
34
35    <test-fixture id="ManyMetas">
36      <template>
37        <iron-meta self key="default1"></iron-meta>
38        <iron-meta self key="default2"></iron-meta>
39        <iron-meta self key="default3"></iron-meta>
40      </template>
41    </test-fixture>
42
43    <test-fixture id="DifferentTypedMetas">
44      <template>
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>
48      </template>
49    </test-fixture>
50
51    <test-fixture id="ClashingMetas">
52      <template>
53        <iron-meta self key="baz"></iron-meta>
54        <iron-meta self key="baz"></iron-meta>
55      </template>
56    </test-fixture>
57
58    <script>
59suite('<iron-meta>', function () {
60  suite('basic behavior', function () {
61    var meta;
62
63    setup(function () {
64      meta = fixture('TrivialMeta');
65    });
66
67    teardown(function () {
68      meta.key = null;
69    });
70
71    test('uses itself as the default value', function () {
72      expect(meta.value).to.be.equal(meta);
73    });
74
75    test('can be assigned alternative values', function () {
76      meta.value = 'foobar';
77
78      expect(meta.list[0]).to.be.equal('foobar');
79    });
80
81    test('can access same-type meta values by key', function () {
82      expect(meta.byKey(meta.key)).to.be.equal(meta.value);
83    });
84
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);
89    });
90  });
91
92  suite('many same-typed metas', function () {
93    var metas;
94
95    setup(function () {
96      metas = fixture('ManyMetas');
97    });
98
99    teardown(function () {
100      metas.forEach(function (meta) {
101        meta.key = null;
102      });
103    });
104
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);
109      });
110    });
111
112    test('can be unregistered individually', function () {
113      metas[0].key = null;
114
115      expect(metas[0].list.length).to.be.equal(2);
116      expect(metas[0].list).to.be.deep.equal([metas[1], metas[2]])
117    });
118
119    test('can access each others value by key', function () {
120      expect(metas[0].byKey('default2')).to.be.equal(metas[1].value);
121    });
122  });
123
124  suite('different-typed metas', function () {
125    var metas;
126
127    setup(function () {
128      metas = fixture('DifferentTypedMetas');
129    });
130
131    teardown(function () {
132      metas.forEach(function (meta) {
133        meta.key = null;
134      });
135    });
136
137    test('cache their values separately', function () {
138      var fooMeta = metas[0];
139      var barMeta = metas[1];
140
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);
144    });
145
146    test('cannot access values of other types', function () {
147      var defaultMeta = metas[2];
148
149      expect(defaultMeta.byKey('foobarKey')).to.be.equal(undefined);
150    });
151
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);
156      })
157    });
158  });
159
160  suite('metas with clashing keys', function () {
161    var metaPair;
162
163    setup(function () {
164      metaPair = fixture('ClashingMetas');
165    });
166
167    teardown(function () {
168      metaPair.forEach(function (meta) {
169        meta.key = null;
170      });
171    });
172
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;
177
178      expect(registeredValue).to.not.be.equal(firstValue);
179      expect(registeredValue).to.be.equal(secondValue);
180    });
181  });
182
183  suite('singleton', function () {
184
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);
189    });
190  });
191});
192    </script>
193
194  </body>
195</html>
196