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-container 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 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 25 <link rel="import" href="../../iron-input/iron-input.html"> |
| 26 <link rel="import" href="../paper-input-container.html"> |
| 27 |
| 28 </head> |
| 29 <body> |
| 30 |
| 31 <test-fixture id="basic"> |
| 32 <template> |
| 33 <paper-input-container> |
| 34 <label id="l">label</label> |
| 35 <input id="i"> |
| 36 </paper-input-container> |
| 37 </template> |
| 38 </test-fixture> |
| 39 |
| 40 <test-fixture id="has-value"> |
| 41 <template> |
| 42 <paper-input-container> |
| 43 <label id="l">label</label> |
| 44 <input id="i" value="value"> |
| 45 </paper-input-container> |
| 46 </template> |
| 47 </test-fixture> |
| 48 |
| 49 <test-fixture id="no-float-has-value"> |
| 50 <template> |
| 51 <paper-input-container no-label-float> |
| 52 <label id="l">label</label> |
| 53 <input id="i" value="value"> |
| 54 </paper-input-container> |
| 55 </template> |
| 56 </test-fixture> |
| 57 |
| 58 <test-fixture id="auto-validate-numbers"> |
| 59 <template> |
| 60 <paper-input-container auto-validate> |
| 61 <label id="l">label</label> |
| 62 <input is="iron-input" id="i" pattern="[0-9]*"> |
| 63 </paper-input-container> |
| 64 </template> |
| 65 </test-fixture> |
| 66 |
| 67 <script> |
| 68 |
| 69 function getTransform(node) { |
| 70 var style = getComputedStyle(node); |
| 71 return style.transform || style.webkitTransform; |
| 72 } |
| 73 |
| 74 suite('label position', function() { |
| 75 |
| 76 test('label is visible by default', function() { |
| 77 var container = fixture('basic'); |
| 78 assert.equal(getComputedStyle(container.querySelector('#l')).visibility,
'visible', 'label has visibility:visible'); |
| 79 }); |
| 80 |
| 81 test('label is floated if value is initialized to not null', function() { |
| 82 var container = fixture('has-value'); |
| 83 assert.notEqual(getTransform(container.querySelector('#l')), 'none', 'la
bel has transform'); |
| 84 }); |
| 85 |
| 86 test('label is invisible if no-label-float and value is initialized to not
null', function() { |
| 87 var container = fixture('no-float-has-value'); |
| 88 assert.equal(getComputedStyle(container.querySelector('#l')).visibility,
'hidden', 'label has visibility:hidden'); |
| 89 }); |
| 90 |
| 91 }); |
| 92 |
| 93 suite('focused styling', function() { |
| 94 |
| 95 test('label is colored when input is focused and has value', function() { |
| 96 var container = fixture('has-value'); |
| 97 var label = Polymer.dom(container).querySelector('#l'); |
| 98 var input = Polymer.dom(container).querySelector('#i'); |
| 99 var color = getComputedStyle(label).color; |
| 100 input.focus(); |
| 101 assert.equal(document.activeElement, input, 'input is focused'); |
| 102 assert.notEqual(getComputedStyle(label).color, color, 'label has differe
nt color when input has focus'); |
| 103 }); |
| 104 |
| 105 test('label is not colored when input is focused and has null value', func
tion() { |
| 106 var container = fixture('basic'); |
| 107 var label = Polymer.dom(container).querySelector('#l'); |
| 108 var input = Polymer.dom(container).querySelector('#i'); |
| 109 var color = getComputedStyle(label).color; |
| 110 input.focus(); |
| 111 assert.equal(document.activeElement, input, 'input is focused'); |
| 112 assert.equal(getComputedStyle(label).color, color, 'label has same color
when input has focus and has null value'); |
| 113 }); |
| 114 |
| 115 test('underline is colored when input is focused', function(done) { |
| 116 var container = fixture('basic'); |
| 117 var input = Polymer.dom(container).querySelector('#i'); |
| 118 var line = Polymer.dom(container.root).querySelector('.focused-line'); |
| 119 assert.notEqual(getTransform(line), 'none', 'line is not colored when in
put is not focused'); |
| 120 line.addEventListener('transitionend', function() { |
| 121 assert.equal(getTransform(line), 'none', 'line is colored when input i
s focused'); |
| 122 done(); |
| 123 }); |
| 124 input.focus(); |
| 125 assert.equal(document.activeElement, input, 'input is focused'); |
| 126 }); |
| 127 |
| 128 }); |
| 129 |
| 130 suite('validation', function() { |
| 131 |
| 132 test('styled when the input is set to an invalid value with auto-validate'
, function(done) { |
| 133 var container = fixture('auto-validate-numbers'); |
| 134 var input = Polymer.dom(container).querySelector('#i'); |
| 135 var label = Polymer.dom(container).querySelector('#l'); |
| 136 var line = Polymer.dom(container.root).querySelector('.focused-line'); |
| 137 var color = getComputedStyle(label).color; |
| 138 line.addEventListener('transitionend', function() { |
| 139 assert.notEqual(getComputedStyle(label).color, color, 'label is colore
d when input is invalid'); |
| 140 assert.equal(getTransform(line), 'none', 'line is colored when input i
s invalid'); |
| 141 done(); |
| 142 }); |
| 143 input.bindValue = 'foobar'; |
| 144 }); |
| 145 |
| 146 }); |
| 147 |
| 148 </script> |
| 149 |
| 150 </body> |
| 151 </html> |
OLD | NEW |