| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 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 | 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 | 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 | 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 | 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 | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> | 9 --> |
| 10 | 10 |
| 11 <html> | 11 <html> |
| 12 <head> | 12 <head> |
| 13 | 13 |
| 14 <title>iron-selector-multi</title> | 14 <title>iron-selector-multi</title> |
| 15 <meta charset="utf-8"> | 15 <meta charset="utf-8"> |
| 16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> | 16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
| 17 | 17 |
| 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> | 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 19 <script src="../../web-component-tester/browser.js"></script> | 19 <script src="../../web-component-tester/browser.js"></script> |
| 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> | 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 21 | 21 |
| 22 <link rel="import" href="../../test-fixture/test-fixture.html"> | 22 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 23 <link rel="import" href="../../iron-test-helpers/iron-test-helpers.html"> |
| 23 <link rel="import" href="../iron-selector.html"> | 24 <link rel="import" href="../iron-selector.html"> |
| 24 | 25 |
| 25 <style> | 26 <style> |
| 26 .iron-selected { | 27 .iron-selected { |
| 27 background: #ccc; | 28 background: #ccc; |
| 28 } | 29 } |
| 29 </style> | 30 </style> |
| 30 | 31 |
| 31 </head> | 32 </head> |
| 32 <body> | 33 <body> |
| 33 | 34 |
| 34 <test-fixture id="test"> | 35 <test-fixture id="test"> |
| 35 <template> | 36 <template> |
| 36 <iron-selector multi> | 37 <iron-selector multi> |
| 37 <div>Item 0</div> | 38 <div>Item 0</div> |
| 38 <div>Item 1</div> | 39 <div>Item 1</div> |
| 39 <div>Item 2</div> | 40 <div>Item 2</div> |
| 40 <div>Item 3</div> | 41 <div>Item 3</div> |
| 41 <div>Item 4</div> | 42 <div>Item 4</div> |
| 42 </iron-selector> | 43 </iron-selector> |
| 43 </template> | 44 </template> |
| 44 </test-fixture> | 45 </test-fixture> |
| 45 | 46 |
| 47 <!-- |
| 48 NOTE(cdata): Enable test-fixture when polymer/polymer#2495 is resolved |
| 49 --> |
| 50 <!--<test-fixture id="repeatedItems"> |
| 51 <template>--> |
| 52 <iron-selector multi id="repeatedItems"> |
| 53 <template is="dom-repeat" items='["foo", "bar", "baz"]'> |
| 54 <div>[[item]]</div> |
| 55 </template> |
| 56 <div>vim</div> |
| 57 </iron-selector> |
| 58 <!--</template> |
| 59 </test-fixture>--> |
| 60 |
| 46 <script> | 61 <script> |
| 47 | 62 |
| 48 suite('multi', function() { | 63 suite('multi', function() { |
| 49 | 64 |
| 50 var s; | 65 var s; |
| 51 | 66 |
| 52 setup(function () { | 67 setup(function () { |
| 53 s = fixture('test'); | 68 s = fixture('test'); |
| 54 }); | 69 }); |
| 55 | 70 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); | 123 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
| 109 // check selectedValues | 124 // check selectedValues |
| 110 assert.equal(s.selectedValues.length, 0); | 125 assert.equal(s.selectedValues.length, 0); |
| 111 // check class | 126 // check class |
| 112 assert.isFalse(s.children[0].classList.contains('iron-selected')); | 127 assert.isFalse(s.children[0].classList.contains('iron-selected')); |
| 113 // check events | 128 // check events |
| 114 assert.equal(selectEventCounter, 1); | 129 assert.equal(selectEventCounter, 1); |
| 115 assert.equal(deselectEventCounter, 1); | 130 assert.equal(deselectEventCounter, 1); |
| 116 }); | 131 }); |
| 117 | 132 |
| 133 test('fires selected-values-changed when selection changes', function() { |
| 134 var selectedValuesChangedEventCounter = 0; |
| 135 |
| 136 s.addEventListener('selected-values-changed', function(e) { |
| 137 selectedValuesChangedEventCounter++; |
| 138 }); |
| 139 |
| 140 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 141 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 142 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 143 |
| 144 expect(selectedValuesChangedEventCounter); |
| 145 }); |
| 146 |
| 147 test('selects from items created by dom-repeat', function(done) { |
| 148 var selectEventCounter = 0; |
| 149 var firstChild; |
| 150 |
| 151 s = document.querySelector('#repeatedItems'); |
| 152 s.addEventListener('iron-select', function(e) { |
| 153 selectEventCounter++; |
| 154 }); |
| 155 |
| 156 // NOTE(cdata): I guess `dom-repeat` doesn't stamp synchronously.. |
| 157 Polymer.Base.async(function() { |
| 158 firstChild = Polymer.dom(s).querySelector('div'); |
| 159 MockInteractions.tap(firstChild); |
| 160 |
| 161 assert.equal(s.selectedItems[0].textContent, 'foo'); |
| 162 done(); |
| 163 }); |
| 164 }); |
| 165 |
| 118 /* test('toggle multi from true to false', function() { | 166 /* test('toggle multi from true to false', function() { |
| 119 // set selected | 167 // set selected |
| 120 s.selected = [0, 2]; | 168 s.selected = [0, 2]; |
| 121 var first = s.selected[0]; | 169 var first = s.selected[0]; |
| 122 // set mutli to false, so to make it single-selection | 170 // set mutli to false, so to make it single-selection |
| 123 s.multi = false; | 171 s.multi = false; |
| 124 // selected should not be an array | 172 // selected should not be an array |
| 125 assert.isNotArray(s.selected); | 173 assert.isNotArray(s.selected); |
| 126 // selected should be the first value from the old array | 174 // selected should be the first value from the old array |
| 127 assert.equal(s.selected, first); | 175 assert.equal(s.selected, first); |
| 128 }); */ | 176 }); */ |
| 129 | 177 |
| 130 }); | 178 }); |
| 131 | 179 |
| 132 </script> | 180 </script> |
| 133 | 181 |
| 134 </body> | 182 </body> |
| 135 </html> | 183 </html> |
| OLD | NEW |