OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 Copyright (c) 2014 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 <meta charset="UTF-8"> |
| 13 <title>paper-input-decorator tests</title> |
| 14 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
| 15 |
| 16 <script src="../../webcomponentsjs/webcomponents.js"></script> |
| 17 <script src="../../web-component-tester/browser.js"></script> |
| 18 <script src="../../polymer-gestures/test/js/fake.js"></script> |
| 19 |
| 20 <script src="util.js"></script> |
| 21 |
| 22 <link href="../../core-input/core-input.html" rel="import"> |
| 23 |
| 24 <link href="../paper-input-decorator.html" rel="import"> |
| 25 <link href="../paper-autogrow-textarea.html" rel="import"> |
| 26 |
| 27 <style> |
| 28 paper-input-decorator { |
| 29 width: 400px; |
| 30 } |
| 31 </style> |
| 32 |
| 33 </head> |
| 34 <body> |
| 35 |
| 36 <template id="default"> |
| 37 <paper-input-decorator label="label"> |
| 38 <input is="core-input"> |
| 39 </paper-input-decorator> |
| 40 <br> |
| 41 </template> |
| 42 |
| 43 <template id="floating-label"> |
| 44 <paper-input-decorator label="floating label" floatingLabel> |
| 45 <input is="core-input"> |
| 46 </paper-input-decorator> |
| 47 <br> |
| 48 </template> |
| 49 |
| 50 <template id="label-visible-false"> |
| 51 <paper-input-decorator label="labelVisible = false" labelVisible="false"> |
| 52 <input is="core-input"> |
| 53 </paper-input-decorator> |
| 54 <br> |
| 55 </template> |
| 56 |
| 57 <template id="floating-label-filled"> |
| 58 <paper-input-decorator label="input" floatingLabel> |
| 59 <input is="core-input" value="prefilled"> |
| 60 </paper-input-decorator> |
| 61 </template> |
| 62 |
| 63 <template id="no-input"> |
| 64 <paper-input-decorator label="no input"> |
| 65 </paper-input-decorator> |
| 66 <br> |
| 67 </template> |
| 68 |
| 69 <template id="error"> |
| 70 <paper-input-decorator label="input" floatingLabel isInvalid error="error me
ssage"> |
| 71 <input is="core-input" value="something"> |
| 72 </paper-input-decorator> |
| 73 <br> |
| 74 </template> |
| 75 |
| 76 <template id="auto-validate"> |
| 77 <paper-input-decorator autoValidate error="input is required"> |
| 78 <input is="core-input" required> |
| 79 </paper-input-decorator> |
| 80 <br> |
| 81 </template> |
| 82 |
| 83 <script> |
| 84 |
| 85 var fake = new Fake(); |
| 86 |
| 87 function cloneAndAppendTemplate(templateId) { |
| 88 var tmpl = document.getElementById(templateId); |
| 89 var frag = document.importNode(tmpl.content, true); |
| 90 var node = frag.children[0]; |
| 91 document.body.appendChild(frag); |
| 92 return { |
| 93 d: node, |
| 94 i: node.querySelector('input') |
| 95 }; |
| 96 } |
| 97 |
| 98 test('label is invisible if value is not null', function() { |
| 99 var nodes = cloneAndAppendTemplate('default'); |
| 100 nodes.i.value = 'foobar'; |
| 101 nodes.d.updateLabelVisibility(nodes.i.value); |
| 102 assert.ok(!nodes.d._labelVisible); |
| 103 }); |
| 104 |
| 105 test('label is invisible if floating label and focused', function(done) { |
| 106 var nodes = cloneAndAppendTemplate('floating-label'); |
| 107 async.series([ |
| 108 function(callback) { |
| 109 ensureFocus(nodes.i, callback); |
| 110 }, |
| 111 function(callback) { |
| 112 assert.ok(!nodes.d._labelVisible); |
| 113 callback(); |
| 114 } |
| 115 ], done); |
| 116 }); |
| 117 |
| 118 |
| 119 test('label is invisible if value = 0', function() { |
| 120 var nodes = cloneAndAppendTemplate('default'); |
| 121 nodes.i.value = 0; |
| 122 nodes.d.updateLabelVisibility(nodes.i.value); |
| 123 assert.ok(!nodes.d._labelVisible); |
| 124 }); |
| 125 |
| 126 test('labelVisible overrides label visibility', function() { |
| 127 var nodes = cloneAndAppendTemplate('default'); |
| 128 nodes.d.labelVisible = false; |
| 129 assert.ok(!nodes.i.value); |
| 130 assert.ok(!nodes.d._labelVisible); |
| 131 }); |
| 132 |
| 133 test('labelVisible works in an attribute', function() { |
| 134 var nodes = cloneAndAppendTemplate('label-visible-false'); |
| 135 assert.ok(!nodes.d._labelVisible); |
| 136 }); |
| 137 |
| 138 test('can create inputs lazily', function() { |
| 139 var nodes = cloneAndAppendTemplate('no-input'); |
| 140 var input = document.createElement('input'); |
| 141 input.value = 'foobar'; |
| 142 nodes.d.appendChild(input); |
| 143 assert.ok(!nodes.d._labelVisible); |
| 144 }); |
| 145 |
| 146 test('tapping on floating label focuses input', function(done) { |
| 147 var nodes = cloneAndAppendTemplate('floating-label-filled'); |
| 148 var floatedLabel = nodes.d.shadowRoot.querySelector('.floated-label'); |
| 149 fake.downOnNode(floatedLabel); |
| 150 fake.upOnNode(floatedLabel); |
| 151 waitFor(function() { |
| 152 assertNodeHasFocus(nodes.i); |
| 153 }, done); |
| 154 }); |
| 155 |
| 156 test('floating label and the error message are the same color', function(don
e) { |
| 157 var nodes = cloneAndAppendTemplate('error'); |
| 158 flush(function() { |
| 159 var s1 = getComputedStyle(nodes.d.$.floatedLabelText); |
| 160 var s2 = getComputedStyle(nodes.d.shadowRoot.querySelector('.error-text'
)); |
| 161 assert.strictEqual(s1.color, s2.color); |
| 162 done(); |
| 163 }); |
| 164 }); |
| 165 |
| 166 test('auto-validate input validates after creation', function() { |
| 167 var nodes = cloneAndAppendTemplate('auto-validate'); |
| 168 flush(function() { |
| 169 assert.ok(nodes.d.isInvalid); |
| 170 }); |
| 171 }); |
| 172 |
| 173 suite('a11y', function() { |
| 174 |
| 175 test('aria-label set on input', function() { |
| 176 var nodes = cloneAndAppendTemplate('default'); |
| 177 flush(function() { |
| 178 assert.strictEqual(nodes.i.getAttribute('aria-label'), nodes.d.label); |
| 179 }); |
| 180 }); |
| 181 |
| 182 }); |
| 183 |
| 184 </script> |
| 185 |
| 186 </body> |
| 187 </html> |
OLD | NEW |