1<!doctype html>
2<!--
3@license
4Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8Code distributed by Google as part of the polymer project is also
9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10-->
11<html>
12<head>
13  <meta charset="UTF-8">
14  <title>iron-checked-element-behavior basic tests</title>
15  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
16
17  <script src="../../webcomponentsjs/webcomponents.js"></script>
18  <script src="../../web-component-tester/browser.js"></script>
19  <script src="../../test-fixture/test-fixture-mocha.js"></script>
20
21  <link href="../../test-fixture/test-fixture.html" rel="import">
22  <link href="../../iron-meta/iron-meta.html" rel="import">
23  <link href="simple-checkbox.html" rel="import">
24
25</head>
26<body>
27
28  <test-fixture id="basic">
29    <template>
30      <simple-checkbox></simple-checkbox>
31    </template>
32  </test-fixture>
33
34  <test-fixture id="checked">
35    <template>
36      <simple-checkbox checked></simple-checkbox>
37    </template>
38  </test-fixture>
39
40  <test-fixture id="with-value">
41    <template>
42      <simple-checkbox value="batman"></simple-checkbox>
43    </template>
44  </test-fixture>
45
46  <script>
47
48    suite('basic', function() {
49      test('can be checked', function() {
50        var c = fixture('basic');
51        assert.isFalse(c.checked);
52        c.checked = true;
53        assert.isTrue(c.checked);
54      });
55
56      test('can be unchecked', function() {
57        var c = fixture('checked');
58        assert.isTrue(c.checked);
59        c.checked = false;
60        assert.isFalse(c.checked);
61      });
62
63      test('invalid if required and not checked', function() {
64        var c = fixture('basic');
65        c.required = true;
66        assert.isFalse(c.checked);
67        assert.isFalse(c.validate());
68        assert.isTrue(c.invalid);
69      });
70
71      test('valid if required and checked', function() {
72        var c = fixture('basic');
73        c.required = true;
74        c.checked = true;
75        assert.isTrue(c.checked);
76        assert.isTrue(c.validate());
77        assert.isFalse(c.invalid);
78      });
79
80      test('valid if not required and not checked', function() {
81        var c = fixture('basic');
82        assert.isFalse(c.checked);
83        assert.isTrue(c.validate());
84        assert.isFalse(c.invalid);
85      });
86
87      test('has a default value of "on", always', function() {
88        var c = fixture('basic');
89
90        assert.isTrue(c.value === 'on');
91
92        c.checked = true;
93        assert.isTrue(c.value === 'on');
94      });
95
96      test('does not stomp over user defined value when checked', function() {
97        var c = fixture('with-value');
98        assert.isTrue(c.value === 'batman');
99
100        c.checked = true;
101        assert.isTrue(c.value === 'batman');
102      });
103
104      test('value returns "on" when no explicit value is specified', function() {
105        var c = fixture('basic');
106
107        assert.equal(c.value, 'on', 'returns "on"');
108      });
109
110      test('value returns the value when an explicit value is set', function() {
111        var c = fixture('basic');
112
113        c.value = 'abc';
114        assert.equal(c.value, 'abc', 'returns "abc"');
115
116        c.value = '123';
117        assert.equal(c.value, '123', 'returns "123"');
118      });
119
120      test('value returns "on" when value is set to undefined', function() {
121        var c = fixture('basic');
122
123        c.value = 'abc';
124        assert.equal(c.value, 'abc', 'returns "abc"');
125
126        c.value = undefined;
127        assert.equal(c.value, 'on', 'returns "on"');
128      });
129    });
130
131    suite('a11y', function() {
132      test('setting `required` sets `aria-required=true`', function() {
133        var c = fixture('basic');
134        c.required = true;
135        assert.equal(c.getAttribute('aria-required'), 'true');
136        c.required = false;
137        assert.isFalse(c.hasAttribute('aria-required'));
138      });
139
140      test('setting `invalid` sets `aria-invalid=true`', function() {
141        var c = fixture('basic');
142        c.invalid = true;
143        assert.equal(c.getAttribute('aria-invalid'), 'true');
144        c.invalid = false;
145        assert.isFalse(c.hasAttribute('aria-invalid'));
146      });
147    });
148
149  </script>
150
151</body>
152</html>
153