<!doctype html> <!– @license Copyright © 2015 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at polymer.github.io/LICENSE.txt The complete set of authors may be found at polymer.github.io/AUTHORS.txt The complete set of contributors may be found at polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at polymer.github.io/PATENTS.txt –> <html> <head>

<title>paper-input-counter tests</title>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">

<script src="../../webcomponentsjs/webcomponents-lite.js"></script>

<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>

<link rel="import" href="../../iron-input/iron-input.html">
<link rel="import" href="../paper-input-container.html">
<link rel="import" href="../paper-input-char-counter.html">
<link rel="import" href="../paper-textarea.html">

</head> <body>

<test-fixture id="counter">
  <template>
    <paper-input-container>
      <label id="l">label</label>
      <input id="i" value="foobar">
      <paper-input-char-counter id="c"></paper-input-char-counter>
    </paper-input-container>
  </template>
</test-fixture>

<test-fixture id="counter-with-max">
  <template>
    <paper-input-container>
      <label id="l">label</label>
      <input id="i" value="foobar" maxlength="10">
      <paper-input-char-counter id="c"></paper-input-char-counter>
    </paper-input-container>
  </template>
</test-fixture>

<test-fixture id="textarea">
  <template>
    <paper-textarea char-counter value="foobar"></paper-textarea>
  </template>
</test-fixture>

<test-fixture id="textarea-with-max">
  <template>
    <paper-textarea char-counter value="foobar" maxlength="100"></paper-textarea>
  </template>
</test-fixture>

<script>

  suite('basic', function() {

    test('character counter shows the value length', function() {
      var container = fixture('counter');
      var input = Polymer.dom(container).querySelector('#i');
      var counter = Polymer.dom(container).querySelector('#c');
      assert.equal(counter._charCounterStr, input.value.length, 'character counter shows input value length');
    });

    test('character counter shows the value length with maxlength', function() {
      var container = fixture('counter-with-max');
      var input = Polymer.dom(container).querySelector('#i');
      var counter = Polymer.dom(container).querySelector('#c');
      assert.equal(counter._charCounterStr, input.value.length + '/' + input.maxLength, 'character counter shows input value length and maxLength');
    });

    test('character counter shows the value length with maxlength', function() {
      var input = fixture('textarea-with-max');
      forceXIfStamp(input);

      var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter');
      assert.ok(counter, 'paper-input-char-counter exists');

      assert.equal(counter._charCounterStr, input.value.length + '/' + input.inputElement.textarea.getAttribute('maxlength'), 'character counter shows input value length and maxLength');
    });

    test('character counter counts new lines in textareas correctly', function() {
      var input = fixture('textarea');
      input.value = 'foo\nbar';
      forceXIfStamp(input);

      var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter')
      assert.ok(counter, 'paper-input-char-counter exists');

      assert.equal(counter._charCounterStr, input.value.length, 'character counter shows the value length');
    });

  });

</script>

</body> </html>