OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 @license |
| 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 8 Code distributed by Google as part of the polymer project is also |
| 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 |
| 14 <title>gold-phone-input tests</title> |
| 15 |
| 16 <meta charset="utf-8"> |
| 17 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 18 <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-
scale=1, user-scalable=yes"> |
| 19 |
| 20 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 21 |
| 22 <script src="../../web-component-tester/browser.js"></script> |
| 23 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 24 |
| 25 <script src="../../iron-test-helpers/test-helpers.js"></script> |
| 26 |
| 27 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 28 <link rel="import" href="../gold-phone-input.html"> |
| 29 |
| 30 </head> |
| 31 <body> |
| 32 |
| 33 <test-fixture id="basic"> |
| 34 <template> |
| 35 <gold-phone-input></gold-phone-input> |
| 36 </template> |
| 37 </test-fixture> |
| 38 |
| 39 <test-fixture id="required"> |
| 40 <template> |
| 41 <gold-phone-input auto-validate required error-message="error"></gold-phon
e-input> |
| 42 </template> |
| 43 </test-fixture> |
| 44 |
| 45 <script> |
| 46 |
| 47 suite('basic', function() { |
| 48 test('input is spaced out correctly', function() { |
| 49 var input = fixture('basic'); |
| 50 input.value='1231112222'; |
| 51 assert.equal(input.value, '123-111-2222'); |
| 52 }); |
| 53 |
| 54 test('invalid input is not ok', function() { |
| 55 var input = fixture('required'); |
| 56 input.value='1234'; |
| 57 forceXIfStamp(input); |
| 58 |
| 59 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 60 assert.ok(container, 'paper-input-container exists'); |
| 61 assert.isTrue(container.invalid); |
| 62 }); |
| 63 |
| 64 test('valid input is ok', function() { |
| 65 var input = fixture('required'); |
| 66 input.value='1231112222'; |
| 67 forceXIfStamp(input); |
| 68 |
| 69 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 70 assert.ok(container, 'paper-input-container exists'); |
| 71 assert.isFalse(container.invalid); |
| 72 }); |
| 73 |
| 74 test('empty required input shows error', function() { |
| 75 var input = fixture('required'); |
| 76 forceXIfStamp(input); |
| 77 |
| 78 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 79 assert.ok(error, 'paper-input-error exists'); |
| 80 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 81 }); |
| 82 |
| 83 test('caret position is preserved', function() { |
| 84 var input = fixture('required'); |
| 85 var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-in
put"]'); |
| 86 input.value='111-111-1'; |
| 87 ironInput.selectionStart = 2; |
| 88 ironInput.selectionEnd = 2; |
| 89 input._computeValue('112-111-11'); |
| 90 |
| 91 assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved')
; |
| 92 assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved'); |
| 93 }); |
| 94 |
| 95 suite('a11y', function() { |
| 96 |
| 97 test('has aria-labelledby', function() { |
| 98 var input = fixture('basic'); |
| 99 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 100 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polym
er.dom(input.root).querySelector('label').id, 'aria-labelledby points to the lab
el'); |
| 101 }); |
| 102 |
| 103 test('required and error has aria-labelledby', function() { |
| 104 var input = fixture('required'); |
| 105 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 106 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polym
er.dom(input.root).querySelector('label').id, 'aria-labelledby points to the lab
el'); |
| 107 }); |
| 108 |
| 109 }); |
| 110 |
| 111 |
| 112 }); |
| 113 |
| 114 </script> |
| 115 |
| 116 </body> |
| 117 </html> |
OLD | NEW |