Home | History | Annotate | Download | only in test
      1 <!doctype html>
      2 <!--
      3 @license
      4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
      5 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
      6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
      7 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
      8 Code distributed by Google as part of the polymer project is also
      9 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
     10 -->
     11 
     12 <html>
     13 <head>
     14 
     15   <title>iron-selector-template-repeat</title>
     16   <meta charset="utf-8">
     17   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
     18 
     19   <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
     20   <script src="../../web-component-tester/browser.js"></script>
     21 
     22   <link rel="import" href="../iron-selector.html">
     23 
     24   <style>
     25     .iron-selected {
     26       background: #ccc;
     27     }
     28   </style>
     29 
     30 </head>
     31 <body>
     32 
     33   <template is="dom-bind">
     34     <iron-selector id="selector" selected="1">
     35       <template id="t" is="dom-repeat">
     36         <div id$="[[item.name]]">{{item.name}}</div>
     37       </template>
     38     </iron-selector>
     39   </template>
     40 
     41   <script>
     42 
     43     suite('dom-repeat', function() {
     44 
     45       var scope, s, t;
     46 
     47       setup(function() {
     48         scope = document.querySelector('template[is="dom-bind"]');
     49         s = scope.$.selector;
     50         t = scope.$.t;
     51         t.items = [{name:'item0'}, {name: 'item1'}, {name: 'item2'}, {name: 'item3'}];
     52       });
     53 
     54       teardown(function() {
     55         t.items = [];
     56       });
     57 
     58       test('supports repeated items', function() {
     59         t.render();
     60         // check items
     61         assert.equal(s.items.length, 4);
     62         // check selected
     63         assert.equal(s.selected, 1);
     64         // check selected item
     65         var item = s.selectedItem;
     66         assert.equal(s.items[1], item);
     67         // check selected class
     68         assert.isTrue(item.classList.contains('iron-selected'));
     69       });
     70 
     71       test('update items', function() {
     72         t.render();
     73         // check items
     74         assert.equal(s.items.length, 4);
     75         // check selected
     76         assert.equal(s.selected, 1);
     77         // update items
     78         t.items = [{name:'foo'}, {name: 'bar'}];
     79         t.render();
     80         // check items
     81         assert.equal(s.items.length, 2);
     82         // check selected (should still honor the selected)
     83         assert.equal(s.selected, 1);
     84         // check selected class
     85         assert.isTrue(s.querySelector('#bar').classList.contains('iron-selected'));
     86       });
     87 
     88       test('set selected to something else', function() {
     89         t.render();
     90         // set selected to something else
     91         s.selected = 3;
     92         // check selected item
     93         var item = s.selectedItem;
     94         assert.equal(s.items[3], item);
     95         // check selected class
     96         assert.isTrue(item.classList.contains('iron-selected'));
     97       });
     98 
     99     });
    100 
    101   </script>
    102 
    103 </body>
    104 </html>
    105