Blame view

bower_components/iron-autogrow-textarea/test/basic.html 5.33 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  <!doctype html>
  <!--
  @license
  Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
  This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  The complete set of contributors may be found at http://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 http://polymer.github.io/PATENTS.txt
  -->
  <html>
    <head>
  
      <title>iron-autogrow-textarea 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>
c5169e0e   Renato De Donato   a new hope
23
      <script src="../../test-fixture/test-fixture-mocha.js"></script>
73bcce88   luigser   COMPONENTS
24
      <script src="../../iron-test-helpers/mock-interactions.js"></script>
c5169e0e   Renato De Donato   a new hope
25
26
  
      <link rel="import" href="../../test-fixture/test-fixture.html">
73bcce88   luigser   COMPONENTS
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      <link rel="import" href="../iron-autogrow-textarea.html">
  
    </head>
    <body>
  
      <test-fixture id="basic">
        <template>
          <iron-autogrow-textarea></iron-autogrow-textarea>
        </template>
      </test-fixture>
  
      <test-fixture id="has-bindValue">
        <template>
          <iron-autogrow-textarea bind-value="foobar"></iron-autogrow-textarea>
        </template>
      </test-fixture>
  
      <test-fixture id="rows">
        <template>
          <iron-autogrow-textarea rows="3"></iron-autogrow-textarea>
        </template>
      </test-fixture>
  
      <script>
  
        suite('basic', function() {
  
          test('setting bindValue sets textarea value', function() {
            var autogrow = fixture('basic');
            var textarea = autogrow.textarea;
  
            autogrow.bindValue = 'batman';
            assert.equal(textarea.value, autogrow.bindValue, 'textarea value equals to bindValue');
          });
  
          test('can set an initial bindValue', function() {
            var autogrow = fixture('has-bindValue');
            assert.equal(autogrow.textarea.value, 'foobar', 'textarea value equals to initial bindValue');
          });
  
          test('can set an initial number of rows', function() {
            var autogrow = fixture("rows");
            assert.equal(autogrow.textarea.rows, 3, 'textarea has rows=3');
          });
  
          test('adding rows grows the textarea', function() {
            var autogrow = fixture('basic');
            var initialHeight = autogrow.offsetHeight;
  
            autogrow.bindValue = 'batman\nand\nrobin';
            var finalHeight = autogrow.offsetHeight
            assert.isTrue(finalHeight > initialHeight);
          });
  
          test('removing rows shrinks the textarea', function() {
            var autogrow = fixture('basic');
            autogrow.bindValue = 'batman\nand\nrobin';
            var initialHeight = autogrow.offsetHeight;
  
            autogrow.bindValue = 'batman';
            var finalHeight = autogrow.offsetHeight
            assert.isTrue(finalHeight < initialHeight);
          });
e619a3b0   Luigi Serra   Controllet cross ...
90
  
eb240478   Luigi Serra   public room cards...
91
92
93
94
95
96
97
98
99
100
101
102
103
          test('an undefined bindValue is the empty string', function() {
            var autogrow = fixture('basic');
            var initialHeight = autogrow.offsetHeight;
  
            autogrow.bindValue = 'batman\nand\nrobin';
            var finalHeight = autogrow.offsetHeight;
            assert.isTrue(finalHeight > initialHeight);
  
            autogrow.bindValue = undefined;
            assert.equal(autogrow.offsetHeight, initialHeight);
            assert.equal(autogrow.textarea.value, '');
          });
  
e619a3b0   Luigi Serra   Controllet cross ...
104
105
106
107
108
109
110
111
112
113
114
          test('textarea selection works', function() {
            var autogrow = fixture('basic');
            var textarea = autogrow.textarea;
            autogrow.bindValue = 'batman\nand\nrobin';
  
            autogrow.selectionStart = 3;
            autogrow.selectionEnd = 5;
  
            assert.equal(textarea.selectionStart, 3);
            assert.equal(textarea.selectionEnd, 5);
          });
73bcce88   luigser   COMPONENTS
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        });
  
        suite('focus/blur events', function() {
          var input;
  
          setup(function() {
            input = fixture('basic');
          });
  
          test('focus/blur events fired on host element', function(done) {
            var nFocusEvents = 0;
            var nBlurEvents = 0;
            input.addEventListener('focus', function() {
              nFocusEvents += 1;
              // setTimeout to wait for potentially more, erroneous events
              setTimeout(function() {
                assert.equal(nFocusEvents, 1, 'one focus event fired');
                MockInteractions.blur(input.textarea);
              });
            });
            input.addEventListener('blur', function() {
              nBlurEvents += 1;
              // setTimeout to wait for potentially more, erroneous events
              setTimeout(function() {
                assert.equal(nBlurEvents, 1, 'one blur event fired');
                done();
              });
            });
            MockInteractions.focus(input.textarea);
          });
  
        });
  
        suite('validation', function() {
          test('a required textarea with no text is invalid', function() {
            var input = fixture('basic');
            input.required = true;
            assert.isFalse(input.validate());
  
            input.bindValue = 'batman';
            assert.isTrue(input.validate());
          });
        });
  
      </script>
  
    </body>
  </html>