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 |
| 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS |
| 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS |
| 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 |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 <meta charset="UTF-8"> |
| 14 <title>iron-list test</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 |
| 21 <link rel="import" href="helpers.html"> |
| 22 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 23 <link rel="import" href="../iron-list.html"> |
| 24 </head> |
| 25 <body> |
| 26 |
| 27 <test-fixture id="trivialList"> |
| 28 <template> |
| 29 <template is="dom-bind"> |
| 30 <style> |
| 31 :host { |
| 32 @apply(--layout-fit); |
| 33 @apply(--layout-vertical); |
| 34 |
| 35 display: block; |
| 36 } |
| 37 |
| 38 iron-list { |
| 39 height: 300px; |
| 40 } |
| 41 |
| 42 .item:nth-child(odd) { |
| 43 height: 100px; |
| 44 background-color: green; |
| 45 color: white; |
| 46 } |
| 47 |
| 48 .item:nth-child(even) { |
| 49 height: 100px; |
| 50 background-color: red; |
| 51 color: white; |
| 52 } |
| 53 </style> |
| 54 <iron-list items="[[data]]" as="item"> |
| 55 <template> |
| 56 <div class="item">[[item.index]]</div> |
| 57 </template> |
| 58 </iron-list> |
| 59 </template> |
| 60 </template> |
| 61 </test-fixture> |
| 62 |
| 63 |
| 64 <script> |
| 65 |
| 66 suite('basic features', function() { |
| 67 var list, container; |
| 68 |
| 69 setup(function() { |
| 70 container = fixture('trivialList'); |
| 71 list = findElementInList(container, 'iron-list'); |
| 72 }); |
| 73 |
| 74 test('defaults', function() { |
| 75 assert.equal(list.items, null); |
| 76 assert.equal(list.as, 'item'); |
| 77 assert.equal(list.indexAs, 'index'); |
| 78 }); |
| 79 |
| 80 test('check items length', function(done) { |
| 81 container.data = buildDataSet(100); |
| 82 |
| 83 flush(function() { |
| 84 assert.equal(list.items.length, container.data.length); |
| 85 done(); |
| 86 }); |
| 87 }); |
| 88 |
| 89 test('check physical item heights', function(done) { |
| 90 container.data = buildDataSet(100); |
| 91 |
| 92 flush(function() { |
| 93 var rowHeight = list._physicalItems[0].offsetHeight; |
| 94 |
| 95 list._physicalItems.forEach(function(item) { |
| 96 assert.equal(item.offsetHeight, rowHeight); |
| 97 }); |
| 98 |
| 99 done(); |
| 100 }); |
| 101 }); |
| 102 |
| 103 test('check physical item size', function(done) { |
| 104 var setSize = list._physicalCount - 1; |
| 105 container.data = buildDataSet(setSize); |
| 106 |
| 107 flush(function() { |
| 108 assert.equal(list.items.length, setSize); |
| 109 done(); |
| 110 }); |
| 111 }); |
| 112 |
| 113 test('first visible index', function(done) { |
| 114 container.data = buildDataSet(100); |
| 115 |
| 116 flush(function() { |
| 117 var setSize = list.items.length; |
| 118 var rowHeight = list._physicalItems[0].offsetHeight; |
| 119 var viewportHeight = list.offsetHeight; |
| 120 var scrollToItem; |
| 121 |
| 122 function checkFirstVisible() { |
| 123 assert.equal(list.firstVisibleIndex, scrollToItem); |
| 124 assert.equal(getFirstItemFromList(list).textContent, scrollToItem); |
| 125 } |
| 126 |
| 127 function doneScrollDown() { |
| 128 checkFirstVisible(); |
| 129 |
| 130 scrollToItem = 1; |
| 131 |
| 132 flush(function() { |
| 133 simulateScroll({ |
| 134 list: list, |
| 135 contribution: rowHeight, |
| 136 target: scrollToItem*rowHeight |
| 137 }, doneScrollUp); |
| 138 }); |
| 139 } |
| 140 |
| 141 function doneScrollUp() { |
| 142 checkFirstVisible(); |
| 143 done(); |
| 144 } |
| 145 |
| 146 scrollToItem = 50; |
| 147 simulateScroll({ |
| 148 list: list, |
| 149 contribution: 50, |
| 150 target: scrollToItem*rowHeight |
| 151 }, doneScrollDown); |
| 152 |
| 153 }); |
| 154 }); |
| 155 |
| 156 test('scroll to index', function(done) { |
| 157 list.items = buildDataSet(100); |
| 158 |
| 159 flush(function() { |
| 160 list.scrollToIndex(30); |
| 161 assert.equal(list.firstVisibleIndex, 30); |
| 162 |
| 163 list.scrollToIndex(0); |
| 164 assert.equal(list.firstVisibleIndex, 0); |
| 165 |
| 166 var rowHeight = getFirstItemFromList(list).offsetHeight; |
| 167 var viewportHeight = list.offsetHeight; |
| 168 var itemsPerViewport = Math.floor(viewportHeight/rowHeight); |
| 169 |
| 170 list.scrollToIndex(99); |
| 171 assert.equal(list.firstVisibleIndex, list.items.length - itemsPerViewpor
t); |
| 172 |
| 173 // make the height of the viewport same as the height of the row |
| 174 // and scroll to the last item |
| 175 list.style.height = list._physicalItems[0].offsetHeight + 'px'; |
| 176 |
| 177 setTimeout(function() { |
| 178 list.scrollToIndex(99); |
| 179 assert.equal(list.firstVisibleIndex, 99); |
| 180 done(); |
| 181 }, 100); |
| 182 |
| 183 }); |
| 184 }); |
| 185 }); |
| 186 </script> |
| 187 |
| 188 </body> |
| 189 </html> |
OLD | NEW |