OLD | NEW |
(Empty) | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.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 |
| 17 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 18 <script src="../../web-component-tester/browser.js"></script> |
| 19 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 20 <script src="../../iron-test-helpers/mock-interactions.js"></script> |
| 21 |
| 22 <link rel="import" href="../iron-dropdown.html"> |
| 23 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 24 |
| 25 </head> |
| 26 <body> |
| 27 |
| 28 <test-fixture id="TrivialDropdown"> |
| 29 <template> |
| 30 <iron-dropdown> |
| 31 <div class="dropdown-content">Hello!</div> |
| 32 </iron-dropdown> |
| 33 </template> |
| 34 </test-fixture> |
| 35 |
| 36 <test-fixture id="AlignedDropdown"> |
| 37 <template> |
| 38 <div style="display: block; position: relative; width: 100px; height: 100p
x;"> |
| 39 <iron-dropdown horizontal-align="right" vertical-align="top"> |
| 40 <div class="dropdown-content">Hello!</div> |
| 41 </iron-dropdown> |
| 42 </div> |
| 43 </template> |
| 44 </test-fixture> |
| 45 |
| 46 <script> |
| 47 function elementIsVisible(element) { |
| 48 var contentRect = element.getBoundingClientRect(); |
| 49 var computedStyle = window.getComputedStyle(element); |
| 50 |
| 51 return computedStyle.display !== 'none' && |
| 52 contentRect.width > 0 && |
| 53 contentRect.height > 0; |
| 54 } |
| 55 |
| 56 suite('<iron-dropdown>', function() { |
| 57 var dropdown; |
| 58 suite('basic', function() { |
| 59 setup(function() { |
| 60 dropdown = fixture('TrivialDropdown'); |
| 61 }); |
| 62 |
| 63 test('effectively hides the dropdown content', function() { |
| 64 var content = dropdown.querySelector('.dropdown-content'); |
| 65 |
| 66 expect(elementIsVisible(content)).to.be.equal(false); |
| 67 }); |
| 68 |
| 69 test('shows dropdown content when opened', function(done) { |
| 70 var content = dropdown.querySelector('.dropdown-content'); |
| 71 |
| 72 dropdown.open(); |
| 73 |
| 74 Polymer.Base.async(function() { |
| 75 expect(elementIsVisible(content)).to.be.equal(true); |
| 76 done(); |
| 77 }); |
| 78 }); |
| 79 |
| 80 test('hides dropdown content when outside is clicked', function(done) { |
| 81 var content = dropdown.querySelector('.dropdown-content'); |
| 82 |
| 83 dropdown.open(); |
| 84 |
| 85 Polymer.Base.async(function() { |
| 86 expect(elementIsVisible(content)).to.be.equal(true); |
| 87 |
| 88 MockInteractions.downAndUp(document.body, function() { |
| 89 |
| 90 Polymer.Base.async(function() { |
| 91 expect(elementIsVisible(content)).to.be.equal(false); |
| 92 done(); |
| 93 }, 100); |
| 94 }); |
| 95 }); |
| 96 |
| 97 }); |
| 98 }); |
| 99 |
| 100 suite('aligned dropdown', function() { |
| 101 var parent; |
| 102 setup(function() { |
| 103 parent = fixture('AlignedDropdown'); |
| 104 dropdown = parent.querySelector('iron-dropdown'); |
| 105 }); |
| 106 |
| 107 test('can be re-aligned to the right and the top', function(done) { |
| 108 var parentRect; |
| 109 var dropdownRect; |
| 110 |
| 111 dropdown.opened = true; |
| 112 |
| 113 Polymer.Base.async(function() { |
| 114 dropdownRect = dropdown.getBoundingClientRect(); |
| 115 parentRect = parent.getBoundingClientRect(); |
| 116 |
| 117 // NOTE(cdata): IE10 / 11 have minor rounding errors in this case, |
| 118 // so we assert with `closeTo` and a tight threshold: |
| 119 expect(dropdownRect.top).to.be.closeTo(parentRect.top, 0.1); |
| 120 expect(dropdownRect.right).to.be.closeTo(parentRect.right, 0.1); |
| 121 done(); |
| 122 }, 1); |
| 123 }); |
| 124 |
| 125 test('can be re-aligned to the bottom', function(done) { |
| 126 var parentRect; |
| 127 var dropdownRect; |
| 128 |
| 129 dropdown.verticalAlign = 'bottom'; |
| 130 dropdown.opened = true; |
| 131 |
| 132 Polymer.Base.async(function() { |
| 133 parentRect = parent.getBoundingClientRect(); |
| 134 dropdownRect = dropdown.getBoundingClientRect(); |
| 135 |
| 136 // NOTE(cdata): IE10 / 11 have minor rounding errors in this case, |
| 137 // so we assert with `closeTo` and a tight threshold: |
| 138 expect(dropdownRect.bottom).to.be.closeTo(parentRect.bottom, 0.1); |
| 139 expect(dropdownRect.right).to.be.closeTo(parentRect.right, 0.1); |
| 140 done(); |
| 141 }, 1); |
| 142 }); |
| 143 |
| 144 }); |
| 145 }); |
| 146 </script> |
| 147 </body> |
| 148 </html> |
OLD | NEW |