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>iron-input 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.html"> |
| 26 <link rel="import" href="letters-only.html"> |
| 27 |
| 28 </head> |
| 29 <body> |
| 30 |
| 31 <test-fixture id="basic"> |
| 32 <template> |
| 33 <input is="iron-input"> |
| 34 </template> |
| 35 </test-fixture> |
| 36 |
| 37 <test-fixture id="has-value"> |
| 38 <template> |
| 39 <input is="iron-input" value="foobar"> |
| 40 </template> |
| 41 </test-fixture> |
| 42 |
| 43 <test-fixture id="has-bind-value"> |
| 44 <template> |
| 45 <input is="iron-input" bind-value="foobar"> |
| 46 </template> |
| 47 </test-fixture> |
| 48 |
| 49 <test-fixture id="prevent-invalid-input"> |
| 50 <template> |
| 51 <input is="iron-input" prevent-invalid-input pattern="[0-9]"> |
| 52 </template> |
| 53 </test-fixture> |
| 54 |
| 55 <test-fixture id="prevent-invalid-input-has-value"> |
| 56 <template> |
| 57 <input is="iron-input" prevent-invalid-input pattern="[0-9]*" value="fooba
r"> |
| 58 </template> |
| 59 </test-fixture> |
| 60 |
| 61 <test-fixture id="prevent-invalid-input-has-bind-value"> |
| 62 <template> |
| 63 <input is="iron-input" prevent-invalid-input pattern="[0-9]*" bind-value="
foobar"> |
| 64 </template> |
| 65 </test-fixture> |
| 66 |
| 67 <test-fixture id="has-validator"> |
| 68 <template> |
| 69 <letters-only></letters-only> |
| 70 <input is="iron-input" validator="letters-only" pattern="[0-9]*"> |
| 71 </template> |
| 72 </test-fixture> |
| 73 |
| 74 <template is="dom-bind" id="bind-to-object"> |
| 75 <input is="iron-input" id="input" bind-value="{{foo}}"> |
| 76 </template> |
| 77 |
| 78 <script> |
| 79 |
| 80 suite('basic', function() { |
| 81 |
| 82 test('setting bindValue sets value', function() { |
| 83 var input = fixture('basic'); |
| 84 input.bindValue = 'foobar'; |
| 85 assert.equal(input.value, input.bindValue, 'value equals to bindValue'); |
| 86 }); |
| 87 |
| 88 test('changing the input triggers an event', function(done) { |
| 89 var input = fixture('basic'); |
| 90 |
| 91 input.addEventListener('bind-value-changed', function(value) { |
| 92 assert.equal(input.value, input.bindValue, 'value equals to bindValue'
); |
| 93 done(); |
| 94 }); |
| 95 |
| 96 input.value = "foo"; |
| 97 input._onInput(); |
| 98 }); |
| 99 |
| 100 test('default value sets bindValue', function() { |
| 101 var input = fixture('has-value'); |
| 102 assert.equal(input.bindValue, input.value, 'bindValue equals value'); |
| 103 }); |
| 104 |
| 105 test('default bindValue sets value', function() { |
| 106 var input = fixture('has-bind-value'); |
| 107 assert.equal(input.value, input.bindValue, 'value equals to bindValue'); |
| 108 }); |
| 109 |
| 110 test('set bindValue to undefined', function() { |
| 111 var scope = document.getElementById('bind-to-object'); |
| 112 scope.foo = undefined; |
| 113 assert.ok(!scope.$.input.bindValue, 'bindValue is falsy'); |
| 114 assert.ok(!scope.$.input.value, 'value is falsy'); |
| 115 }); |
| 116 |
| 117 test('validator used instead of constraints api if provided', function() { |
| 118 var input = fixture('has-validator')[1]; |
| 119 input.value = '123'; |
| 120 input.validate(); |
| 121 assert.isTrue(input.invalid, 'input is invalid'); |
| 122 }); |
| 123 |
| 124 test('prevent invalid input works in _onInput', function() { |
| 125 var input = fixture('prevent-invalid-input'); |
| 126 input.value = '123'; |
| 127 input._onInput(); |
| 128 assert.equal(input.bindValue, '123'); |
| 129 |
| 130 input.value = '123foo'; |
| 131 input._onInput(); |
| 132 assert.equal(input.bindValue, '123'); |
| 133 }); |
| 134 }); |
| 135 |
| 136 </script> |
| 137 |
| 138 </body> |
| 139 </html> |
OLD | NEW |