Blame view

bower_components/iron-label/test/basic.html 4.71 KB
a1a3bc73   Luigi Serra   graphs updates
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
  <!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 lang="en">
  <head>
    <meta charset="UTF-8">
    <title>iron-label basic tests</title>
      <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="../../test-fixture/test-fixture.html">
  
      <link rel="import" href="../iron-label.html">
  </head>
  <body>
  
    <test-fixture id="TrivialWrapper">
      <template>
        <iron-label>
          Label
          <input type="text">
        </iron-label>
      </template>
    </test-fixture>
  
    <test-fixture id="MultiElementWrapper">
      <template>
        <iron-label>
          <span>Label</span>
          <input iron-label-target type="text">
        </iron-label>
      </template>
    </test-fixture>
  
    <test-fixture id="ExplicitId">
      <template>
        <iron-label id="explicit">Label<input type="text"></iron-label>
      </template>
    </test-fixture>
  
    <test-fixture id="TrivialSelector">
      <template>
        <div>
          <iron-label for="input">Label</iron-label>
          <input id="input" type="text">
        </div>
      </template>
    </test-fixture>
  
    <test-fixture id="DynamicLabel">
      <template>
        <div>
          <iron-label id="label"><input id="nested">Label</iron-label>
          <input id="one" type="text">
        </div>
      </template>
    </test-fixture>
  
    <test-fixture id="UniqueIds">
      <template>
        <iron-label></iron-label>
        <iron-label></iron-label>
      </template>
    </test-fixture>
  
    <script>
      suite('basic', function() {
  
        test('id generated on creation', function() {
          var e = document.createElement('iron-label');
          assert(e.id, 'iron-label-0');
        });
  
        test('id not overwritten if given', function() {
          var label = fixture('ExplicitId');
          assert.equal(label.id, 'explicit', 'explict id is kept');
        });
  
        test('ids are unique', function() {
          var labels = fixture('UniqueIds');
          assert.notEqual(labels[0].id, labels[1].id);
        });
  
        a11ySuite('TrivialWrapper');
        a11ySuite('MultiElementWrapper');
        a11ySuite('ExplicitId');
        a11ySuite('TrivialSelector');
  
      });
  
      suite('targeting', function() {
  
        function expectedTarget(expected, label) {
          assert.ok(expected, 'expected is defined');
          assert.ok(label, 'label is defined');
          var actual = label._findTarget();
          assert.equal(actual, expected, 'target is expected');
          assert.ok(expected.hasAttribute('aria-labelledby'), 'has aria labelledby');
          assert.equal(expected.getAttribute('aria-labelledby'), label.id, 'aria-labelledby points to iron-label');
          if (label.for) {
            assert.equal(label.getAttribute('for'), label.for, 'for property reflected');
          }
        }
  
        test('Trivial', function() {
          var label = fixture('TrivialWrapper');
          var expected = Polymer.dom(label).firstElementChild;
          expectedTarget(expected, label);
        });
  
        test('Multiple', function() {
          var label = fixture('MultiElementWrapper');
          var expected = Polymer.dom(label).querySelector('[iron-label-target]');
          expectedTarget(expected, label);
        });
  
        test('selected target via selector', function() {
          var container = fixture('TrivialSelector');
          var label = Polymer.dom(container).firstElementChild;
          var expected = label.nextElementSibling;
          expectedTarget(expected, label);
        });
  
      });
  
      suite('dynamic targeting', function() {
        var container, label, nested, one;
  
        setup(function() {
          container = fixture('DynamicLabel');
          label = Polymer.dom(container).querySelector('#label');
          nested = Polymer.dom(label).firstElementChild;
          one = Polymer.dom(container).querySelector('#one');
        });
  
        test('nested is target', function() {
          assert.equal(nested.getAttribute('aria-labelledby'), label.id);
          assert.notOk(one.hasAttribute('aria-labelledby'));
        });
  
        test('nested -> #one', function() {
          label.for = 'one';
          assert.equal(one.getAttribute('aria-labelledby'), label.id);
          assert.notOk(nested.hasAttribute('aria-labelledby'));
        });
  
      });
  
    </script>
  
  </body>
  </html>