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-next-previous</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="../iron-selector.html"> |
| 24 |
| 25 <style> |
| 26 .iron-selected { |
| 27 background: #ccc; |
| 28 } |
| 29 </style> |
| 30 |
| 31 </head> |
| 32 <body> |
| 33 |
| 34 <test-fixture id="test1"> |
| 35 <template> |
| 36 <iron-selector selected="0"> |
| 37 <div>Item 0</div> |
| 38 <div>Item 1</div> |
| 39 <div>Item 2</div> |
| 40 </iron-selector> |
| 41 </template> |
| 42 </test-fixture> |
| 43 |
| 44 <test-fixture id="test2"> |
| 45 <template> |
| 46 <iron-selector selected="foo" attr-for-selected="name"> |
| 47 <div name="foo">Item Foo</div> |
| 48 <div name="bar">Item Bar</div> |
| 49 <div name="zot">Item Zot</div> |
| 50 </iron-selector> |
| 51 </template> |
| 52 </test-fixture> |
| 53 |
| 54 <script> |
| 55 |
| 56 var s; |
| 57 |
| 58 function assertAndSelect(method, expectedIndex) { |
| 59 assert.equal(s.selected, expectedIndex); |
| 60 s[method](); |
| 61 } |
| 62 |
| 63 suite('next/previous', function() { |
| 64 |
| 65 setup(function () { |
| 66 s = fixture('test1'); |
| 67 }); |
| 68 |
| 69 test('selectNext', function() { |
| 70 assert.equal(s.selected, 0); |
| 71 assertAndSelect('selectNext', 0); |
| 72 assertAndSelect('selectNext', 1); |
| 73 assertAndSelect('selectNext', 2); |
| 74 assert.equal(s.selected, 0); |
| 75 }); |
| 76 |
| 77 test('selectPrevious', function() { |
| 78 assert.equal(s.selected, 0); |
| 79 assertAndSelect('selectPrevious', 0); |
| 80 assertAndSelect('selectPrevious', 2); |
| 81 assertAndSelect('selectPrevious', 1); |
| 82 assert.equal(s.selected, 0); |
| 83 }); |
| 84 |
| 85 test('selectNext/Previous', function() { |
| 86 assert.equal(s.selected, 0); |
| 87 assertAndSelect('selectNext', 0); |
| 88 assertAndSelect('selectNext', 1); |
| 89 assertAndSelect('selectPrevious', 2); |
| 90 assertAndSelect('selectNext', 1); |
| 91 assertAndSelect('selectPrevious', 2); |
| 92 assert.equal(s.selected, 1); |
| 93 }); |
| 94 |
| 95 }); |
| 96 |
| 97 suite('next/previous attrForSelected', function() { |
| 98 |
| 99 setup(function () { |
| 100 s = fixture('test2'); |
| 101 }); |
| 102 |
| 103 test('selectNext', function() { |
| 104 assert.equal(s.selected, 'foo'); |
| 105 assertAndSelect('selectNext', 'foo'); |
| 106 assertAndSelect('selectNext', 'bar'); |
| 107 assertAndSelect('selectNext', 'zot'); |
| 108 assert.equal(s.selected, 'foo'); |
| 109 }); |
| 110 |
| 111 test('selectPrevious', function() { |
| 112 assert.equal(s.selected, 'foo'); |
| 113 assertAndSelect('selectPrevious', 'foo'); |
| 114 assertAndSelect('selectPrevious', 'zot'); |
| 115 assertAndSelect('selectPrevious', 'bar'); |
| 116 assert.equal(s.selected, 'foo'); |
| 117 }); |
| 118 |
| 119 test('selectNext/Previous', function() { |
| 120 assert.equal(s.selected, 'foo'); |
| 121 assertAndSelect('selectNext', 'foo'); |
| 122 assertAndSelect('selectNext', 'bar'); |
| 123 assertAndSelect('selectPrevious', 'zot'); |
| 124 assertAndSelect('selectNext', 'bar'); |
| 125 assertAndSelect('selectPrevious', 'zot'); |
| 126 assert.equal(s.selected, 'bar'); |
| 127 }); |
| 128 |
| 129 }); |
| 130 |
| 131 </script> |
| 132 |
| 133 </body> |
| 134 </html> |
OLD | NEW |