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-content</title> |
| 14 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
| 15 |
| 16 <script src="../../webcomponentsjs/webcomponents.js"></script> |
| 17 <script src="../../web-component-tester/browser.js"></script> |
| 18 |
| 19 <link rel="import" href="../core-selector.html"> |
| 20 |
| 21 <style> |
| 22 .core-selected { |
| 23 background: #ccc; |
| 24 } |
| 25 </style> |
| 26 |
| 27 </head> |
| 28 <body> |
| 29 |
| 30 <polymer-element name="test-core-selector" noscript attributes="selected"> |
| 31 <template> |
| 32 <core-selector id="selector" selected="{{selected}}" valueattr="id"> |
| 33 <content></content> |
| 34 </core-selector> |
| 35 </template> |
| 36 </polymer-element> |
| 37 |
| 38 <test-core-selector selected="item0"> |
| 39 <div id="item0">item0</div> |
| 40 <div id="item1">item1</div> |
| 41 <div id="item2">item2</div> |
| 42 <div id="item3">item3</div> |
| 43 </test-core-selector> |
| 44 |
| 45 <script> |
| 46 |
| 47 var s = document.querySelector('test-core-selector'); |
| 48 |
| 49 suite('content', function() { |
| 50 |
| 51 test('get selected', function(done) { |
| 52 asyncPlatformFlush(function() { |
| 53 // check selected class |
| 54 assert.isTrue(s.children[0].classList.contains('core-selected')); |
| 55 done(); |
| 56 }); |
| 57 }); |
| 58 |
| 59 test('set selected', function(done) { |
| 60 // set selected |
| 61 s.selected = 'item1'; |
| 62 asyncPlatformFlush(function() { |
| 63 // check selected class |
| 64 assert.isTrue(s.children[1].classList.contains('core-selected')); |
| 65 done(); |
| 66 }); |
| 67 }); |
| 68 |
| 69 test('get items', function() { |
| 70 assert.equal(s.$.selector.items.length, s.children.length); |
| 71 }); |
| 72 |
| 73 test('activate event', function(done) { |
| 74 s.children[2].dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
| 75 asyncPlatformFlush(function() { |
| 76 // check selected class |
| 77 assert.isTrue(s.children[2].classList.contains('core-selected')); |
| 78 done(); |
| 79 }); |
| 80 }); |
| 81 |
| 82 test('add item dynamically', function(done) { |
| 83 var item = document.createElement('div'); |
| 84 item.id = 'item4'; |
| 85 item.textContent = 'item4'; |
| 86 s.appendChild(item); |
| 87 // set selected |
| 88 s.selected = 'item4'; |
| 89 asyncPlatformFlush(function() { |
| 90 // check selected class |
| 91 assert.isTrue(s.children[4].classList.contains('core-selected')); |
| 92 done(); |
| 93 }); |
| 94 }); |
| 95 |
| 96 }); |
| 97 |
| 98 </script> |
| 99 |
| 100 </body> |
| 101 </html> |
OLD | NEW |