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
13
<meta charset="UTF-8">
14
<title>paper-radio-group basic tests</title>
15
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
17
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
18
<script src="../../web-component-tester/browser.js"></script>
19
<script src="../../iron-test-helpers/mock-interactions.js"></script>
20
<link rel="import" href="../paper-radio-group.html">
25
<test-fixture id="NoSelection">
28
<paper-radio-button name="r1">r1</paper-radio-button>
29
<paper-radio-button name="r2">r2</paper-radio-button>
30
<paper-radio-button name="r3">r3</paper-radio-button>
35
<test-fixture id="WithSelection">
37
<paper-radio-group selected="r1">
38
<paper-radio-button name="r1">r1</paper-radio-button>
39
<paper-radio-button name="r2">r2</paper-radio-button>
40
<paper-radio-button name="r3">r3</paper-radio-button>
45
<test-fixture id="WithDisabled">
47
<paper-radio-group selected="r1">
48
<paper-radio-button name="r1">r1</paper-radio-button>
49
<paper-radio-button name="r2" disabled>r2</paper-radio-button>
50
<paper-radio-button name="r3">r3</paper-radio-button>
56
suite('defaults', function() {
60
test('group can have no selection', function (done) {
61
var g = fixture('NoSelection');
63
// Needs to be async since the underlying iron-selector uses observeNodes.
64
Polymer.Base.async(function() {
65
expect(g.selected).to.not.be.ok;
67
expect(items.length).to.be.equal(3);
69
expect(items[0].checked).to.be.equal(false);
70
expect(items[1].checked).to.be.equal(false);
71
expect(items[2].checked).to.be.equal(false);
78
test('group can have a selection', function (done) {
79
var g = fixture('WithSelection');
81
// Needs to be async since the underlying iron-selector uses observeNodes.
82
Polymer.Base.async(function() {
83
expect(g.selected).to.be.ok;
85
expect(items.length).to.be.equal(3);
87
expect(items[0].checked).to.be.equal(true);
88
expect(items[1].checked).to.be.equal(false);
89
expect(items[2].checked).to.be.equal(false);
90
expect(items[0].getAttribute('name')).to.be.equal(g.selected);
96
test('right arrow advances the selection', function (done) {
97
var g = fixture('WithSelection');
99
// Needs to be async since the underlying iron-selector uses observeNodes.
100
Polymer.Base.async(function() {
102
expect(items[0].checked).to.be.equal(true);
104
g.addEventListener('paper-radio-group-changed', function () {
105
expect(items[0].checked).to.be.equal(false);
106
expect(items[1].checked).to.be.equal(true);
107
expect(items[2].checked).to.be.equal(false);
110
MockInteractions.keyDownOn(g, RIGHT_ARROW);
114
test('left arrow reverses the selection', function (done) {
115
var g = fixture('WithSelection');
117
// Needs to be async since the underlying iron-selector uses observeNodes.
118
Polymer.Base.async(function() {
120
expect(items[0].checked).to.be.equal(true);
122
g.addEventListener('paper-radio-group-changed', function () {
123
expect(items[0].checked).to.be.equal(false);
124
expect(items[1].checked).to.be.equal(false);
125
expect(items[2].checked).to.be.equal(true);
128
MockInteractions.keyDownOn(g, LEFT_ARROW);
132
test('selection should skip disabled items', function (done) {
133
var g = fixture('WithDisabled');
135
// Needs to be async since the underlying iron-selector uses observeNodes.
136
Polymer.Base.async(function() {
138
expect(items[0].checked).to.be.equal(true);
140
g.addEventListener('paper-radio-group-changed', function () {
141
expect(items[0].checked).to.be.equal(false);
142
expect(items[1].checked).to.be.equal(false);
143
expect(items[2].checked).to.be.equal(true);
146
MockInteractions.keyDownOn(g, RIGHT_ARROW);
150
test('clicking should change the selection', function (done) {
151
var g = fixture('WithSelection');
153
// Needs to be async since the underlying iron-selector uses observeNodes.
154
Polymer.Base.async(function() {
156
expect(items[0].checked).to.be.equal(true);
158
g.addEventListener('paper-radio-group-changed', function () {
159
expect(items[0].checked).to.be.equal(false);
160
expect(items[1].checked).to.be.equal(true);
161
expect(items[2].checked).to.be.equal(false);
164
MockInteractions.tap(items[1]);
168
test('clicking the selected item should not deselect', function (done) {
169
var g = fixture('WithSelection');
171
// Needs to be async since the underlying iron-selector uses observeNodes.
172
Polymer.Base.async(function() {
174
expect(items[0].checked).to.be.equal(true);
176
// The selection should not change, but wait for a little bit just
177
// in case it would and an event would be fired.
178
setTimeout(function() {
179
expect(items[0].checked).to.be.equal(true);
180
expect(items[1].checked).to.be.equal(false);
181
expect(items[2].checked).to.be.equal(false);
184
MockInteractions.tap(items[0]);
188
test('clicking the selected item should deselect if allow-empty-selection is set', function (done) {
189
var g = fixture('WithSelection');
190
g.allowEmptySelection = true;
192
// Needs to be async since the underlying iron-selector uses observeNodes.
193
Polymer.Base.async(function() {
195
expect(items[0].checked).to.be.equal(true);
197
// The selection should not change, but wait for a little bit just
198
// in case it would and an event would be fired.
199
setTimeout(function() {
200
expect(items[0].checked).to.be.equal(false);
201
expect(items[1].checked).to.be.equal(false);
202
expect(items[2].checked).to.be.equal(false);
205
MockInteractions.tap(items[0]);
209
test('arrow keys cause iron-activate events', function(done) {
210
var g = fixture('WithSelection');
212
// Needs to be async since the underlying iron-selector uses observeNodes.
213
Polymer.Base.async(function() {
217
g.addEventListener('iron-activate', function() {
220
MockInteractions.pressAndReleaseKeyOn(g, 38);
224
MockInteractions.pressAndReleaseKeyOn(g, 39);
228
MockInteractions.pressAndReleaseKeyOn(g, 40);
236
MockInteractions.pressAndReleaseKeyOn(g, 37);