| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <!-- | |
| 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 | |
| 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 | |
| 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 | |
| 9 --> | |
| 10 <html> | |
| 11 <head> | |
| 12 <meta charset="UTF-8"> | |
| 13 <title>core-selector-multi</title> | |
| 14 | |
| 15 <script src="../../platform/platform.js"></script> | |
| 16 <script src="../../web-component-tester/browser.js"></script> | |
| 17 | |
| 18 <link rel="import" href="../core-selector.html"> | |
| 19 | |
| 20 <style> | |
| 21 .core-selected { | |
| 22 background: #ccc; | |
| 23 } | |
| 24 </style> | |
| 25 | |
| 26 </head> | |
| 27 <body> | |
| 28 | |
| 29 <core-selector id="selector" multi> | |
| 30 <div>Item 1</div> | |
| 31 <div>Item 2</div> | |
| 32 <div>Item 3</div> | |
| 33 <div>Item 4</div> | |
| 34 <div>Item 5</div> | |
| 35 </core-selector> | |
| 36 | |
| 37 <script> | |
| 38 | |
| 39 var s = document.querySelector('#selector'); | |
| 40 | |
| 41 suite('multi', function() { | |
| 42 | |
| 43 test('honors the multi attribute', function() { | |
| 44 assert.isTrue(s.multi); | |
| 45 }); | |
| 46 | |
| 47 test('has sane defaults', function() { | |
| 48 assert.equal(s.selected, null); | |
| 49 assert.equal(s.selectedClass, 'core-selected'); | |
| 50 assert.equal(s.valueattr, 'name'); | |
| 51 assert.equal(s.items.length, 5); | |
| 52 }); | |
| 53 | |
| 54 test('allows multi-selection', function(done) { | |
| 55 // setup listener for core-select event | |
| 56 var selectEventCounter = 0; | |
| 57 s.addEventListener('core-select', function(e) { | |
| 58 if (e.detail.isSelected) { | |
| 59 selectEventCounter++; | |
| 60 } else { | |
| 61 selectEventCounter--; | |
| 62 } | |
| 63 // check selectedItem in core-select event | |
| 64 assert.equal(this.selectedItem.length, selectEventCounter); | |
| 65 }); | |
| 66 // set selected | |
| 67 s.selected = [0, 2]; | |
| 68 asyncPlatformFlush(function() { | |
| 69 // check core-select event | |
| 70 assert.equal(selectEventCounter, 2); | |
| 71 // check selected class | |
| 72 assert.isTrue(s.children[0].classList.contains('core-selected')); | |
| 73 assert.isTrue(s.children[2].classList.contains('core-selected')); | |
| 74 // check selectedItem | |
| 75 assert.equal(s.selectedItem.length, 2); | |
| 76 assert.equal(s.selectedItem[0], s.children[0]); | |
| 77 assert.equal(s.selectedItem[1], s.children[2]); | |
| 78 // tap on already selected element should unselect it | |
| 79 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); | |
| 80 // check selected | |
| 81 assert.equal(s.selected.length, 1); | |
| 82 assert.isFalse(s.children[0].classList.contains('core-selected')); | |
| 83 done(); | |
| 84 }); | |
| 85 }); | |
| 86 | |
| 87 }); | |
| 88 | |
| 89 </script> | |
| 90 | |
| 91 </body> | |
| 92 </html> | |
| OLD | NEW |