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-basic</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 | |
23 .my-selected { | |
24 background: red; | |
25 } | |
26 </style> | |
27 </head> | |
28 <body> | |
29 | |
30 <core-selector id="selector1"> | |
31 <div>Item 1</div> | |
32 <div>Item 2</div> | |
33 <div>Item 3</div> | |
34 <div>Item 4</div> | |
35 <div>Item 5</div> | |
36 </core-selector> | |
37 | |
38 <br><br> | |
39 | |
40 <core-selector id="selector2" selected="item3" selectedClass="my-selected" val
ueattr="id"> | |
41 <div id="item1">Item 1</div> | |
42 <div id="item2">Item 2</div> | |
43 <div id="item3">Item 3</div> | |
44 <div id="item4">Item 4</div> | |
45 <div id="item5">Item 5</div> | |
46 </core-selector> | |
47 | |
48 <script> | |
49 var async = requestAnimationFrame; | |
50 | |
51 function oneMutation(node, options, cb) { | |
52 var o = new MutationObserver(function() { | |
53 cb(); | |
54 o.disconnect(); | |
55 }); | |
56 o.observe(node, options); | |
57 } | |
58 | |
59 document.addEventListener('polymer-ready', function() { | |
60 var assert = chai.assert; | |
61 // selector1 | |
62 var s = document.querySelector('#selector1'); | |
63 assert.equal(s.selected, null); | |
64 assert.equal(s.selectedClass, 'core-selected'); | |
65 assert.isFalse(s.multi); | |
66 assert.equal(s.valueattr, 'name'); | |
67 assert.equal(s.items.length, 5); | |
68 // selector2 | |
69 s = document.querySelector('#selector2'); | |
70 assert.equal(s.selected, "item3"); | |
71 assert.equal(s.selectedClass, 'my-selected'); | |
72 // setup listener for core-select event | |
73 var selectEventCounter = 0; | |
74 s.addEventListener('core-select', function(e) { | |
75 if (e.detail.isSelected) { | |
76 selectEventCounter++; | |
77 // selectedItem and detail.item should be the same | |
78 assert.equal(e.detail.item, s.selectedItem); | |
79 } | |
80 }); | |
81 // set selected | |
82 s.selected = 'item5'; | |
83 Platform.flush(); | |
84 setTimeout(function() { | |
85 // check core-select event | |
86 assert.equal(selectEventCounter, 1); | |
87 // check selected class | |
88 assert.isTrue(s.children[4].classList.contains('my-selected')); | |
89 // check selectedItem | |
90 assert.equal(s.selectedItem, s.children[4]); | |
91 // selecting the same value shouldn't fire core-select | |
92 selectEventCounter = 0; | |
93 s.selected = 'item5'; | |
94 Platform.flush(); | |
95 // TODO(ffu): would be better to wait for something to happen | |
96 // instead of not to happen | |
97 setTimeout(function() { | |
98 assert.equal(selectEventCounter, 0); | |
99 done(); | |
100 }, 50); | |
101 }, 50); | |
102 }); | |
103 </script> | |
104 </body> | |
105 </html> | |
OLD | NEW |