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 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
26
|
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
|
c5169e0e
Renato De Donato
a new hope
|
27
|
<link rel="import" href="../../test-fixture/test-fixture.html">
|
73bcce88
luigser
COMPONENTS
|
28
29
30
31
32
33
34
35
36
37
38
39
|
<link rel="import" href="../paper-input.html">
<link rel="import" href="letters-only.html">
</head>
<body>
<test-fixture id="basic">
<template>
<paper-input></paper-input>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
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
|
<test-fixture id="label">
<template>
<paper-input label="foo"></paper-input>
</template>
</test-fixture>
<test-fixture id="label-has-value">
<template>
<paper-input label="foo" value="bar"></paper-input>
</template>
</test-fixture>
<test-fixture id="error">
<template>
<paper-input auto-validate pattern="[0-9]*" value="foobar" error-message="error"></paper-input>
</template>
</test-fixture>
<test-fixture id="required">
<template>
<paper-input auto-validate required error-message="error"></paper-input>
</template>
</test-fixture>
<test-fixture id="required-no-auto-validate">
<template>
<paper-input required error-message="error"></paper-input>
</template>
</test-fixture>
|
c5169e0e
Renato De Donato
a new hope
|
70
|
|
73bcce88
luigser
COMPONENTS
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<test-fixture id="required-char-counter">
<template>
<paper-input auto-validate char-counter required error-message="error"></paper-input>
</template>
</test-fixture>
<test-fixture id="char-counter">
<template>
<paper-input char-counter value="foobar"></paper-input>
</template>
</test-fixture>
<test-fixture id="always-float-label">
<template>
<paper-input always-float-label label="foo"></paper-input>
</template>
</test-fixture>
<test-fixture id="placeholder">
<template>
<paper-input label="foo" placeholder="bar"></paper-input>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
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
|
<letters-only></letters-only>
<test-fixture id="validator">
<template>
<paper-input value="123123" validator="letters-only" auto-validate></paper-input>
</template>
</test-fixture>
<script>
suite('basic', function() {
test('setting value sets the input value', function() {
var input = fixture('basic');
input.value = 'foobar';
assert.equal(input.inputElement.value, input.value, 'inputElement.value equals input.value');
});
test('placeholder does not overlap label', function() {
var input = fixture('placeholder');
assert.equal(input.inputElement.placeholder, input.placeholder, 'inputElement.placeholder equals input.placeholder');
assert.equal(input.noLabelFloat, false);
var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
assert.ok(floatingLabel);
});
|
73bcce88
luigser
COMPONENTS
|
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
|
test('always-float-label attribute works without placeholder', function() {
var input = fixture('always-float-label');
var container = Polymer.dom(input.root).querySelector('paper-input-container');
var inputContent = Polymer.dom(container.root).querySelector('.input-content');
assert.isTrue(inputContent.classList.contains('label-is-floating'), 'label is floating');
});
test('error message is displayed', function() {
var input = fixture('error');
forceXIfStamp(input);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
});
test('empty required input shows error', function() {
var input = fixture('required');
forceXIfStamp(input);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
});
test('character counter is displayed', function() {
var input = fixture('char-counter');
forceXIfStamp(input);
var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter')
assert.ok(counter, 'paper-input-char-counter exists');
assert.equal(counter._charCounterStr, input.value.length, 'character counter shows the value length');
});
test('validator is used', function() {
var input = fixture('validator');
assert.ok(input.inputElement.invalid, 'input is invalid');
});
test('caret position is preserved', function() {
var input = fixture('basic');
var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-input"]');
input.value = 'nananana';
ironInput.selectionStart = 2;
ironInput.selectionEnd = 2;
input.updateValueAndPreserveCaret('nanananabatman');
assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved');
assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved');
});
});
suite('focus/blur events', function() {
var input;
setup(function() {
input = fixture('basic');
});
|
e619a3b0
Luigi Serra
Controllet cross ...
|
179
|
test('focus/blur events fired on host element', function() {
|
73bcce88
luigser
COMPONENTS
|
180
181
|
var nFocusEvents = 0;
var nBlurEvents = 0;
|
e619a3b0
Luigi Serra
Controllet cross ...
|
182
|
input.addEventListener('focus', function(event) {
|
73bcce88
luigser
COMPONENTS
|
183
|
nFocusEvents += 1;
|
e619a3b0
Luigi Serra
Controllet cross ...
|
184
185
|
assert(input.focused, 'input is focused');
MockInteractions.blur(input.inputElement);
|
73bcce88
luigser
COMPONENTS
|
186
187
188
|
});
input.addEventListener('blur', function() {
nBlurEvents += 1;
|
e619a3b0
Luigi Serra
Controllet cross ...
|
189
|
assert(!input.focused, 'input is blurred');
|
73bcce88
luigser
COMPONENTS
|
190
191
|
});
MockInteractions.focus(input.inputElement);
|
e619a3b0
Luigi Serra
Controllet cross ...
|
192
193
|
assert.isTrue(nFocusEvents >= 1, 'focus event fired');
assert.isTrue(nBlurEvents >= 1, 'blur event fired');
|
73bcce88
luigser
COMPONENTS
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
});
});
suite('focused styling (integration test)', function() {
test('underline is colored when input is focused', function(done) {
var input = fixture('basic');
var container = Polymer.dom(input.root).querySelector('paper-input-container');
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.inputElement);
requestAnimationFrame(function() {
assert.isTrue(line.classList.contains('is-highlighted'), 'line is highlighted when input is focused');
done();
});
});
});
|
c5169e0e
Renato De Donato
a new hope
|
214
|
|
73bcce88
luigser
COMPONENTS
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
suite('validation', function() {
test('invalid attribute updated after calling validate()', function() {
var input = fixture('required-no-auto-validate');
forceXIfStamp(input);
input.validate();
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
assert.isTrue(input.invalid, 'invalid is true');
});
});
suite('a11y', function() {
test('has aria-labelledby', function() {
var input = fixture('label');
assert.isTrue(input.inputElement.hasAttribute('aria-labelledby'))
assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label');
});
test('has aria-describedby for error message', function() {
var input = fixture('required');
forceXIfStamp(input);
assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id, 'aria-describedby points to the error message');
});
test('has aria-describedby for character counter', function() {
var input = fixture('char-counter');
forceXIfStamp(input);
assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the character counter');
});
test('has aria-describedby for character counter and error', function() {
var input = fixture('required-char-counter');
forceXIfStamp(input);
assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id + ' ' + Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the error message and character counter');
});
|
73bcce88
luigser
COMPONENTS
|
258
259
260
261
262
263
|
});
</script>
</body>
</html>
|