| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 suite('cr-scrollable-behavior', function() { |
| 6 /** @type {CrScrollableListElement} */ var testElement; |
| 7 /** @type {HTMLDivElement} */ var container; |
| 8 /** @type {IronListElement} */ var ironList; |
| 9 |
| 10 suiteSetup(function() { |
| 11 document.body.innerHTML = ` |
| 12 <dom-module is="test-element"> |
| 13 <template> |
| 14 <style> |
| 15 #container { |
| 16 height: 30px; |
| 17 overflow-y: auto; |
| 18 } |
| 19 </style> |
| 20 <div id="container" scrollable> |
| 21 <iron-list scroll-target="container" items=[[items]]> |
| 22 <template> |
| 23 <div>[[item]]</div> |
| 24 </template> |
| 25 </iron-list> |
| 26 </div> |
| 27 </template> |
| 28 </dom-module> |
| 29 `; |
| 30 |
| 31 Polymer({ |
| 32 is: 'test-element', |
| 33 |
| 34 properties: { |
| 35 items: { |
| 36 type: Array, |
| 37 value: function() { |
| 38 return ['apple', 'bannana', 'cucumber', 'doughnut']; |
| 39 }, |
| 40 }, |
| 41 }, |
| 42 |
| 43 behaviors: [CrScrollableBehavior], |
| 44 }); |
| 45 }); |
| 46 |
| 47 setup(function(done) { |
| 48 PolymerTest.clearBody(); |
| 49 |
| 50 testElement = document.createElement('test-element'); |
| 51 document.body.appendChild(testElement); |
| 52 container = testElement.$$('#container'); |
| 53 ironList = testElement.$$('iron-list'); |
| 54 |
| 55 // Wait for requestAnimationFrame for CrScrollableBehavior to set the |
| 56 // initial scrollable class properties. |
| 57 window.requestAnimationFrame(function() { |
| 58 done(); |
| 59 }); |
| 60 }); |
| 61 |
| 62 // There is no MockInteractions scroll event, and simlating a scroll is messy, |
| 63 // so instead scroll ironList and send a 'scroll' event to the container. |
| 64 function scrollToIndex(index) { |
| 65 ironList.scrollToIndex(index); |
| 66 container.dispatchEvent(new CustomEvent('scroll')); |
| 67 Polymer.dom.flush(); |
| 68 }; |
| 69 |
| 70 test('scroll', function() { |
| 71 assertTrue(container.classList.contains('can-scroll')); |
| 72 assertFalse(container.classList.contains('is-scrolled')); |
| 73 assertFalse(container.classList.contains('scrolled-to-bottom')); |
| 74 scrollToIndex(1); |
| 75 assertTrue(container.classList.contains('is-scrolled')); |
| 76 assertFalse(container.classList.contains('scrolled-to-bottom')); |
| 77 scrollToIndex(3); |
| 78 assertTrue(container.classList.contains('scrolled-to-bottom')); |
| 79 }); |
| 80 |
| 81 test('save scroll', function(done) { |
| 82 scrollToIndex(2); |
| 83 assertTrue(container.classList.contains('can-scroll')); |
| 84 assertTrue(container.classList.contains('is-scrolled')); |
| 85 var scrollTop = container.scrollTop; |
| 86 testElement.saveScroll(ironList); |
| 87 testElement.items = ['apple', 'bannana', 'cactus', 'cucumber', 'doughnut']; |
| 88 testElement.restoreScroll(ironList); |
| 89 Polymer.dom.flush(); |
| 90 Polymer.Base.async(function() { |
| 91 assertEquals(scrollTop, container.scrollTop); |
| 92 done(); |
| 93 }); |
| 94 }); |
| 95 }); |
| OLD | NEW |