OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2014 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 <html> | 10 <html> |
11 <head> | 11 <head> |
12 <meta charset="UTF-8"> | 12 <meta charset="UTF-8"> |
13 <title>core-selector-multi</title> | 13 <title>core-selector-multi</title> |
14 | 14 |
15 <script src="../../platform/platform.js"></script> | 15 <script src="../../webcomponentsjs/webcomponents.js"></script> |
16 <script src="../../web-component-tester/browser.js"></script> | 16 <script src="../../web-component-tester/browser.js"></script> |
17 | 17 |
18 <link rel="import" href="../core-selector.html"> | 18 <link rel="import" href="../core-selector.html"> |
19 | 19 |
20 <style> | 20 <style> |
21 .core-selected { | 21 .core-selected { |
22 background: #ccc; | 22 background: #ccc; |
23 } | 23 } |
24 </style> | 24 </style> |
25 | 25 |
(...skipping 27 matching lines...) Expand all Loading... |
53 | 53 |
54 test('allows multi-selection', function(done) { | 54 test('allows multi-selection', function(done) { |
55 // setup listener for core-select event | 55 // setup listener for core-select event |
56 var selectEventCounter = 0; | 56 var selectEventCounter = 0; |
57 s.addEventListener('core-select', function(e) { | 57 s.addEventListener('core-select', function(e) { |
58 if (e.detail.isSelected) { | 58 if (e.detail.isSelected) { |
59 selectEventCounter++; | 59 selectEventCounter++; |
60 } else { | 60 } else { |
61 selectEventCounter--; | 61 selectEventCounter--; |
62 } | 62 } |
63 // check selectedItem in core-select event | |
64 assert.equal(this.selectedItem.length, selectEventCounter); | |
65 }); | 63 }); |
66 // set selected | 64 // set selected |
67 s.selected = [0, 2]; | 65 s.selected = [0, 2]; |
68 asyncPlatformFlush(function() { | 66 asyncPlatformFlush(function() { |
69 // check core-select event | 67 // check core-select event |
70 assert.equal(selectEventCounter, 2); | 68 assert.equal(selectEventCounter, 2); |
71 // check selected class | 69 // check selected class |
72 assert.isTrue(s.children[0].classList.contains('core-selected')); | 70 assert.isTrue(s.children[0].classList.contains('core-selected')); |
73 assert.isTrue(s.children[2].classList.contains('core-selected')); | 71 assert.isTrue(s.children[2].classList.contains('core-selected')); |
74 // check selectedItem | 72 // check selectedItem |
75 assert.equal(s.selectedItem.length, 2); | 73 assert.equal(s.selectedItem.length, 2); |
76 assert.equal(s.selectedItem[0], s.children[0]); | 74 assert.equal(s.selectedItem[0], s.children[0]); |
77 assert.equal(s.selectedItem[1], s.children[2]); | 75 assert.equal(s.selectedItem[1], s.children[2]); |
78 // tap on already selected element should unselect it | 76 // tap on already selected element should unselect it |
79 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); | 77 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
80 // check selected | 78 // check selected |
81 assert.equal(s.selected.length, 1); | 79 assert.equal(s.selected.length, 1); |
82 assert.isFalse(s.children[0].classList.contains('core-selected')); | 80 asyncPlatformFlush(function() { |
| 81 assert.equal(selectEventCounter, 1); |
| 82 assert.isFalse(s.children[0].classList.contains('core-selected')); |
| 83 // add selected |
| 84 s.selected.push(3); |
| 85 s.selected.push(4); |
| 86 // check core-select event |
| 87 asyncPlatformFlush(function() { |
| 88 assert.equal(selectEventCounter, 3); |
| 89 done(); |
| 90 }); |
| 91 }); |
| 92 }); |
| 93 }); |
| 94 |
| 95 test('toggle multi to false', function(done) { |
| 96 // set selected |
| 97 s.selected = [0, 2]; |
| 98 var first = s.selected[0]; |
| 99 // set mutli to false, so to make it single-selection |
| 100 s.multi = false; |
| 101 asyncPlatformFlush(function() { |
| 102 // selected should not be an array |
| 103 assert.isNotArray(s.selected); |
| 104 // selected should be the first value in the old array |
| 105 assert.equal(s.selected, first); |
83 done(); | 106 done(); |
84 }); | 107 }); |
85 }); | 108 }); |
86 | 109 |
87 }); | 110 }); |
88 | 111 |
89 </script> | 112 </script> |
90 | 113 |
91 </body> | 114 </body> |
92 </html> | 115 </html> |
OLD | NEW |