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 <script> |
| 64 |
| 65 suite('mutations to items', function() { |
| 66 var list, container; |
| 67 |
| 68 setup(function() { |
| 69 container = fixture('trivialList'); |
| 70 list = findElementInList(container, 'iron-list'); |
| 71 }); |
| 72 |
| 73 test('update physical item', function(done) { |
| 74 var setSize = 100; |
| 75 var phrase = 'It works!'; |
| 76 |
| 77 list.items = buildDataSet(setSize); |
| 78 |
| 79 list.set('items.0.index', phrase); |
| 80 |
| 81 flush(function() { |
| 82 assert.equal(getFirstItemFromList(list).textContent, phrase); |
| 83 done(); |
| 84 }); |
| 85 }); |
| 86 |
| 87 test('update virtual item', function(done) { |
| 88 var setSize = 100; |
| 89 var phrase = 'It works!'; |
| 90 |
| 91 list.items = buildDataSet(setSize); |
| 92 |
| 93 function scrollBackUp() { |
| 94 simulateScroll({ |
| 95 list: list, |
| 96 contribution: 100, |
| 97 target: 0 |
| 98 }, function() { |
| 99 flush(function() { |
| 100 assert.equal(getFirstItemFromList(list).textContent, phrase); |
| 101 done(); |
| 102 }); |
| 103 }); |
| 104 } |
| 105 |
| 106 flush(function() { |
| 107 var rowHeight = list._physicalItems[0].offsetHeight; |
| 108 // scroll down |
| 109 simulateScroll({ |
| 110 list: list, |
| 111 contribution: 100, |
| 112 target: setSize*rowHeight |
| 113 }, function() { |
| 114 list.set('items.0.index', phrase); |
| 115 flush(scrollBackUp); |
| 116 }); |
| 117 }); |
| 118 }); |
| 119 |
| 120 test('push', function(done) { |
| 121 var setSize = 100; |
| 122 |
| 123 list.items = buildDataSet(setSize); |
| 124 setSize = list.items.length; |
| 125 |
| 126 list.push('items', buildItem(setSize)); |
| 127 assert.equal(list.items.length, setSize + 1); |
| 128 |
| 129 flush(function() { |
| 130 var rowHeight = list._physicalItems[0].offsetHeight; |
| 131 var viewportHeight = list.offsetHeight; |
| 132 var itemsPerViewport = Math.floor(viewportHeight/rowHeight); |
| 133 |
| 134 assert.equal(getFirstItemFromList(list).textContent, 0); |
| 135 |
| 136 simulateScroll({ |
| 137 list: list, |
| 138 contribution: rowHeight, |
| 139 target: list.items.length*rowHeight |
| 140 }, function() { |
| 141 assert.equal(getFirstItemFromList(list).textContent, |
| 142 list.items.length - itemsPerViewport); |
| 143 done(); |
| 144 }); |
| 145 }) |
| 146 }); |
| 147 |
| 148 test('pop', function(done) { |
| 149 var setSize = 100; |
| 150 list.items = buildDataSet(setSize); |
| 151 |
| 152 flush(function() { |
| 153 var rowHeight = list._physicalItems[0].offsetHeight; |
| 154 |
| 155 simulateScroll({ |
| 156 list: list, |
| 157 contribution: rowHeight, |
| 158 target: setSize*rowHeight |
| 159 }, function() { |
| 160 var viewportHeight = list.offsetHeight; |
| 161 var itemsPerViewport = Math.floor(viewportHeight/rowHeight); |
| 162 |
| 163 list.pop('items'); |
| 164 |
| 165 flush(function() { |
| 166 assert.equal(list.items.length, setSize-1); |
| 167 assert.equal(getFirstItemFromList(list).textContent, setSize - 3 -
1); |
| 168 done(); |
| 169 }); |
| 170 }); |
| 171 }); |
| 172 }); |
| 173 |
| 174 test('splice', function(done) { |
| 175 var setSize = 45; |
| 176 var phrase = 'It works!' |
| 177 list.items = buildDataSet(setSize); |
| 178 |
| 179 list.splice('items', 0, setSize, buildItem(phrase)); |
| 180 |
| 181 flush(function() { |
| 182 assert.equal(list.items.length, 1); |
| 183 assert.equal(getFirstItemFromList(list).textContent, phrase); |
| 184 done(); |
| 185 }); |
| 186 }); |
| 187 }); |
| 188 </script> |
| 189 |
| 190 </body> |
| 191 </html> |
OLD | NEW |