| OLD | NEW |
| (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 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 <script src="../../iron-test-helpers/test-helpers.js"></script> |
| 25 |
| 26 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 27 <link rel="import" href="../paper-input.html"> |
| 28 <link rel="import" href="letters-only.html"> |
| 29 |
| 30 </head> |
| 31 <body> |
| 32 |
| 33 <test-fixture id="basic"> |
| 34 <template> |
| 35 <paper-input></paper-input> |
| 36 </template> |
| 37 </test-fixture> |
| 38 |
| 39 <test-fixture id="label"> |
| 40 <template> |
| 41 <paper-input label="foo"></paper-input> |
| 42 </template> |
| 43 </test-fixture> |
| 44 |
| 45 <test-fixture id="error"> |
| 46 <template> |
| 47 <paper-input auto-validate pattern="[0-9]*" value="foobar" error-message="
error"></paper-input> |
| 48 </template> |
| 49 </test-fixture> |
| 50 |
| 51 <test-fixture id="required"> |
| 52 <template> |
| 53 <paper-input auto-validate required error-message="error"></paper-input> |
| 54 </template> |
| 55 </test-fixture> |
| 56 |
| 57 <test-fixture id="required-no-auto-validate"> |
| 58 <template> |
| 59 <paper-input required error-message="error"></paper-input> |
| 60 </template> |
| 61 </test-fixture> |
| 62 |
| 63 |
| 64 <test-fixture id="required-char-counter"> |
| 65 <template> |
| 66 <paper-input auto-validate char-counter required error-message="error"></p
aper-input> |
| 67 </template> |
| 68 </test-fixture> |
| 69 |
| 70 <test-fixture id="char-counter"> |
| 71 <template> |
| 72 <paper-input char-counter value="foobar"></paper-input> |
| 73 </template> |
| 74 </test-fixture> |
| 75 |
| 76 <test-fixture id="always-float-label"> |
| 77 <template> |
| 78 <paper-input always-float-label label="foo"></paper-input> |
| 79 </template> |
| 80 </test-fixture> |
| 81 |
| 82 <test-fixture id="placeholder"> |
| 83 <template> |
| 84 <paper-input label="foo" placeholder="bar"></paper-input> |
| 85 </template> |
| 86 </test-fixture> |
| 87 |
| 88 <letters-only></letters-only> |
| 89 |
| 90 <test-fixture id="validator"> |
| 91 <template> |
| 92 <paper-input value="123123" validator="letters-only" auto-validate></paper
-input> |
| 93 </template> |
| 94 </test-fixture> |
| 95 |
| 96 <script> |
| 97 |
| 98 suite('basic', function() { |
| 99 |
| 100 test('setting value sets the input value', function() { |
| 101 var input = fixture('basic'); |
| 102 input.value = 'foobar'; |
| 103 assert.equal(input.inputElement.value, input.value, 'inputElement.value
equals input.value'); |
| 104 }); |
| 105 |
| 106 test('placeholder does not overlap label', function() { |
| 107 var input = fixture('placeholder'); |
| 108 assert.equal(input.inputElement.placeholder, input.placeholder, 'inputEl
ement.placeholder equals input.placeholder'); |
| 109 assert.equal(input.noLabelFloat, false); |
| 110 var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('p
aper-input-container').root).querySelector('.label-is-floating'); |
| 111 assert.ok(floatingLabel); |
| 112 }); |
| 113 |
| 114 test('always-float-label attribute works without placeholder', function()
{ |
| 115 var input = fixture('always-float-label'); |
| 116 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 117 var inputContent = Polymer.dom(container.root).querySelector('.input-con
tent'); |
| 118 assert.isTrue(inputContent.classList.contains('label-is-floating'), 'lab
el is floating'); |
| 119 }); |
| 120 |
| 121 test('error message is displayed', function() { |
| 122 var input = fixture('error'); |
| 123 forceXIfStamp(input); |
| 124 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 125 assert.ok(error, 'paper-input-error exists'); |
| 126 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 127 }); |
| 128 |
| 129 test('empty required input shows error', function() { |
| 130 var input = fixture('required'); |
| 131 forceXIfStamp(input); |
| 132 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 133 assert.ok(error, 'paper-input-error exists'); |
| 134 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 135 }); |
| 136 |
| 137 test('character counter is displayed', function() { |
| 138 var input = fixture('char-counter'); |
| 139 forceXIfStamp(input); |
| 140 var counter = Polymer.dom(input.root).querySelector('paper-input-char-co
unter') |
| 141 assert.ok(counter, 'paper-input-char-counter exists'); |
| 142 assert.equal(counter._charCounterStr, input.value.length, 'character cou
nter shows the value length'); |
| 143 }); |
| 144 |
| 145 test('validator is used', function() { |
| 146 var input = fixture('validator'); |
| 147 assert.ok(input.inputElement.invalid, 'input is invalid'); |
| 148 }); |
| 149 |
| 150 test('caret position is preserved', function() { |
| 151 var input = fixture('basic'); |
| 152 var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-in
put"]'); |
| 153 input.value = 'nananana'; |
| 154 ironInput.selectionStart = 2; |
| 155 ironInput.selectionEnd = 2; |
| 156 |
| 157 input.updateValueAndPreserveCaret('nanananabatman'); |
| 158 |
| 159 assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved')
; |
| 160 assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved'); |
| 161 }); |
| 162 |
| 163 }); |
| 164 |
| 165 suite('focus/blur events', function() { |
| 166 var input; |
| 167 |
| 168 setup(function() { |
| 169 input = fixture('basic'); |
| 170 }); |
| 171 |
| 172 test('focus/blur events fired on host element', function(done) { |
| 173 var nFocusEvents = 0; |
| 174 var nBlurEvents = 0; |
| 175 input.addEventListener('focus', function() { |
| 176 nFocusEvents += 1; |
| 177 // setTimeout to wait for potentially more, erroneous events |
| 178 setTimeout(function() { |
| 179 assert.equal(nFocusEvents, 1, 'one focus event fired'); |
| 180 input.inputElement.blur(); |
| 181 }); |
| 182 }); |
| 183 input.addEventListener('blur', function() { |
| 184 nBlurEvents += 1; |
| 185 // setTimeout to wait for potentially more, erroneous events |
| 186 setTimeout(function() { |
| 187 assert.equal(nBlurEvents, 1, 'one blur event fired'); |
| 188 done(); |
| 189 }); |
| 190 }); |
| 191 input.inputElement.focus(); |
| 192 }); |
| 193 |
| 194 }); |
| 195 |
| 196 suite('validation', function() { |
| 197 |
| 198 test('invalid attribute updated after calling validate()', function() { |
| 199 var input = fixture('required-no-auto-validate'); |
| 200 forceXIfStamp(input); |
| 201 input.validate(); |
| 202 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 203 assert.ok(error, 'paper-input-error exists'); |
| 204 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 205 assert.isTrue(input.invalid, 'invalid is true'); |
| 206 }); |
| 207 |
| 208 }); |
| 209 |
| 210 suite('a11y', function() { |
| 211 |
| 212 test('has aria-labelledby', function() { |
| 213 var input = fixture('label'); |
| 214 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 215 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer
.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label
'); |
| 216 }); |
| 217 |
| 218 test('has aria-describedby for error message', function() { |
| 219 var input = fixture('required'); |
| 220 forceXIfStamp(input); |
| 221 assert.isTrue(input.inputElement.hasAttribute('aria-describedby')); |
| 222 assert.equal(input.inputElement.getAttribute('aria-describedby'), Polyme
r.dom(input.root).querySelector('paper-input-error').id, 'aria-describedby point
s to the error message'); |
| 223 }); |
| 224 |
| 225 test('has aria-describedby for character counter', function() { |
| 226 var input = fixture('char-counter'); |
| 227 forceXIfStamp(input); |
| 228 assert.isTrue(input.inputElement.hasAttribute('aria-describedby')); |
| 229 assert.equal(input.inputElement.getAttribute('aria-describedby'), Polyme
r.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedb
y points to the character counter'); |
| 230 }); |
| 231 |
| 232 test('has aria-describedby for character counter and error', function() { |
| 233 var input = fixture('required-char-counter'); |
| 234 forceXIfStamp(input); |
| 235 assert.isTrue(input.inputElement.hasAttribute('aria-describedby')); |
| 236 assert.equal(input.inputElement.getAttribute('aria-describedby'), Polyme
r.dom(input.root).querySelector('paper-input-error').id + ' ' + Polymer.dom(inpu
t.root).querySelector('paper-input-char-counter').id, 'aria-describedby points t
o the error message and character counter'); |
| 237 }); |
| 238 |
| 239 }); |
| 240 |
| 241 </script> |
| 242 |
| 243 </body> |
| 244 </html> |
| OLD | NEW |