OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 Copyright (c) 2015 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 |
| 11 <html> |
| 12 <head> |
| 13 |
| 14 <title>iron-selector-content</title> |
| 15 <meta charset="utf-8"> |
| 16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
| 17 |
| 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 19 <script src="../../web-component-tester/browser.js"></script> |
| 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 21 |
| 22 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 23 <link rel="import" href="content-element.html"> |
| 24 |
| 25 <style> |
| 26 .iron-selected { |
| 27 background: #ccc; |
| 28 } |
| 29 </style> |
| 30 |
| 31 </head> |
| 32 <body> |
| 33 |
| 34 <test-content-element id="selector1" selected="item0"> |
| 35 <div id="item0">item0</div> |
| 36 <div id="item1">item1</div> |
| 37 <div id="item2">item2</div> |
| 38 <div id="item3">item3</div> |
| 39 </test-content-element> |
| 40 |
| 41 <test-content-element id="selector2" selected="item0" selectable="item"> |
| 42 <item id="item0">item0</item> |
| 43 <hr> |
| 44 <item id="item1">item1</item> |
| 45 <item id="item2">item2</item> |
| 46 <hr> |
| 47 <item id="item3">item3</item> |
| 48 </test-content-element> |
| 49 |
| 50 <test-content-element id="selector3" selected="item0"> |
| 51 <template is="dom-repeat" id="t"> |
| 52 <div id$="[[item.name]]">[[item.name]]</div> |
| 53 </template> |
| 54 </test-content-element> |
| 55 |
| 56 <script> |
| 57 |
| 58 var s1 = document.querySelector('#selector1'); |
| 59 var s2 = document.querySelector('#selector2'); |
| 60 var s3 = document.querySelector('#selector3'); |
| 61 |
| 62 var t = document.querySelector('#t'); |
| 63 |
| 64 suite('content', function() { |
| 65 |
| 66 test('attribute selected', function() { |
| 67 // check selected class |
| 68 assert.isTrue(s1.querySelector('#item0').classList.contains('iron-select
ed')); |
| 69 }); |
| 70 |
| 71 test('set selected', function() { |
| 72 // set selected |
| 73 s1.selected = 'item1'; |
| 74 // check selected class |
| 75 assert.isTrue(s1.querySelector('#item1').classList.contains('iron-select
ed')); |
| 76 }); |
| 77 |
| 78 test('get items', function() { |
| 79 assert.equal(s1.$.selector.items.length, 4); |
| 80 }); |
| 81 |
| 82 test('activate event', function() { |
| 83 var item = s1.querySelector('#item2'); |
| 84 item.dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
| 85 // check selected class |
| 86 assert.isTrue(item.classList.contains('iron-selected')); |
| 87 }); |
| 88 |
| 89 test('add item dynamically', function() { |
| 90 var item = document.createElement('div'); |
| 91 item.id = 'item4'; |
| 92 item.textContent = 'item4'; |
| 93 Polymer.dom(s1).appendChild(item); |
| 94 Polymer.dom.flush(); |
| 95 // set selected |
| 96 s1.selected = 'item4'; |
| 97 // check items length |
| 98 assert.equal(s1.$.selector.items.length, 5); |
| 99 // check selected class |
| 100 assert.isTrue(s1.querySelector('#item4').classList.contains('iron-select
ed')); |
| 101 }); |
| 102 |
| 103 }); |
| 104 |
| 105 suite('content with selectable', function() { |
| 106 |
| 107 test('attribute selected', function() { |
| 108 // check selected class |
| 109 assert.isTrue(s2.querySelector('#item0').classList.contains('iron-select
ed')); |
| 110 }); |
| 111 |
| 112 test('set selected', function() { |
| 113 // set selected |
| 114 s2.selected = 'item1'; |
| 115 // check selected class |
| 116 assert.isTrue(s2.querySelector('#item1').classList.contains('iron-select
ed')); |
| 117 }); |
| 118 |
| 119 test('get items', function() { |
| 120 assert.equal(s2.$.selector.items.length, 4); |
| 121 }); |
| 122 |
| 123 test('activate event', function() { |
| 124 var item = s2.querySelector('#item2'); |
| 125 item.dispatchEvent(new CustomEvent('tap', {bubbles: true})); |
| 126 // check selected class |
| 127 assert.isTrue(item.classList.contains('iron-selected')); |
| 128 }); |
| 129 |
| 130 test('add item dynamically', function() { |
| 131 var item = document.createElement('item'); |
| 132 item.id = 'item4'; |
| 133 item.textContent = 'item4'; |
| 134 Polymer.dom(s2).appendChild(item); |
| 135 Polymer.dom.flush(); |
| 136 // set selected |
| 137 s2.selected = 'item4'; |
| 138 // check items length |
| 139 assert.equal(s2.$.selector.items.length, 5); |
| 140 // check selected class |
| 141 assert.isTrue(s2.querySelector('#item4').classList.contains('iron-select
ed')); |
| 142 }); |
| 143 |
| 144 }); |
| 145 |
| 146 suite('content with dom-repeat', function() { |
| 147 |
| 148 test('supports repeated children', function(done) { |
| 149 t.items = [{name:'item0'}, {name: 'item1'}, {name: 'item2'}, {name: 'ite
m3'}]; |
| 150 setTimeout(function() { |
| 151 // check selected |
| 152 assert.equal(s3.selected, 'item0'); |
| 153 // check selected class |
| 154 assert.isTrue(s3.querySelector('#item0').classList.contains('iron-sele
cted')); |
| 155 // set selected |
| 156 s3.selected = 'item2'; |
| 157 // check selected class |
| 158 assert.isTrue(s3.querySelector('#item2').classList.contains('iron-sele
cted')); |
| 159 done(); |
| 160 }); |
| 161 }); |
| 162 |
| 163 }); |
| 164 |
| 165 </script> |
| 166 |
| 167 </body> |
| 168 </html> |
OLD | NEW |