PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Test04/www/bower_components/paper-input/test/paper-input.html

https://gitlab.com/hemantr/Test04
HTML | 293 lines | 233 code | 52 blank | 8 comment | 0 complexity | 2308f5a5daa612777e5a4df534ec26db MD5 | raw file
  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.github.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/CONTRIBUTORS.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/PATENTS.txt
  9. -->
  10. <html>
  11. <head>
  12. <title>paper-input tests</title>
  13. <meta charset="utf-8">
  14. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  15. <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
  16. <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  17. <script src="../../web-component-tester/browser.js"></script>
  18. <script src="../../iron-test-helpers/test-helpers.js"></script>
  19. <script src="../../iron-test-helpers/mock-interactions.js"></script>
  20. <link rel="import" href="../paper-input.html">
  21. <link rel="import" href="letters-only.html">
  22. </head>
  23. <body>
  24. <test-fixture id="basic">
  25. <template>
  26. <paper-input></paper-input>
  27. </template>
  28. </test-fixture>
  29. <test-fixture id="has-tabindex">
  30. <template>
  31. <paper-input tabindex="0"></paper-input>
  32. </template>
  33. </test-fixture>
  34. <test-fixture id="label">
  35. <template>
  36. <paper-input label="foo"></paper-input>
  37. </template>
  38. </test-fixture>
  39. <test-fixture id="label-has-value">
  40. <template>
  41. <paper-input label="foo" value="bar"></paper-input>
  42. </template>
  43. </test-fixture>
  44. <test-fixture id="error">
  45. <template>
  46. <paper-input auto-validate pattern="[0-9]*" value="foobar" error-message="error"></paper-input>
  47. </template>
  48. </test-fixture>
  49. <test-fixture id="required">
  50. <template>
  51. <paper-input auto-validate required error-message="error"></paper-input>
  52. </template>
  53. </test-fixture>
  54. <test-fixture id="required-no-auto-validate">
  55. <template>
  56. <paper-input required error-message="error"></paper-input>
  57. </template>
  58. </test-fixture>
  59. <test-fixture id="required-char-counter">
  60. <template>
  61. <paper-input auto-validate char-counter required error-message="error"></paper-input>
  62. </template>
  63. </test-fixture>
  64. <test-fixture id="char-counter">
  65. <template>
  66. <paper-input char-counter value="foobar"></paper-input>
  67. </template>
  68. </test-fixture>
  69. <test-fixture id="always-float-label">
  70. <template>
  71. <paper-input always-float-label label="foo"></paper-input>
  72. </template>
  73. </test-fixture>
  74. <test-fixture id="placeholder">
  75. <template>
  76. <paper-input label="foo" placeholder="bar"></paper-input>
  77. </template>
  78. </test-fixture>
  79. <test-fixture id="date">
  80. <template>
  81. <paper-input label="foo" type="date"></paper-input>
  82. </template>
  83. </test-fixture>
  84. <letters-only></letters-only>
  85. <test-fixture id="validator">
  86. <template>
  87. <paper-input value="123123" validator="letters-only" auto-validate></paper-input>
  88. </template>
  89. </test-fixture>
  90. <script>
  91. suite('basic', function() {
  92. test('setting value sets the input value', function() {
  93. var input = fixture('basic');
  94. input.value = 'foobar';
  95. assert.equal(input.inputElement.value, input.value, 'inputElement.value equals input.value');
  96. });
  97. test('placeholder does not overlap label', function() {
  98. var input = fixture('placeholder');
  99. assert.equal(input.inputElement.placeholder, input.placeholder, 'inputElement.placeholder equals input.placeholder');
  100. assert.equal(input.noLabelFloat, false);
  101. var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
  102. assert.ok(floatingLabel);
  103. });
  104. test('special types autofloat the label', function() {
  105. var input = fixture('date');
  106. // Browsers that don't support special <input> types like `date` fallback
  107. // to `text`, so make sure to only test if type is still preserved after
  108. // the element is attached.
  109. if (input.inputElement.type === "date") {
  110. assert.equal(input.alwaysFloatLabel, true);
  111. var floatingLabel = Polymer.dom(Polymer.dom(input.root).querySelector('paper-input-container').root).querySelector('.label-is-floating');
  112. assert.ok(floatingLabel);
  113. }
  114. });
  115. test('always-float-label attribute works without placeholder', function() {
  116. var input = fixture('always-float-label');
  117. var container = Polymer.dom(input.root).querySelector('paper-input-container');
  118. var inputContent = Polymer.dom(container.root).querySelector('.input-content');
  119. assert.isTrue(inputContent.classList.contains('label-is-floating'), 'label is floating');
  120. });
  121. test('error message is displayed', function() {
  122. var input = fixture('error');
  123. forceXIfStamp(input);
  124. var error = Polymer.dom(input.root).querySelector('paper-input-error');
  125. assert.ok(error, 'paper-input-error exists');
  126. assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
  127. });
  128. test('empty required input shows error', function() {
  129. var input = fixture('required');
  130. forceXIfStamp(input);
  131. var error = Polymer.dom(input.root).querySelector('paper-input-error');
  132. assert.ok(error, 'paper-input-error exists');
  133. assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
  134. });
  135. test('character counter is displayed', function() {
  136. var input = fixture('char-counter');
  137. forceXIfStamp(input);
  138. var counter = Polymer.dom(input.root).querySelector('paper-input-char-counter')
  139. assert.ok(counter, 'paper-input-char-counter exists');
  140. assert.equal(counter._charCounterStr, input.value.length, 'character counter shows the value length');
  141. });
  142. test('validator is used', function() {
  143. var input = fixture('validator');
  144. assert.ok(input.inputElement.invalid, 'input is invalid');
  145. });
  146. test('caret position is preserved', function() {
  147. var input = fixture('basic');
  148. var ironInput = Polymer.dom(input.root).querySelector('input[is="iron-input"]');
  149. input.value = 'nananana';
  150. ironInput.selectionStart = 2;
  151. ironInput.selectionEnd = 2;
  152. input.updateValueAndPreserveCaret('nanananabatman');
  153. assert.equal(ironInput.selectionStart, 2, 'selectionStart is preserved');
  154. assert.equal(ironInput.selectionEnd, 2, 'selectionEnd is preserved');
  155. });
  156. });
  157. suite('focus/blur events', function() {
  158. var input;
  159. setup(function() {
  160. input = fixture('basic');
  161. });
  162. test('focus/blur events fired on host element', function() {
  163. var nFocusEvents = 0;
  164. var nBlurEvents = 0;
  165. input.addEventListener('focus', function(event) {
  166. nFocusEvents += 1;
  167. assert(input.focused, 'input is focused');
  168. MockInteractions.blur(input.inputElement);
  169. });
  170. input.addEventListener('blur', function() {
  171. nBlurEvents += 1;
  172. assert(!input.focused, 'input is blurred');
  173. });
  174. MockInteractions.focus(input.inputElement);
  175. assert.isTrue(nFocusEvents >= 1, 'focus event fired');
  176. assert.isTrue(nBlurEvents >= 1, 'blur event fired');
  177. });
  178. });
  179. suite('focused styling (integration test)', function() {
  180. test('underline is colored when input is focused', function(done) {
  181. var input = fixture('basic');
  182. var container = Polymer.dom(input.root).querySelector('paper-input-container');
  183. var line = Polymer.dom(container.root).querySelector('.underline');
  184. assert.isFalse(line.classList.contains('is-highlighted'), 'line is not highlighted when input is not focused');
  185. MockInteractions.focus(input.inputElement);
  186. requestAnimationFrame(function() {
  187. assert.isTrue(line.classList.contains('is-highlighted'), 'line is highlighted when input is focused');
  188. done();
  189. });
  190. });
  191. });
  192. suite('validation', function() {
  193. test('invalid attribute updated after calling validate()', function() {
  194. var input = fixture('required-no-auto-validate');
  195. forceXIfStamp(input);
  196. input.validate();
  197. var error = Polymer.dom(input.root).querySelector('paper-input-error');
  198. assert.ok(error, 'paper-input-error exists');
  199. assert.notEqual(getComputedStyle(error).display, 'none', 'error is not display:none');
  200. assert.isTrue(input.invalid, 'invalid is true');
  201. });
  202. });
  203. suite('a11y', function() {
  204. test('has aria-labelledby', function() {
  205. var input = fixture('label');
  206. assert.isTrue(input.inputElement.hasAttribute('aria-labelledby'))
  207. assert.equal(input.inputElement.getAttribute('aria-labelledby'), Polymer.dom(input.root).querySelector('label').id, 'aria-labelledby points to the label');
  208. });
  209. test('has aria-describedby for error message', function() {
  210. var input = fixture('required');
  211. forceXIfStamp(input);
  212. assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
  213. assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id, 'aria-describedby points to the error message');
  214. });
  215. test('has aria-describedby for character counter', function() {
  216. var input = fixture('char-counter');
  217. forceXIfStamp(input);
  218. assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
  219. assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the character counter');
  220. });
  221. test('has aria-describedby for character counter and error', function() {
  222. var input = fixture('required-char-counter');
  223. forceXIfStamp(input);
  224. assert.isTrue(input.inputElement.hasAttribute('aria-describedby'));
  225. assert.equal(input.inputElement.getAttribute('aria-describedby'), Polymer.dom(input.root).querySelector('paper-input-error').id + ' ' + Polymer.dom(input.root).querySelector('paper-input-char-counter').id, 'aria-describedby points to the error message and character counter');
  226. });
  227. test('focus an input with tabindex', function(done) {
  228. var input = fixture('has-tabindex');
  229. flush(function() {
  230. MockInteractions.focus(input);
  231. flush(function() {
  232. assert.equal(input.shadowRoot ? input.shadowRoot.activeElement :
  233. document.activeElement, input._focusableElement);
  234. done();
  235. });
  236. });
  237. });
  238. });
  239. </script>
  240. </body>
  241. </html>