| 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 <title>core-selector-multi</title> | |
| 13 <script src="../../platform/platform.js"></script> | |
| 14 <link rel="import" href="../../polymer-test-tools/tools.html"> | |
| 15 <script src="../../polymer-test-tools/htmltest.js"></script> | |
| 16 | |
| 17 <link rel="import" href="../../core-selector/core-selector.html"> | |
| 18 <style> | |
| 19 .core-selected { | |
| 20 background: #ccc; | |
| 21 } | |
| 22 </style> | |
| 23 </head> | |
| 24 <body> | |
| 25 | |
| 26 <core-selector id="selector" multi> | |
| 27 <div>Item 1</div> | |
| 28 <div>Item 2</div> | |
| 29 <div>Item 3</div> | |
| 30 <div>Item 4</div> | |
| 31 <div>Item 5</div> | |
| 32 </core-selector> | |
| 33 | |
| 34 <script> | |
| 35 function oneMutation(node, options, cb) { | |
| 36 var o = new MutationObserver(function() { | |
| 37 cb(); | |
| 38 o.disconnect(); | |
| 39 }); | |
| 40 o.observe(node, options); | |
| 41 } | |
| 42 | |
| 43 document.addEventListener('polymer-ready', function() { | |
| 44 var assert = chai.assert; | |
| 45 // | |
| 46 var s = document.querySelector('#selector'); | |
| 47 assert.equal(s.selected, null); | |
| 48 assert.equal(s.selectedClass, 'core-selected'); | |
| 49 assert.isTrue(s.multi); | |
| 50 assert.equal(s.valueattr, 'name'); | |
| 51 assert.equal(s.items.length, 5); | |
| 52 // setup listener for core-select event | |
| 53 var selectEventCounter = 0; | |
| 54 s.addEventListener('core-select', function(e) { | |
| 55 if (e.detail.isSelected) { | |
| 56 selectEventCounter++; | |
| 57 } else { | |
| 58 selectEventCounter--; | |
| 59 } | |
| 60 // check selectedItem in core-select event | |
| 61 assert.equal(this.selectedItem.length, selectEventCounter); | |
| 62 }); | |
| 63 // set selected | |
| 64 s.selected = [0, 2]; | |
| 65 Platform.flush(); | |
| 66 setTimeout(function() { | |
| 67 // check core-select event | |
| 68 assert.equal(selectEventCounter, 2); | |
| 69 // check selected class | |
| 70 assert.isTrue(s.children[0].classList.contains('core-selected')); | |
| 71 assert.isTrue(s.children[2].classList.contains('core-selected')); | |
| 72 // check selectedItem | |
| 73 assert.equal(s.selectedItem.length, 2); | |
| 74 assert.equal(s.selectedItem[0], s.children[0]); | |
| 75 assert.equal(s.selectedItem[1], s.children[2]); | |
| 76 // tap on already selected element should unselect it | |
| 77 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true})); | |
| 78 // check selected | |
| 79 assert.equal(s.selected.length, 1); | |
| 80 assert.isFalse(s.children[0].classList.contains('core-selected')); | |
| 81 done(); | |
| 82 }, 50); | |
| 83 }); | |
| 84 </script> | |
| 85 </body> | |
| 86 </html> | |
| OLD | NEW |