This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
basic.html
170 lines (132 loc) · 6.43 KB
/
basic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!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>gold-cc-expiration-input tests</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../iron-test-helpers/test-helpers.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../gold-cc-expiration-input.html">
</head>
<body>
<test-fixture id="basic">
<template>
<gold-cc-expiration-input auto-validate required error-message="error"></gold-cc-expiration-input>
</template>
</test-fixture>
<script>
suite('basic', function() {
test('invalid input is not ok', function() {
var input = fixture('basic');
input.value='1234';
forceXIfStamp(input);
var container = Polymer.dom(input.root).querySelector('paper-input-container');
assert.ok(container, 'paper-input-container exists');
assert.isTrue(container.invalid);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).visibility, 'hidden', 'error is not visibility:hidden');
});
test('misformed dates are not ok', function() {
var input = fixture('basic');
input.value='33/33';
forceXIfStamp(input);
var container = Polymer.dom(input.root).querySelector('paper-input-container');
assert.ok(container, 'paper-input-container exists');
assert.isTrue(container.invalid);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).visibility, 'hidden', 'error is not visibility:hidden');
});
test('past dates are not ok', function() {
var input = fixture('basic');
input.value='11/00';
forceXIfStamp(input);
var container = Polymer.dom(input.root).querySelector('paper-input-container');
assert.ok(container, 'paper-input-container exists');
assert.isTrue(container.invalid);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.notEqual(getComputedStyle(error).visibility, 'hidden', 'error is not visibility:hidden');
});
test('future dates are ok', function() {
var input = fixture('basic');
// Note: this test will start failing in 2099. Apologies, future maintainers.
input.value='11/99';
forceXIfStamp(input);
var container = Polymer.dom(input.root).querySelector('paper-input-container');
assert.ok(container, 'paper-input-container exists');
assert.isFalse(container.invalid);
assert.equal(input.value, '11/99');
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.equal(getComputedStyle(error).visibility, 'hidden', 'error is visibility:hidden');
});
test('value is updated correctly ', function() {
var input = fixture('basic');
input.$$('.paper-input-input').month = 11;
input.$$('.paper-input-input').year = 15;
assert.equal(input.value, '11/15');
});
test('empty required input shows error on blur', function(done) {
var input = fixture('basic');
forceXIfStamp(input);
var error = Polymer.dom(input.root).querySelector('paper-input-error');
assert.ok(error, 'paper-input-error exists');
assert.equal(getComputedStyle(error).visibility, 'hidden', 'error is visibility:hidden');
input.addEventListener('blur', function(event) {
assert(!input.focused, 'input is blurred');
assert.notEqual(getComputedStyle(error).visibility, 'hidden', 'error is not visibility:hidden');
done();
});
MockInteractions.focus(input.inputElement);
MockInteractions.blur(input.inputElement);
});
test('placeholder shows correctly', function() {
var input = fixture('basic');
forceXIfStamp(input);
var dateInput = Polymer.dom(input.root).querySelector('date-input');
var month = Polymer.dom(dateInput.root).querySelector('#expirationMonth');
var year = Polymer.dom(dateInput.root).querySelector('#expirationYear');
assert.equal(month.placeholder, 'MM', 'month placeholder is MM');
assert.equal(year.placeholder, 'YY', 'year placeholder is YY');
});
test('/ key advances to year input', function() {
var input = fixture('basic');
forceXIfStamp(input);
var dateInput = Polymer.dom(input.root).querySelector('date-input');
var year = Polymer.dom(dateInput.root).querySelector('#expirationYear');
MockInteractions.pressAndReleaseKeyOn(dateInput, 191, [], '/');
assert.equal(Polymer.dom(dateInput.root).activeElement, year, 'year is focused');
});
});
suite('a11y', function() {
test('has aria-labelledby', function() {
var input = fixture('basic');
var dateInput = input.$$('.paper-input-input');
var month = dateInput.$$('input:nth-of-type(1)');
var year = dateInput.$$('input:nth-of-type(2)');
var label = Polymer.dom(input.root).querySelector('label').id;
assert.ok(month);
assert.ok(year);
assert.isTrue(month.hasAttribute('aria-labelledby'));
assert.isTrue(year.hasAttribute('aria-labelledby'));
assert.equal(month.getAttribute('aria-labelledby'), label + ' monthLabel');
assert.equal(year.getAttribute('aria-labelledby'), label + ' yearLabel');
});
});
</script>
</body>
</html>