1<!doctype html> 2<!-- 3@license 4Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 8Code distributed by Google as part of the polymer project is also 9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 10--> 11 12<html> 13 <head> 14 15 <title>iron-collapse-flex</title> 16 <meta charset="utf-8"> 17 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 18 19 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> 20 <script src="../../web-component-tester/browser.js"></script> 21 <script src="../../test-fixture/test-fixture-mocha.js"></script> 22 23 <link rel="import" href="../../iron-flex-layout/iron-flex-layout-classes.html"> 24 <link rel="import" href="../../test-fixture/test-fixture.html"> 25 <link rel="import" href="../iron-collapse.html"> 26 27 <style is="custom-style" include="iron-flex"> 28 </style> 29 30 </head> 31 <body> 32 33 <test-fixture id="test"> 34 <template> 35 <div id="container" class="layout vertical" style="height: 200px"> 36 <iron-collapse id="collapse" opened style="flex: 1 0 auto"> 37 <div style="height:100px;"> 38 Lorem ipsum 39 </div> 40 </iron-collapse> 41 </div> 42 </template> 43 </test-fixture> 44 45 <script> 46 47 suite('flex', function() { 48 49 var container; 50 var collapse; 51 var collapseHeight; 52 53 setup(function() { 54 container = fixture('test'); 55 collapse = container.querySelector('iron-collapse'); 56 collapseHeight = getComputedStyle(collapse).height; 57 }); 58 59 test('default opened height', function() { 60 assert.equal(collapse.style.height, ''); 61 }); 62 63 test('set opened to false triggers animation', function(done) { 64 collapse.opened = false; 65 // Animation got enabled. 66 assert.notEqual(collapse.style.transitionDuration, '0s'); 67 collapse.addEventListener('transitionend', function() { 68 // Animation disabled. 69 assert.equal(collapse.style.transitionDuration, '0s'); 70 done(); 71 }); 72 }); 73 74 test('enableTransition(false) disables animations', function() { 75 collapse.enableTransition(false); 76 assert.isTrue(collapse.noAnimation, '`noAnimation` is true'); 77 // trying to animate the size update 78 collapse.updateSize('0px', true); 79 // Animation immediately disabled. 80 assert.equal(collapse.style.maxHeight, '0px'); 81 }); 82 83 test('set opened to false, then to true', function(done) { 84 // this listener will be triggered twice (every time `opened` changes) 85 collapse.addEventListener('transitionend', function() { 86 if (collapse.opened) { 87 // Check finalSize after animation is done. 88 assert.equal(collapse.style.maxHeight, ''); 89 done(); 90 } else { 91 // Check if size is still 0px. 92 assert.equal(collapse.style.maxHeight, '0px'); 93 // Trigger 2nd toggle. 94 collapse.opened = true; 95 // Size should be immediately set. 96 assert.equal(collapse.style.maxHeight, collapseHeight); 97 } 98 }); 99 // Trigger 1st toggle. 100 collapse.opened = false; 101 // Size should be immediately set. 102 assert.equal(collapse.style.maxHeight, '0px'); 103 }); 104 105 test('opened changes trigger iron-resize', function() { 106 var spy = sinon.stub(); 107 collapse.addEventListener('iron-resize', spy); 108 // No animations for faster test. 109 collapse.noAnimation = true; 110 collapse.opened = false; 111 assert.isTrue(spy.calledOnce, 'iron-resize was fired'); 112 }); 113 114 test('overflow is hidden while animating', function(done) { 115 collapse.addEventListener('transitionend', function() { 116 // Should still be hidden. 117 assert.equal(getComputedStyle(collapse).overflow, 'hidden'); 118 done(); 119 }); 120 assert.equal(getComputedStyle(collapse).overflow, 'visible'); 121 collapse.opened = false; 122 // Immediately updated style. 123 assert.equal(getComputedStyle(collapse).overflow, 'hidden'); 124 }); 125 126 test('toggle horizontal updates size', function() { 127 collapse.horizontal = false; 128 assert.equal(collapse.style.width, ''); 129 assert.equal(collapse.style.maxHeight, ''); 130 assert.equal(collapse.style.transitionProperty, 'max-height'); 131 132 collapse.horizontal = true; 133 assert.equal(collapse.style.maxWidth, ''); 134 assert.equal(collapse.style.height, ''); 135 assert.equal(collapse.style.transitionProperty, 'max-width'); 136 }); 137 138 test('change size with updateSize', function(done) { 139 collapse.addEventListener('transitionend', function() { 140 // size should be kept after transition 141 assert.equal(collapse.style.maxHeight, "123px"); 142 done(); 143 }); 144 collapse.updateSize("123px", true); 145 }); 146 147 }); 148 149 </script> 150 151 </body> 152</html> 153