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-email-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-email-input.html"> |
| 29 |
| 30 </head> |
| 31 <body> |
| 32 |
| 33 <test-fixture id="basic"> |
| 34 <template> |
| 35 <gold-email-input auto-validate required error-message="error"></gold-emai
l-input> |
| 36 </template> |
| 37 </test-fixture> |
| 38 |
| 39 <script> |
| 40 |
| 41 suite('basic', function() { |
| 42 test('invalid input shows error', function() { |
| 43 var input = fixture('basic'); |
| 44 input.value='1234'; |
| 45 forceXIfStamp(input); |
| 46 |
| 47 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 48 assert.ok(container, 'paper-input-container exists'); |
| 49 assert.isTrue(container.invalid); |
| 50 |
| 51 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 52 assert.ok(error, 'paper-input-error exists'); |
| 53 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 54 }); |
| 55 |
| 56 test('valid input does not show error', function() { |
| 57 var input = fixture('basic'); |
| 58 input.value='batman@gotham.org'; |
| 59 forceXIfStamp(input); |
| 60 |
| 61 var container = Polymer.dom(input.root).querySelector('paper-input-conta
iner'); |
| 62 assert.ok(container, 'paper-input-container exists'); |
| 63 assert.isFalse(container.invalid); |
| 64 |
| 65 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 66 assert.ok(error, 'paper-input-error exists'); |
| 67 assert.equal(getComputedStyle(error).display, 'none', 'error is display:
none'); |
| 68 }); |
| 69 |
| 70 test('empty required input shows error', function() { |
| 71 var input = fixture('basic'); |
| 72 forceXIfStamp(input); |
| 73 |
| 74 var error = Polymer.dom(input.root).querySelector('paper-input-error'); |
| 75 assert.ok(error, 'paper-input-error exists'); |
| 76 assert.notEqual(getComputedStyle(error).display, 'none', 'error is not d
isplay:none'); |
| 77 }); |
| 78 |
| 79 }); |
| 80 |
| 81 suite('a11y', function() { |
| 82 |
| 83 test('has aria-labelledby', function() { |
| 84 var input = fixture('basic'); |
| 85 assert.isTrue(input.inputElement.hasAttribute('aria-labelledby')) |
| 86 assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer
.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label
'); |
| 87 }); |
| 88 |
| 89 }); |
| 90 |
| 91 function testEmail(address, valid) { |
| 92 var input = fixture('basic'); |
| 93 forceXIfStamp(input); |
| 94 |
| 95 var container = Polymer.dom(input.root).querySelector('paper-input-contain
er'); |
| 96 assert.ok(container, 'paper-input-container exists'); |
| 97 |
| 98 input.value = address; |
| 99 var errorString = address + ' should be ' + (valid ? 'valid' : 'invalid'); |
| 100 assert.equal(container.invalid, !valid, errorString); |
| 101 } |
| 102 |
| 103 suite('valid email address validation', function() { |
| 104 |
| 105 test('valid email', function() { |
| 106 testEmail('email@domain.com', true); |
| 107 }); |
| 108 |
| 109 test('email with a dot in the address field', function() { |
| 110 testEmail('firstname.lastname@domain.com', true); |
| 111 }); |
| 112 |
| 113 test('email with a subdomain', function() { |
| 114 testEmail('email@subdomain.domain.com', true); |
| 115 }); |
| 116 |
| 117 test('weird tlds', function() { |
| 118 testEmail('testing+contact@subdomain.domain.pizza', true); |
| 119 }); |
| 120 |
| 121 test('plus sign is ok', function() { |
| 122 testEmail('firstname+lastname@domain.com', true); |
| 123 }); |
| 124 |
| 125 test('domain is valid ip', function() { |
| 126 testEmail('email@123.123.123.123', true); |
| 127 }); |
| 128 |
| 129 test('digits in address', function() { |
| 130 testEmail('1234567890@domain.com', true); |
| 131 }); |
| 132 |
| 133 test('dash in domain name', function() { |
| 134 testEmail('email@domain-one.com', true); |
| 135 }); |
| 136 |
| 137 test('dash in address field', function() { |
| 138 testEmail('firstname-lastname@domain.com', true); |
| 139 }); |
| 140 |
| 141 test('underscore in address field', function() { |
| 142 testEmail('_______@domain-one.com', true); |
| 143 }); |
| 144 |
| 145 test('dot in tld', function() { |
| 146 testEmail('email@domain.co.jp', true); |
| 147 }); |
| 148 }); |
| 149 |
| 150 suite('invalid email address validation', function() { |
| 151 test('missing @ and domain', function() { |
| 152 testEmail('plainaddress', false); |
| 153 }); |
| 154 |
| 155 test('missing @', function() { |
| 156 testEmail('email.domain.com', false); |
| 157 }); |
| 158 |
| 159 test('garbage', function() { |
| 160 testEmail('#@%^%#$@#$@#.com', false); |
| 161 }); |
| 162 |
| 163 test('missing username', function() { |
| 164 testEmail('@domain.com', false); |
| 165 }); |
| 166 |
| 167 test('has spaces', function() { |
| 168 testEmail('firstname lastname@domain.com', false); |
| 169 }); |
| 170 |
| 171 test('encoded html', function() { |
| 172 testEmail('Joe Smith <email@domain.com>', false); |
| 173 }); |
| 174 |
| 175 test('two @ signs', function() { |
| 176 testEmail('email@domain@domain.com', false); |
| 177 }); |
| 178 |
| 179 test('leading . in address', function() { |
| 180 testEmail('.email@domain.com', false); |
| 181 }); |
| 182 |
| 183 test('trailing . in address', function() { |
| 184 testEmail('email.@domain.com', false); |
| 185 }); |
| 186 |
| 187 test('multiple . in address', function() { |
| 188 testEmail('email..email@domain.com', false); |
| 189 }); |
| 190 |
| 191 test('unicode in address', function() { |
| 192 testEmail('あいうえお@domain.com', false); |
| 193 }); |
| 194 |
| 195 test('text after address', function() { |
| 196 testEmail('email@domain.com (Joe Smith)', false); |
| 197 }); |
| 198 |
| 199 test('missing tld', function() { |
| 200 testEmail('email@domain', false); |
| 201 }); |
| 202 |
| 203 test('leading dash in front of tld', function() { |
| 204 testEmail('email@-domain', false); |
| 205 }); |
| 206 |
| 207 test('multiple dots in domain', function() { |
| 208 testEmail('email@domain..com', false); |
| 209 }); |
| 210 |
| 211 }); |
| 212 |
| 213 </script> |
| 214 |
| 215 </body> |
| 216 </html> |
OLD | NEW |