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-cc-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-cc-input.html"> |
| 29 |
| 30 </head> |
| 31 <body> |
| 32 |
| 33 <test-fixture id="basic"> |
| 34 <template> |
| 35 <gold-cc-input></gold-cc-input> |
| 36 </template> |
| 37 </test-fixture> |
| 38 |
| 39 <test-fixture id="ErrorWithoutAutoValidate"> |
| 40 <template> |
| 41 <gold-cc-input required error-message="error"></gold-cc-input> |
| 42 </template> |
| 43 </test-fixture> |
| 44 |
| 45 <test-fixture id="required"> |
| 46 <template> |
| 47 <gold-cc-input auto-validate required error-message="error"></gold-cc-inpu
t> |
| 48 </template> |
| 49 </test-fixture> |
| 50 |
| 51 <script> |
| 52 |
| 53 suite('basic', function() { |
| 54 test('input is spaced out correctly', function() { |
| 55 var input = fixture('basic'); |
| 56 input.value='12345678'; |
| 57 assert.equal(input.value, '1234 5678'); |
| 58 }); |
| 59 |
| 60 test('invalid input is not ok', function() { |
| 61 var input = fixture('required'); |
| 62 input.value='1234'; |
| 63 forceXIfStamp(input); |
| 64 |
| 65 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 66 assert.ok(container, 'paper-input-container exists'); |
| 67 assert.isTrue(container.invalid); |
| 68 assert.equal(input.cardType, ''); |
| 69 }); |
| 70 |
| 71 test('valid input is ok', function() { |
| 72 var input = fixture('required'); |
| 73 input.value='4000000000000002'; |
| 74 forceXIfStamp(input); |
| 75 |
| 76 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 77 assert.ok(container, 'paper-input-container exists'); |
| 78 assert.isFalse(container.invalid); |
| 79 assert.equal(input.cardType, 'visa'); |
| 80 }); |
| 81 |
| 82 test('empty required input shows error', function() { |
| 83 var input = fixture('required'); |
| 84 forceXIfStamp(input); |
| 85 |
| 86 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 87 assert.ok(error, 'paper-input-error exists'); |
| 88 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 89 }); |
| 90 |
| 91 test('invalid input shows error message after manual validation', function
() { |
| 92 var input = fixture('ErrorWithoutAutoValidate'); |
| 93 forceXIfStamp(input); |
| 94 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 95 assert.ok(error, 'paper-input-error exists'); |
| 96 |
| 97 // The error message is only displayed after manual validation. |
| 98 assert.equal(getComputedStyle(error).display, 'none', 'error is not disp
lay:none'); |
| 99 input.validate(); |
| 100 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 101 }); |
| 102 |
| 103 test('caret position is preserved', function() { |
| 104 var input = fixture('required'); |
| 105 var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-in
put"]'); |
| 106 input.value='1111 1111'; |
| 107 ironInput.selectionStart = 2; |
| 108 ironInput.selectionEnd = 2; |
| 109 input._computeValue('1122 1111 11'); |
| 110 |
| 111 assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved')
; |
| 112 assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved'); |
| 113 }); |
| 114 |
| 115 }); |
| 116 |
| 117 suite('a11y', function() { |
| 118 |
| 119 test('has aria-labelledby', function() { |
| 120 var input = fixture('basic'); |
| 121 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 122 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer
.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label
'); |
| 123 }); |
| 124 |
| 125 test('required and error has aria-labelledby', function() { |
| 126 var input = fixture('required'); |
| 127 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 128 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer
.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label
'); |
| 129 }); |
| 130 |
| 131 }); |
| 132 |
| 133 </script> |
| 134 |
| 135 </body> |
| 136 </html> |
OLD | NEW |