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'); |
| 69 t = Polymer.dom(s).querySelector('[is="dom-repeat"]'); |
54 }); | 70 }); |
55 | 71 |
56 test('honors the multi attribute', function() { | 72 test('honors the multi attribute', function() { |
57 assert.isTrue(s.multi); | 73 assert.isTrue(s.multi); |
58 }); | 74 }); |
59 | 75 |
60 test('has sane defaults', function() { | 76 test('has sane defaults', function() { |
61 assert.equal(s.selectedValues, undefined); | 77 assert.equal(s.selectedValues, undefined); |
62 assert.equal(s.selectedClass, 'iron-selected'); | 78 assert.equal(s.selectedClass, 'iron-selected'); |
63 assert.equal(s.items.length, 5); | 79 assert.equal(s.items.length, 5); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); | 124 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
109 // check selectedValues | 125 // check selectedValues |
110 assert.equal(s.selectedValues.length, 0); | 126 assert.equal(s.selectedValues.length, 0); |
111 // check class | 127 // check class |
112 assert.isFalse(s.children[0].classList.contains('iron-selected')); | 128 assert.isFalse(s.children[0].classList.contains('iron-selected')); |
113 // check events | 129 // check events |
114 assert.equal(selectEventCounter, 1); | 130 assert.equal(selectEventCounter, 1); |
115 assert.equal(deselectEventCounter, 1); | 131 assert.equal(deselectEventCounter, 1); |
116 }); | 132 }); |
117 | 133 |
| 134 test('fires selected-values-changed when selection changes', function() { |
| 135 var selectedValuesChangedEventCounter = 0; |
| 136 |
| 137 s.addEventListener('selected-values-changed', function(e) { |
| 138 selectedValuesChangedEventCounter++; |
| 139 }); |
| 140 |
| 141 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 142 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 143 MockInteractions.tap(Polymer.dom(s).children[0]); |
| 144 |
| 145 expect(selectedValuesChangedEventCounter); |
| 146 }); |
| 147 |
| 148 test('selects from items created by dom-repeat', function(done) { |
| 149 var selectEventCounter = 0; |
| 150 var firstChild; |
| 151 |
| 152 s = document.querySelector('#repeatedItems'); |
| 153 s.addEventListener('iron-select', function(e) { |
| 154 selectEventCounter++; |
| 155 }); |
| 156 |
| 157 // NOTE(cdata): I guess `dom-repeat` doesn't stamp synchronously.. |
| 158 Polymer.Base.async(function() { |
| 159 firstChild = Polymer.dom(s).querySelector('div'); |
| 160 MockInteractions.tap(firstChild); |
| 161 |
| 162 assert.equal(s.selectedItems[0].textContent, 'foo'); |
| 163 done(); |
| 164 }); |
| 165 }); |
| 166 |
| 167 test('updates selection when dom changes', function(done) { |
| 168 var selectEventCounter = 0; |
| 169 |
| 170 s = fixture('test'); |
| 171 |
| 172 Polymer.Base.async(function() { |
| 173 var firstChild = Polymer.dom(s).querySelector(':first-child'); |
| 174 var lastChild = Polymer.dom(s).querySelector(':last-child'); |
| 175 |
| 176 MockInteractions.tap(firstChild); |
| 177 MockInteractions.tap(lastChild); |
| 178 |
| 179 expect(s.selectedItems.length).to.be.equal(2); |
| 180 |
| 181 Polymer.dom(s).removeChild(lastChild); |
| 182 |
| 183 Polymer.Base.async(function() { |
| 184 expect(s.selectedItems.length).to.be.equal(1); |
| 185 done(); |
| 186 }); |
| 187 }); |
| 188 |
| 189 }); |
| 190 |
118 /* test('toggle multi from true to false', function() { | 191 /* test('toggle multi from true to false', function() { |
119 // set selected | 192 // set selected |
120 s.selected = [0, 2]; | 193 s.selected = [0, 2]; |
121 var first = s.selected[0]; | 194 var first = s.selected[0]; |
122 // set mutli to false, so to make it single-selection | 195 // set mutli to false, so to make it single-selection |
123 s.multi = false; | 196 s.multi = false; |
124 // selected should not be an array | 197 // selected should not be an array |
125 assert.isNotArray(s.selected); | 198 assert.isNotArray(s.selected); |
126 // selected should be the first value from the old array | 199 // selected should be the first value from the old array |
127 assert.equal(s.selected, first); | 200 assert.equal(s.selected, first); |
128 }); */ | 201 }); */ |
129 | 202 |
130 }); | 203 }); |
131 | 204 |
132 </script> | 205 </script> |
133 | 206 |
134 </body> | 207 </body> |
135 </html> | 208 </html> |
OLD | NEW |