blob: e161c1b15ddf05a1c1cbb534ea7def17f23a851b [file] [log] [blame]
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-selector-next-previous</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../iron-selector.html">
<style>
.iron-selected {
background: #ccc;
}
</style>
</head>
<body>
<test-fixture id="test1">
<template>
<iron-selector selected="0">
<div>Item 0</div>
<div>Item 1</div>
<div>Item 2</div>
</iron-selector>
</template>
</test-fixture>
<test-fixture id="test2">
<template>
<iron-selector selected="foo" attr-for-selected="name">
<div name="foo">Item Foo</div>
<div name="bar">Item Bar</div>
<div name="zot">Item Zot</div>
</iron-selector>
</template>
</test-fixture>
<script>
var s;
function assertAndSelect(method, expectedIndex) {
assert.equal(s.selected, expectedIndex);
s[method]();
}
suite('next/previous', function() {
setup(function () {
s = fixture('test1');
});
test('selectNext', function() {
assert.equal(s.selected, 0);
assertAndSelect('selectNext', 0);
assertAndSelect('selectNext', 1);
assertAndSelect('selectNext', 2);
assert.equal(s.selected, 0);
});
test('selectPrevious', function() {
assert.equal(s.selected, 0);
assertAndSelect('selectPrevious', 0);
assertAndSelect('selectPrevious', 2);
assertAndSelect('selectPrevious', 1);
assert.equal(s.selected, 0);
});
test('selectNext/Previous', function() {
assert.equal(s.selected, 0);
assertAndSelect('selectNext', 0);
assertAndSelect('selectNext', 1);
assertAndSelect('selectPrevious', 2);
assertAndSelect('selectNext', 1);
assertAndSelect('selectPrevious', 2);
assert.equal(s.selected, 1);
});
});
suite('next/previous attrForSelected', function() {
setup(function () {
s = fixture('test2');
});
test('selectNext', function() {
assert.equal(s.selected, 'foo');
assertAndSelect('selectNext', 'foo');
assertAndSelect('selectNext', 'bar');
assertAndSelect('selectNext', 'zot');
assert.equal(s.selected, 'foo');
});
test('selectPrevious', function() {
assert.equal(s.selected, 'foo');
assertAndSelect('selectPrevious', 'foo');
assertAndSelect('selectPrevious', 'zot');
assertAndSelect('selectPrevious', 'bar');
assert.equal(s.selected, 'foo');
});
test('selectNext/Previous', function() {
assert.equal(s.selected, 'foo');
assertAndSelect('selectNext', 'foo');
assertAndSelect('selectNext', 'bar');
assertAndSelect('selectPrevious', 'zot');
assertAndSelect('selectNext', 'bar');
assertAndSelect('selectPrevious', 'zot');
assert.equal(s.selected, 'bar');
});
});
</script>
</body>
</html>