Blame view

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