PageRenderTime 36ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Test04/www/bower_components/iron-dropdown/test/iron-dropdown.html

https://gitlab.com/hemantr/Test04
HTML | 387 lines | 315 code | 62 blank | 10 comment | 0 complexity | 071e987e60f7485fa5f5152af15c0800 MD5 | raw file
  1. <!doctype html>
  2. <!--
  3. @license
  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
  10. -->
  11. <html>
  12. <head>
  13. <meta charset="UTF-8">
  14. <title>iron-dropdown basic tests</title>
  15. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  16. <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  17. <script src="../../web-component-tester/browser.js"></script>
  18. <script src="../../test-fixture/test-fixture-mocha.js"></script>
  19. <script src="../../iron-test-helpers/mock-interactions.js"></script>
  20. <link rel="import" href="../iron-dropdown.html">
  21. <link rel="import" href="../../test-fixture/test-fixture.html">
  22. </head>
  23. <style>
  24. body {
  25. margin: 0;
  26. padding: 0;
  27. }
  28. </style>
  29. <body>
  30. <test-fixture id="TrivialDropdown">
  31. <template>
  32. <iron-dropdown>
  33. <div class="dropdown-content">Hello!</div>
  34. </iron-dropdown>
  35. </template>
  36. </test-fixture>
  37. <test-fixture id="NonLockingDropdown">
  38. <template>
  39. <iron-dropdown allow-outside-scroll>
  40. <div class="dropdown-content">I don't lock scroll!</div>
  41. </iron-dropdown>
  42. </template>
  43. </test-fixture>
  44. <test-fixture id="AlignedDropdown">
  45. <template>
  46. <div style="display: block; position: relative; width: 100px; height: 100px;">
  47. <iron-dropdown horizontal-align="right" vertical-align="top">
  48. <div class="dropdown-content">Hello!</div>
  49. </iron-dropdown>
  50. </div>
  51. </template>
  52. </test-fixture>
  53. <!-- Absolutely position the dropdown so that it has enough space to move around -->
  54. <test-fixture id="OffsetDropdownTopLeft">
  55. <template>
  56. <div style="display: block; position: absolute; top: 40px; left: 40px; width: 100px; height: 100px;">
  57. <iron-dropdown>
  58. <div class="dropdown-content">Hello!</div>
  59. </iron-dropdown>
  60. </div>
  61. </template>
  62. </test-fixture>
  63. <test-fixture id="OffsetDropdownBottomRight">
  64. <template>
  65. <div style="display: block; position: absolute; top: 40px; left: 40px; width: 100px; height: 100px;">
  66. <iron-dropdown horizontal-align="right" vertical-align="bottom">
  67. <div class="dropdown-content">Hello!</div>
  68. </iron-dropdown>
  69. </div>
  70. </template>
  71. </test-fixture>
  72. <test-fixture id="FocusableContentDropdown">
  73. <template>
  74. <iron-dropdown>
  75. <div class="dropdown-content" tabindex="0">
  76. <div class="subcontent" tabindex="0"></div>
  77. </div>
  78. </iron-dropdown>
  79. </template>
  80. </test-fixture>
  81. <test-fixture id="RTLDropdownLeft">
  82. <template>
  83. <div dir="rtl" style="display: block; position: relative; width: 100px; height: 100px;">
  84. <iron-dropdown>
  85. <div class="dropdown-content">Hello!</div>
  86. </iron-dropdown>
  87. </div>
  88. </template>
  89. </test-fixture>
  90. <test-fixture id="RTLDropdownRight">
  91. <template>
  92. <div dir="rtl" style="display: block; position: relative; width: 100px; height: 100px;">
  93. <iron-dropdown horizontal-align="right">
  94. <div class="dropdown-content">Hello!</div>
  95. </iron-dropdown>
  96. </div>
  97. </template>
  98. </test-fixture>
  99. <script>
  100. function elementIsVisible(element) {
  101. var contentRect = element.getBoundingClientRect();
  102. var computedStyle = window.getComputedStyle(element);
  103. return computedStyle.display !== 'none' &&
  104. contentRect.width > 0 &&
  105. contentRect.height > 0;
  106. }
  107. suite('<iron-dropdown>', function() {
  108. var dropdown;
  109. var content;
  110. suite('basic', function() {
  111. setup(function() {
  112. dropdown = fixture('TrivialDropdown');
  113. content = Polymer.dom(dropdown).querySelector('.dropdown-content');
  114. });
  115. test('effectively hides the dropdown content', function() {
  116. expect(elementIsVisible(content)).to.be.equal(false);
  117. });
  118. test('shows dropdown content when opened', function(done) {
  119. dropdown.open();
  120. Polymer.Base.async(function() {
  121. expect(elementIsVisible(content)).to.be.equal(true);
  122. done();
  123. });
  124. });
  125. test('hides dropdown content when outside is clicked', function(done) {
  126. dropdown.open();
  127. Polymer.Base.async(function() {
  128. expect(elementIsVisible(content)).to.be.equal(true);
  129. // The document capture-click listeners are set async.
  130. // Note(noms): I think this bit in iron-overlay-behavior is pretty
  131. // brittle, so if the tests start failing in the future, make sure
  132. // _toggleListeners is getting called at the right time.
  133. Polymer.Base.async(function() {
  134. MockInteractions.tap(dropdown.parentNode);
  135. Polymer.Base.async(function() {
  136. expect(elementIsVisible(content)).to.be.equal(false);
  137. done();
  138. }, 100);
  139. }, 1);
  140. });
  141. });
  142. suite('when content is focusable', function() {
  143. setup(function() {
  144. dropdown = fixture('FocusableContentDropdown');
  145. content = Polymer.dom(dropdown).querySelector('.dropdown-content');
  146. });
  147. test('focuses the content when opened', function(done) {
  148. dropdown.open();
  149. Polymer.Base.async(function() {
  150. expect(document.activeElement).to.be.equal(content);
  151. done();
  152. });
  153. });
  154. test('focuses a configured focus target', function(done) {
  155. var focusableChild = Polymer.dom(content).querySelector('div[tabindex]');
  156. dropdown.focusTarget = focusableChild;
  157. dropdown.open();
  158. Polymer.Base.async(function() {
  159. expect(document.activeElement).to.not.be.equal(content);
  160. expect(document.activeElement).to.be.equal(focusableChild);
  161. done();
  162. });
  163. });
  164. });
  165. });
  166. suite('locking scroll', function() {
  167. var dropdown;
  168. setup(function() {
  169. dropdown = fixture('NonLockingDropdown');
  170. });
  171. test('can be disabled with `allowOutsideScroll`', function(done) {
  172. dropdown.open();
  173. Polymer.Base.async(function() {
  174. expect(Polymer.IronDropdownScrollManager.elementIsScrollLocked(document.body))
  175. .to.be.equal(false);
  176. done();
  177. });
  178. });
  179. });
  180. suite('aligned dropdown', function() {
  181. var parent;
  182. setup(function() {
  183. parent = fixture('AlignedDropdown');
  184. dropdown = parent.querySelector('iron-dropdown');
  185. });
  186. test('can be re-aligned to the right and the top', function(done) {
  187. var parentRect;
  188. var dropdownRect;
  189. dropdown.opened = true;
  190. Polymer.Base.async(function() {
  191. dropdownRect = dropdown.getBoundingClientRect();
  192. parentRect = parent.getBoundingClientRect();
  193. // NOTE(cdata): IE10 / 11 have minor rounding errors in this case,
  194. // so we assert with `closeTo` and a tight threshold:
  195. expect(dropdownRect.top).to.be.closeTo(parentRect.top, 0.1);
  196. expect(dropdownRect.right).to.be.closeTo(parentRect.right, 0.1);
  197. done();
  198. }, 1);
  199. });
  200. test('can be re-aligned to the bottom', function(done) {
  201. var parentRect;
  202. var dropdownRect;
  203. dropdown.verticalAlign = 'bottom';
  204. dropdown.opened = true;
  205. Polymer.Base.async(function() {
  206. parentRect = parent.getBoundingClientRect();
  207. dropdownRect = dropdown.getBoundingClientRect();
  208. // NOTE(cdata): IE10 / 11 have minor rounding errors in this case,
  209. // so we assert with `closeTo` and a tight threshold:
  210. expect(dropdownRect.bottom).to.be.closeTo(parentRect.bottom, 0.1);
  211. expect(dropdownRect.right).to.be.closeTo(parentRect.right, 0.1);
  212. done();
  213. }, 1);
  214. });
  215. });
  216. suite('when align is left/top, with an offset', function() {
  217. var dropdownRect;
  218. var offsetDropdownRect;
  219. var dropdown;
  220. setup(function() {
  221. var parent = fixture('OffsetDropdownTopLeft');
  222. dropdown = parent.querySelector('iron-dropdown');
  223. });
  224. test('can be offset towards the bottom right', function(done) {
  225. dropdown.opened = true;
  226. Polymer.Base.async(function() {
  227. dropdownRect = dropdown.getBoundingClientRect();
  228. dropdown.verticalOffset = 10;
  229. dropdown.horizontalOffset = 10;
  230. offsetDropdownRect = dropdown.getBoundingClientRect();
  231. // verticalAlign is top, so a positive offset moves down.
  232. expect(dropdownRect.top + 10).to.be.closeTo(offsetDropdownRect.top, 0.1);
  233. // horizontalAlign is left, so a positive offset moves to the right.
  234. expect(dropdownRect.left + 10).to.be.closeTo(offsetDropdownRect.left, 0.1);
  235. done();
  236. }, 1);
  237. });
  238. test('can be offset towards the top left', function(done) {
  239. dropdown.opened = true;
  240. Polymer.Base.async(function() {
  241. dropdownRect = dropdown.getBoundingClientRect();
  242. dropdown.verticalOffset = -10;
  243. dropdown.horizontalOffset = -10;
  244. offsetDropdownRect = dropdown.getBoundingClientRect();
  245. // verticalAlign is top, so a negative offset moves up.
  246. expect(dropdownRect.top - 10).to.be.closeTo(offsetDropdownRect.top, 0.1);
  247. // horizontalAlign is left, so a negative offset moves to the left.
  248. expect(dropdownRect.left - 10).to.be.closeTo(offsetDropdownRect.left, 0.1);
  249. done();
  250. }, 1);
  251. });
  252. });
  253. suite('when align is right/bottom, with an offset', function() {
  254. var dropdownRect;
  255. var offsetDropdownRect;
  256. var dropdown;
  257. setup(function() {
  258. var parent = fixture('OffsetDropdownBottomRight');
  259. dropdown = parent.querySelector('iron-dropdown');
  260. });
  261. test('can be offset towards the top left', function(done) {
  262. dropdown.opened = true;
  263. Polymer.Base.async(function() {
  264. dropdownRect = dropdown.getBoundingClientRect();
  265. dropdown.verticalOffset = 10;
  266. dropdown.horizontalOffset = 10;
  267. offsetDropdownRect = dropdown.getBoundingClientRect();
  268. // verticalAlign is bottom, so a positive offset moves up.
  269. expect(dropdownRect.bottom - 10).to.be.closeTo(offsetDropdownRect.bottom, 0.1);
  270. // horizontalAlign is right, so a positive offset moves to the left.
  271. expect(dropdownRect.right - 10).to.be.closeTo(offsetDropdownRect.right, 0.1);
  272. done();
  273. }, 1);
  274. });
  275. test('can be offset towards the bottom right', function(done) {
  276. dropdown.opened = true;
  277. Polymer.Base.async(function() {
  278. dropdownRect = dropdown.getBoundingClientRect();
  279. dropdown.verticalOffset = -10;
  280. dropdown.horizontalOffset = -10;
  281. offsetDropdownRect = dropdown.getBoundingClientRect();
  282. // verticalAlign is bottom, so a negative offset moves down.
  283. expect(dropdownRect.bottom + 10).to.be.closeTo(offsetDropdownRect.bottom, 0.1);
  284. // horizontalAlign is right, so a positive offset moves to the right.
  285. expect(dropdownRect.right + 10).to.be.closeTo(offsetDropdownRect.right, 0.1);
  286. done();
  287. }, 1);
  288. });
  289. });
  290. suite('RTL', function() {
  291. var dropdown;
  292. var dropdownRect;
  293. test('with horizontalAlign=left', function(done) {
  294. var parent = fixture('RTLDropdownLeft');
  295. dropdown = parent.querySelector('iron-dropdown');
  296. dropdown.open();
  297. Polymer.Base.async(function() {
  298. // In RTL, if `horizontalAlign` is "left", that's the same as
  299. // being right-aligned in LTR. So the dropdown should be in the top
  300. // right corner.
  301. dropdownRect = dropdown.getBoundingClientRect();
  302. expect(dropdownRect.top).to.be.equal(0);
  303. expect(dropdownRect.right).to.be.equal(100);
  304. done();
  305. });
  306. });
  307. test('with horizontalAlign=right', function(done) {
  308. var parent = fixture('RTLDropdownRight');
  309. dropdown = parent.querySelector('iron-dropdown');
  310. dropdown.open();
  311. Polymer.Base.async(function() {
  312. // In RTL, if `horizontalAlign` is "right", that's the same as
  313. // being left-aligned in LTR. So the dropdown should be in the top
  314. // left corner.
  315. dropdownRect = dropdown.getBoundingClientRect();
  316. expect(dropdownRect.top).to.be.equal(0);
  317. expect(dropdownRect.left).to.be.equal(0);
  318. done();
  319. });
  320. });
  321. });
  322. });
  323. </script>
  324. </body>
  325. </html>