| 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-counter 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 <script src="../../iron-test-helpers/test-helpers.js"></script> |
| 25 |
| 26 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 27 <link rel="import" href="../../iron-input/iron-input.html"> |
| 28 <link rel="import" href="../paper-input-container.html"> |
| 29 <link rel="import" href="../paper-input-char-counter.html"> |
| 30 <link rel="import" href="../paper-textarea.html"> |
| 31 |
| 32 </head> |
| 33 <body> |
| 34 |
| 35 <test-fixture id="counter"> |
| 36 <template> |
| 37 <paper-input-container> |
| 38 <label id="l">label</label> |
| 39 <input id="i" value="foobar"> |
| 40 <paper-input-char-counter id="c"></paper-input-char-counter> |
| 41 </paper-input-container> |
| 42 </template> |
| 43 </test-fixture> |
| 44 |
| 45 <test-fixture id="counter-with-max"> |
| 46 <template> |
| 47 <paper-input-container> |
| 48 <label id="l">label</label> |
| 49 <input id="i" value="foobar" maxlength="10"> |
| 50 <paper-input-char-counter id="c"></paper-input-char-counter> |
| 51 </paper-input-container> |
| 52 </template> |
| 53 </test-fixture> |
| 54 |
| 55 <test-fixture id="textarea"> |
| 56 <template> |
| 57 <paper-textarea char-counter value="foobar"></paper-textarea> |
| 58 </template> |
| 59 </test-fixture> |
| 60 |
| 61 <test-fixture id="textarea-with-max"> |
| 62 <template> |
| 63 <paper-textarea char-counter value="foobar" maxlength="100"></paper-textar
ea> |
| 64 </template> |
| 65 </test-fixture> |
| 66 |
| 67 <script> |
| 68 |
| 69 suite('basic', function() { |
| 70 |
| 71 test('character counter shows the value length', function() { |
| 72 var container = fixture('counter'); |
| 73 var input = Polymer.dom(container).querySelector('#i'); |
| 74 var counter = Polymer.dom(container).querySelector('#c'); |
| 75 assert.equal(counter._charCounterStr, input.value.length, 'character cou
nter shows input value length'); |
| 76 }); |
| 77 |
| 78 test('character counter shows the value length with maxlength', function()
{ |
| 79 var container = fixture('counter-with-max'); |
| 80 var input = Polymer.dom(container).querySelector('#i'); |
| 81 var counter = Polymer.dom(container).querySelector('#c'); |
| 82 assert.equal(counter._charCounterStr, input.value.length + '/' + input.m
axLength, 'character counter shows input value length and maxLength'); |
| 83 }); |
| 84 |
| 85 test('character counter shows the value length with maxlength', function()
{ |
| 86 var input = fixture('textarea-with-max'); |
| 87 forceXIfStamp(input); |
| 88 |
| 89 var counter = Polymer.dom(input.root).querySelector('paper-input-char-co
unter'); |
| 90 assert.ok(counter, 'paper-input-char-counter exists'); |
| 91 |
| 92 assert.equal(counter._charCounterStr, input.value.length + '/' + input.i
nputElement.textarea.getAttribute('maxlength'), 'character counter shows input v
alue length and maxLength'); |
| 93 }); |
| 94 |
| 95 test('character counter counts new lines in textareas correctly', function
() { |
| 96 var input = fixture('textarea'); |
| 97 input.value = 'foo\nbar'; |
| 98 forceXIfStamp(input); |
| 99 |
| 100 var counter = Polymer.dom(input.root).querySelector('paper-input-char-co
unter') |
| 101 assert.ok(counter, 'paper-input-char-counter exists'); |
| 102 |
| 103 // A new line counts as two characters. |
| 104 assert.equal(counter._charCounterStr, input.value.length + 1, 'character
counter shows the value length'); |
| 105 }); |
| 106 |
| 107 }); |
| 108 |
| 109 </script> |
| 110 |
| 111 </body> |
| 112 </html> |
| OLD | NEW |