Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: polymer_1.0.4/bower_components/paper-input/test/paper-input-container.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <!--
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 -->
10 <html>
11 <head>
12
13 <title>paper-input-container tests</title>
14
15 <meta charset="utf-8">
16 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
17 <meta name="viewport" content="width=device-width, minimum-scale=1.0, initia l-scale=1, user-scalable=yes">
18
19 <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
20
21 <script src="../../web-component-tester/browser.js"></script>
22 <script src="../../test-fixture/test-fixture-mocha.js"></script>
23
24 <link rel="import" href="../../test-fixture/test-fixture.html">
25 <link rel="import" href="../../iron-input/iron-input.html">
26 <link rel="import" href="../paper-input-container.html">
27 <link rel="import" href="letters-only.html">
28
29 </head>
30 <body>
31
32 <test-fixture id="basic">
33 <template>
34 <paper-input-container>
35 <label id="l">label</label>
36 <input id="i">
37 </paper-input-container>
38 </template>
39 </test-fixture>
40
41 <test-fixture id="has-value">
42 <template>
43 <paper-input-container>
44 <label id="l">label</label>
45 <input id="i" value="value">
46 </paper-input-container>
47 </template>
48 </test-fixture>
49
50 <test-fixture id="no-float-has-value">
51 <template>
52 <paper-input-container no-label-float>
53 <label id="l">label</label>
54 <input id="i" value="value">
55 </paper-input-container>
56 </template>
57 </test-fixture>
58
59 <test-fixture id="always-float">
60 <template>
61 <paper-input-container always-float-label>
62 <label id="l">label</label>
63 <input id="i" value="value">
64 </paper-input-container>
65 </template>
66 </test-fixture>
67
68 <test-fixture id="auto-validate-numbers">
69 <template>
70 <paper-input-container auto-validate>
71 <label id="l">label</label>
72 <input is="iron-input" id="i" pattern="[0-9]*">
73 </paper-input-container>
74 </template>
75 </test-fixture>
76
77 <test-fixture id="manual-validate-numbers">
78 <template>
79 <paper-input-container>
80 <label id="l">label</label>
81 <input is="iron-input" id="i" pattern="[0-9]*">
82 </paper-input-container>
83 </template>
84 </test-fixture>
85
86 <letters-only></letters-only>
87
88 <test-fixture id="auto-validate-validator">
89 <template>
90 <paper-input-container auto-validate>
91 <label id="l">label</label>
92 <input is="iron-input" id="i" pattern="[0-9]*" validator="letters-only">
93 </paper-input-container>
94 </template>
95 </test-fixture>
96
97 <test-fixture id="auto-validate-validator-has-invalid-value">
98 <template>
99 <paper-input-container auto-validate>
100 <label id="l">label</label>
101 <input is="iron-input" id="i" validator="letters-only" value="123123">
102 </paper-input-container>
103 </template>
104 </test-fixture>
105
106 <script>
107
108 function getTransform(node) {
109 var style = getComputedStyle(node);
110 return style.transform || style.webkitTransform;
111 }
112
113 suite('label position', function() {
114
115 test('label is visible by default', function() {
116 var container = fixture('basic');
117 assert.equal(getComputedStyle(container.querySelector('#l')).visibility, 'visible', 'label has visibility:visible');
118 });
119
120 test('label is floated if value is initialized to not null', function() {
121 var container = fixture('has-value');
122 assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'la bel has transform');
123 });
124
125 test('label is invisible if no-label-float and value is initialized to not null', function() {
126 var container = fixture('no-float-has-value');
127 assert.equal(getComputedStyle(container.querySelector('#l')).visibility, 'hidden', 'label has visibility:hidden');
128 });
129
130 test('label is floated if always-float-label is true', function() {
131 var container = fixture('always-float');
132 assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'la bel has transform');
133 })
134
135 });
136
137 suite('focused styling', function() {
138
139 test('label is colored when input is focused and has value', function(done ) {
140 var container = fixture('has-value');
141 var label = Polymer.dom(container).querySelector('#l');
142 var input = Polymer.dom(container).querySelector('#i');
143 var inputContent = Polymer.dom(container.root).querySelector('.input-con tent');
144 input.focus();
145 // 'focus' event isn't firing on windows ff for some reason when you cal l focus()
146 container._onFocus();
147 requestAnimationFrame(function() {
148 assert.equal(document.activeElement, input, 'input is focused');
149 assert.isTrue(container.focused, 'focused is true');
150 assert.isTrue(inputContent.classList.contains('label-is-highlighted'), 'label is highlighted when input has focus');
151 done();
152 });
153 });
154
155 test('label is not colored when input is focused and has null value', func tion(done) {
156 var container = fixture('basic');
157 var label = Polymer.dom(container).querySelector('#l');
158 var input = Polymer.dom(container).querySelector('#i');
159 var inputContent = Polymer.dom(container.root).querySelector('.input-con tent');
160 input.focus();
161 container._onFocus();
162 requestAnimationFrame(function() {
163 assert.isFalse(inputContent.classList.contains('label-is-highlighted') , 'label is not highlighted when input has focus and has null value');
164 done();
165 });
166 });
167
168 test('underline is colored when input is focused', function(done) {
169 var container = fixture('basic');
170 var input = Polymer.dom(container).querySelector('#i');
171 var line = Polymer.dom(container.root).querySelector('.underline');
172 assert.isFalse(line.classList.contains('is-highlighted'), 'line is not h ighlighted when input is not focused');
173 input.focus();
174 container._onFocus();
175 requestAnimationFrame(function() {
176 assert.equal(document.activeElement, input, 'input is focused');
177 assert.isTrue(line.classList.contains('is-highlighted'), 'line is high lighted when input is focused');
178 done();
179 });
180 });
181
182 });
183
184 suite('validation', function() {
185
186 test('styled when the input is set to an invalid value with auto-validate' , function() {
187 var container = fixture('auto-validate-numbers');
188 var input = Polymer.dom(container).querySelector('#i');
189 var inputContent = Polymer.dom(container.root).querySelector('.input-con tent');
190 var line = Polymer.dom(container.root).querySelector('.underline');
191
192 input.bindValue = 'foobar';
193
194 assert.isTrue(container.invalid, 'invalid is true');
195 assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
196 assert.isTrue(line.classList.contains('is-invalid'), 'underline has inva lid styling when input is invalid');
197 });
198
199 test('styled when the input is set to an invalid value with auto-validate, with validator', function() {
200 var container = fixture('auto-validate-validator');
201 var input = Polymer.dom(container).querySelector('#i');
202 var inputContent = Polymer.dom(container.root).querySelector('.input-con tent');
203 var line = Polymer.dom(container.root).querySelector('.underline');
204
205 input.bindValue = '123123';
206
207 assert.isTrue(container.invalid, 'invalid is true');
208 assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
209 assert.isTrue(line.classList.contains('is-invalid'), 'underline has inva lid styling when input is invalid');
210 });
211
212 test('styled when the input is set initially to an invalid value with auto -validate, with validator', function() {
213 var container = fixture('auto-validate-validator-has-invalid-value');
214 assert.isTrue(container.invalid, 'invalid is true');
215 assert.isTrue(Polymer.dom(container.root).querySelector('.underline').cl assList.contains('is-invalid'), 'underline has is-invalid class');
216 });
217
218 test('styled when the input is set to an invalid value with manual validat ion', function() {
219 var container = fixture('manual-validate-numbers');
220 var input = Polymer.dom(container).querySelector('#i');
221 var inputContent = Polymer.dom(container.root).querySelector('.input-con tent');
222 var line = Polymer.dom(container.root).querySelector('.underline');
223
224 input.bindValue = 'foobar';
225 input.validate();
226
227 assert.isTrue(container.invalid, 'invalid is true');
228 assert.isTrue(inputContent.classList.contains('is-invalid'), 'label has invalid styling when input is invalid');
229 assert.isTrue(line.classList.contains('is-invalid'), 'underline has inva lid styling when input is invalid');
230 });
231
232 });
233
234 </script>
235
236 </body>
237 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698