Blame view

bower_components/paper-input/test/paper-input-container.html 9 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <!doctype html>
  <!--
  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>paper-input-container tests</title>
  
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
c5169e0e   Renato De Donato   a new hope
17
      <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
73bcce88   luigser   COMPONENTS
18
19
20
21
  
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  
    <script src="../../web-component-tester/browser.js"></script>
c5169e0e   Renato De Donato   a new hope
22
23
    <script src="../../test-fixture/test-fixture-mocha.js"></script>
  
73bcce88   luigser   COMPONENTS
24
25
    <script src="../../iron-test-helpers/mock-interactions.js"></script>
  
c5169e0e   Renato De Donato   a new hope
26
    <link rel="import" href="../../test-fixture/test-fixture.html">
73bcce88   luigser   COMPONENTS
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    <link rel="import" href="../../iron-input/iron-input.html">
    <link rel="import" href="../paper-input-container.html">
    <link rel="import" href="letters-only.html">
  
  </head>
  <body>
  
    <test-fixture id="basic">
      <template>
        <paper-input-container>
          <label id="l">label</label>
          <input id="i">
        </paper-input-container>
      </template>
    </test-fixture>
  
73bcce88   luigser   COMPONENTS
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
    <test-fixture id="has-value">
      <template>
        <paper-input-container>
          <label id="l">label</label>
          <input id="i" value="value">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <test-fixture id="no-float-has-value">
      <template>
        <paper-input-container no-label-float>
          <label id="l">label</label>
          <input id="i" value="value">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <test-fixture id="always-float">
      <template>
        <paper-input-container always-float-label>
          <label id="l">label</label>
          <input id="i" value="value">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <test-fixture id="auto-validate-numbers">
      <template>
        <paper-input-container auto-validate>
          <label id="l">label</label>
          <input is="iron-input" id="i" pattern="[0-9]*">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <test-fixture id="manual-validate-numbers">
      <template>
        <paper-input-container>
          <label id="l">label</label>
          <input is="iron-input" id="i" pattern="[0-9]*">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <letters-only></letters-only>
  
    <test-fixture id="auto-validate-validator">
      <template>
        <paper-input-container auto-validate>
          <label id="l">label</label>
          <input is="iron-input" id="i" pattern="[0-9]*" validator="letters-only">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <test-fixture id="auto-validate-validator-has-invalid-value">
      <template>
        <paper-input-container auto-validate>
          <label id="l">label</label>
          <input is="iron-input" id="i" validator="letters-only" value="123123">
        </paper-input-container>
      </template>
    </test-fixture>
  
    <script>
  
      function getTransform(node) {
        var style = getComputedStyle(node);
        return style.transform || style.webkitTransform;
      }
  
      suite('label position', function() {
  
        test('label is visible by default', function() {
          var container = fixture('basic');
          assert.equal(getComputedStyle(container.querySelector('#l')).visibility, 'visible', 'label has visibility:visible');
        });
  
c5169e0e   Renato De Donato   a new hope
122
        test('label is floated if value is initialized to not null', function() {
73bcce88   luigser   COMPONENTS
123
          var container = fixture('has-value');
c5169e0e   Renato De Donato   a new hope
124
          assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'label has transform');
73bcce88   luigser   COMPONENTS
125
126
127
128
129
130
131
132
133
134
        });
  
        test('label is invisible if no-label-float and value is initialized to not null', function() {
          var container = fixture('no-float-has-value');
          assert.equal(getComputedStyle(container.querySelector('#l')).visibility, 'hidden', 'label has visibility:hidden');
        });
  
        test('label is floated if always-float-label is true', function() {
          var container = fixture('always-float');
          assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'label has transform');
c5169e0e   Renato De Donato   a new hope
135
        })
73bcce88   luigser   COMPONENTS
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  
      });
  
      suite('focused styling', function() {
  
        test('label is colored when input is focused and has value', function(done) {
          var container = fixture('has-value');
          var label = Polymer.dom(container).querySelector('#l');
          var input = Polymer.dom(container).querySelector('#i');
          var inputContent = Polymer.dom(container.root).querySelector('.input-content');
          MockInteractions.focus(input);
          requestAnimationFrame(function() {
            assert.isTrue(container.focused, 'focused is true');
            assert.isTrue(inputContent.classList.contains('label-is-highlighted'), 'label is highlighted when input has focus');
            done();
          });
        });
  
        test('label is not colored when input is focused and has null value', function(done) {
          var container = fixture('basic');
          var label = Polymer.dom(container).querySelector('#l');
          var input = Polymer.dom(container).querySelector('#i');
          var inputContent = Polymer.dom(container.root).querySelector('.input-content');
          MockInteractions.focus(input);
          requestAnimationFrame(function() {
            assert.isFalse(inputContent.classList.contains('label-is-highlighted'), 'label is not highlighted when input has focus and has null value');
            done();
          });
        });
  
        test('underline is colored when input is focused', function(done) {
          var container = fixture('basic');
          var input = Polymer.dom(container).querySelector('#i');
          var line = Polymer.dom(container.root).querySelector('.underline');
          assert.isFalse(line.classList.contains('is-highlighted'), 'line is not highlighted when input is not focused');
          MockInteractions.focus(input);
          requestAnimationFrame(function() {
            assert.isTrue(line.classList.contains('is-highlighted'), 'line is highlighted when input is focused');
            done();
          });
        });
  
      });
  
      suite('validation', function() {
  
        test('styled when the input is set to an invalid value with auto-validate', function() {
          var container = fixture('auto-validate-numbers');
          var input = Polymer.dom(container).querySelector('#i');
          var inputContent = Polymer.dom(container.root).querySelector('.input-content');
          var line = Polymer.dom(container.root).querySelector('.underline');
  
          input.bindValue = 'foobar';
  
          assert.isTrue(container.invalid, 'invalid is true');
          assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
          assert.isTrue(line.classList.contains('is-invalid'), 'underline has invalid styling when input is invalid');
        });
  
        test('styled when the input is set to an invalid value with auto-validate, with validator', function() {
          var container = fixture('auto-validate-validator');
          var input = Polymer.dom(container).querySelector('#i');
          var inputContent = Polymer.dom(container.root).querySelector('.input-content');
          var line = Polymer.dom(container.root).querySelector('.underline');
  
          input.bindValue = '123123';
  
          assert.isTrue(container.invalid, 'invalid is true');
          assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
          assert.isTrue(line.classList.contains('is-invalid'), 'underline has invalid styling when input is invalid');
        });
  
        test('styled when the input is set initially to an invalid value with auto-validate, with validator', function() {
          var container = fixture('auto-validate-validator-has-invalid-value');
          assert.isTrue(container.invalid, 'invalid is true');
          assert.isTrue(Polymer.dom(container.root).querySelector('.underline').classList.contains('is-invalid'), 'underline has is-invalid class');
        });
  
        test('styled when the input is set to an invalid value with manual validation', function() {
          var container = fixture('manual-validate-numbers');
          var input = Polymer.dom(container).querySelector('#i');
          var inputContent = Polymer.dom(container.root).querySelector('.input-content');
          var line = Polymer.dom(container.root).querySelector('.underline');
  
          input.bindValue = 'foobar';
          input.validate();
  
          assert.isTrue(container.invalid, 'invalid is true');
          assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
          assert.isTrue(line.classList.contains('is-invalid'), 'underline has invalid styling when input is invalid');
        });
  
      });
  
    </script>
  
  </body>
  </html>