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.github.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/CONTRIBUTORS.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/PATENTS.txt
14
<title>paper-input-counter tests</title>
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">
20
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
22
<script src="../../web-component-tester/browser.js"></script>
23
<script src="../../iron-test-helpers/test-helpers.js"></script>
25
<link rel="import" href="../../iron-input/iron-input.html">
26
<link rel="import" href="../paper-input-container.html">
27
<link rel="import" href="../paper-input-char-counter.html">
28
<link rel="import" href="../paper-textarea.html">
33
<test-fixture id="counter">
35
<paper-input-container>
36
<label id="l">label</label>
37
<input id="i" value="foobar">
38
<paper-input-char-counter id="c"></paper-input-char-counter>
39
</paper-input-container>
43
<test-fixture id="counter-with-max">
45
<paper-input-container>
46
<label id="l">label</label>
47
<input id="i" value="foobar" maxlength="10">
48
<paper-input-char-counter id="c"></paper-input-char-counter>
49
</paper-input-container>
53
<test-fixture id="textarea">
55
<paper-textarea char-counter value="foobar"></paper-textarea>
59
<test-fixture id="textarea-with-max">
61
<paper-textarea char-counter value="foobar" maxlength="100"></paper-textarea>
67
suite('basic', function() {
69
test('character counter shows the value length', function() {
70
var container = fixture('counter');
71
var input = Polymer.dom(container).querySelector('#i');
72
var counter = Polymer.dom(container).querySelector('#c');
73
assert.equal(counter._charCounterStr, input.value.length, 'character counter shows input value length');
76
test('character counter shows the value length with maxlength', function() {
77
var container = fixture('counter-with-max');
78
var input = Polymer.dom(container).querySelector('#i');
79
var counter = Polymer.dom(container).querySelector('#c');
80
assert.equal(counter._charCounterStr, input.value.length + '/' + input.maxLength, 'character counter shows input value length and maxLength');
83
test('character counter shows the value length with maxlength', function() {
84
var input = fixture('textarea-with-max');
87
var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter');
88
assert.ok(counter, 'paper-input-char-counter exists');
90
assert.equal(counter._charCounterStr, input.value.length + '/' + input.inputElement.textarea.getAttribute('maxlength'), 'character counter shows input value length and maxLength');
93
test('character counter counts new lines in textareas correctly', function() {
94
var input = fixture('textarea');
95
input.value = 'foo\nbar';
98
var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter')
99
assert.ok(counter, 'paper-input-char-counter exists');
101
assert.equal(counter._charCounterStr, input.value.length, 'character counter shows the value length');