OLD | NEW |
(Empty) | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 9 --> |
| 10 |
| 11 <html> |
| 12 <head> |
| 13 |
| 14 <title>iron-collapse-basic</title> |
| 15 <meta charset="utf-8"> |
| 16 <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 17 |
| 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 19 <script src="../../web-component-tester/browser.js"></script> |
| 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 21 |
| 22 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 23 <link rel="import" href="../iron-collapse.html"> |
| 24 |
| 25 </head> |
| 26 <body> |
| 27 |
| 28 <test-fixture id="test"> |
| 29 <template> |
| 30 <iron-collapse id="collapse" opened> |
| 31 <div style="height:100px;"> |
| 32 Lorem ipsum |
| 33 </div> |
| 34 </iron-collapse> |
| 35 </template> |
| 36 </test-fixture> |
| 37 |
| 38 <script> |
| 39 |
| 40 suite('basic', function() { |
| 41 |
| 42 var collapse; |
| 43 var collapseHeight; |
| 44 |
| 45 setup(function() { |
| 46 collapse = fixture('test'); |
| 47 collapseHeight = getComputedStyle(collapse).height; |
| 48 }); |
| 49 |
| 50 test('opened attribute', function() { |
| 51 assert.equal(collapse.opened, true); |
| 52 }); |
| 53 |
| 54 test('animated by default', function() { |
| 55 assert.isTrue(!collapse.noAnimation, '`noAnimation` is falsy'); |
| 56 }); |
| 57 |
| 58 test('horizontal attribute', function() { |
| 59 assert.equal(collapse.horizontal, false); |
| 60 }); |
| 61 |
| 62 test('default opened height', function() { |
| 63 assert.equal(collapse.style.height, 'auto'); |
| 64 }); |
| 65 |
| 66 test('set opened to false triggers animation', function(done) { |
| 67 collapse.opened = false; |
| 68 // Animation got enabled. |
| 69 assert.notEqual(collapse.style.transitionDuration, '0s'); |
| 70 collapse.addEventListener('transitionend', function() { |
| 71 // Animation disabled. |
| 72 assert.equal(collapse.style.transitionDuration, '0s'); |
| 73 done(); |
| 74 }); |
| 75 }); |
| 76 |
| 77 test('enableTransition(false) disables animations', function() { |
| 78 collapse.enableTransition(false); |
| 79 assert.isTrue(collapse.noAnimation, '`noAnimation` is true'); |
| 80 // trying to animate the size update |
| 81 collapse.updateSize('0px', true); |
| 82 // Animation immediately disabled. |
| 83 assert.equal(collapse.style.height, '0px'); |
| 84 }); |
| 85 |
| 86 test('set opened to false, then to true', function(done) { |
| 87 // this listener will be triggered twice (every time `opened` changes) |
| 88 collapse.addEventListener('transitionend', function() { |
| 89 if (collapse.opened) { |
| 90 // Check finalSize after animation is done. |
| 91 assert.equal(collapse.style.height, 'auto'); |
| 92 done(); |
| 93 } else { |
| 94 // Check if size is still 0px. |
| 95 assert.equal(collapse.style.height, '0px'); |
| 96 // Trigger 2nd toggle. |
| 97 collapse.opened = true; |
| 98 // Size should be immediately set. |
| 99 assert.equal(collapse.style.height, collapseHeight); |
| 100 } |
| 101 }); |
| 102 // Trigger 1st toggle. |
| 103 collapse.opened = false; |
| 104 // Size should be immediately set. |
| 105 assert.equal(collapse.style.height, '0px'); |
| 106 }); |
| 107 |
| 108 }); |
| 109 |
| 110 </script> |
| 111 |
| 112 </body> |
| 113 </html> |
OLD | NEW |