-
Notifications
You must be signed in to change notification settings - Fork 78
/
wai-aria.html
498 lines (395 loc) · 17.7 KB
/
wai-aria.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../vaadin-date-picker.html">
<link rel="import" href="../vaadin-date-picker-light.html">
<link rel="import" href="../src/vaadin-date-picker-overlay.html">
<link rel="import" href="../src/vaadin-date-picker-overlay-content.html">
<link rel="import" href="../src/vaadin-month-calendar.html">
<link rel="import" href="not-animated-styles.html">
<script src="common.js"></script>
</head>
<body>
<test-fixture id="datepicker">
<template>
<vaadin-date-picker label="ariatest"></vaadin-date-picker>
</template>
</test-fixture>
<test-fixture id="datepickerLight">
<template>
<vaadin-date-picker-light>
<input>
</vaadin-date-picker-light>
</template>
</test-fixture>
<test-fixture id="overlay">
<template>
<vaadin-date-picker-overlay-content></vaadin-date-picker-overlay-content>
</template>
</test-fixture>
<test-fixture id="month-calendar">
<template>
<vaadin-month-calendar></vaadin-month-calendar>
</template>
</test-fixture>
<script>
describe('WAI-ARIA', () => {
describe('date picker', () => {
var datepicker, toggleButton, clearButton;
beforeEach(() => {
datepicker = fixture('datepicker');
const overlayContent = datepicker.$.overlay.content.querySelector('#overlay-content');
overlayContent.$.monthScroller.bufferSize = 0;
overlayContent.$.yearScroller.bufferSize = 0;
clearButton = datepicker.root.querySelector('[part="clear-button"]');
toggleButton = datepicker.root.querySelector('[part="toggle-button"]');
});
it('should have application role on input container', () => {
// Makes JAWS not to intercept arrow keys but pass them to the browser
// instead. Otherwise, the keyboard navigation is broken with JAWS.
expect(datepicker._inputElement.getAttribute('role')).to.equal('application');
});
it('should have button roles on buttons', () => {
// Indicate icon buttons as clickable. Especially helpful on touch devices.
expect(toggleButton.getAttribute('role')).to.equal('button');
expect(clearButton.getAttribute('role')).to.equal('button');
});
it('should have label properties on buttons', () => {
// Give spoken names for the icon buttons.
expect(toggleButton.getAttribute('aria-label')).to.equal('Calendar');
expect(clearButton.getAttribute('aria-label')).to.equal('Clear');
});
it('should have label properties on buttons in correct locale', () => {
datepicker.set('i18n.calendar', 'kalenteri');
datepicker.set('i18n.clear', 'tyhjennä');
expect(toggleButton.getAttribute('aria-label')).to.equal('kalenteri');
expect(clearButton.getAttribute('aria-label')).to.equal('tyhjennä');
});
it('should have expanded state false on calendar button', () => {
// Indicate that there is a collabsible calendar, closed by default.
expect(toggleButton.getAttribute('aria-expanded')).not.to.be.ok;
});
it('should have expanded state true on calendar button when opened', () => {
datepicker.open();
expect(toggleButton.getAttribute('aria-expanded')).to.equal('true');
});
it('should have label property on the input', () => {
expect(datepicker._inputElement.getAttribute('aria-label')).to.equal('ariatest');
});
});
describe('overlay contents', () => {
var overlay;
beforeEach(done => {
overlay = fixture('overlay');
overlay.$.monthScroller.bufferSize = 0;
overlay.$.yearScroller.bufferSize = 1;
overlay.i18n = getDefaultI18n();
setTimeout(done);
});
describe('title announcer', () => {
beforeEach(done => {
Polymer.RenderStatus.afterNextRender(overlay.$.scroller, () => {
setTimeout(() => {
done();
}, 1);
});
overlay.initialPosition = new Date();
});
// Title announcer notifies the user when the overlay opens with
// an explicit “<alert> Calender” announce.
it('should be present in the overlay', () => {
expect(overlay.$.announcer).to.be.ok;
});
it('should be the first child of the overlay', () => {
// Always introduce calendar contents with “Calendar”.
expect(overlay.root.querySelector(':not(style):not(:empty)')).to.equal(overlay.$.announcer);
});
it('should not have hidden state', () => {
// Otherwise is not spoken.
expect(overlay.$.announcer.getAttribute('aria-hidden')).to.not.equal('true');
});
it('should be visible', () => {
expect(overlay.$.announcer.offsetWidth).to.be.at.least(1);
expect(overlay.$.announcer.offsetHeight).to.be.at.least(1);
});
it('should have role alert', () => {
expect(overlay.$.announcer.getAttribute('role')).to.equal('alert');
});
it('should have live property polite', () => {
// By default alerts are assertive and interrupt screen readers.
// Polite mode makes the announce in normal order.
expect(overlay.$.announcer.getAttribute('aria-live')).to.equal('polite');
});
it('should have text', () => {
expect(overlay.$.announcer.textContent.trim()).to.equal('Calendar');
});
it('should have text in correct locale', () => {
overlay.set('i18n.calendar', 'kalenteri');
expect(overlay.$.announcer.textContent.trim()).to.equal('kalenteri');
});
});
describe('year scroller contents', () => {
var yearScrollerContents;
beforeEach(done => {
var scroller = overlay.$.yearScroller;
scroller.active = true;
scroller._reset();
Polymer.RenderStatus.afterNextRender(scroller, () => {
animationFrameFlush(function() {
scroller._debouncerUpdateClones.flush();
yearScrollerContents = overlay.$.yearScroller
.querySelectorAll('div > [part="year-number"]');
done();
});
});
});
it('should contain button role for years', () => {
// Indicate years as clickable.
var years = Array.prototype.filter.call(yearScrollerContents, el => {
return /\d+/.test(el.textContent);
});
expect(years).to.not.be.empty;
years.forEach(year => {
expect(year.getAttribute('role')).to.equal('button');
});
});
it('should have hidden state for dots', () => {
// Do not speak dots between years.
var dots = Array.prototype.slice.call(yearScrollerContents)
.map(el => el.nextElementSibling);
expect(dots).to.not.be.empty;
dots.forEach(dot => {
expect(dot.getAttribute('aria-hidden')).to.equal('true');
});
});
});
});
describe('month calendar contents', () => {
let monthCalendar;
beforeEach(done => {
monthCalendar = fixture('month-calendar');
monthCalendar.i18n = getDefaultI18n();
monthCalendar.month = new Date(2016, 1, 1);
setTimeout(done);
});
it('should have heading role on the title', () => {
// Consistency and convenience. Announces title as a header.
expect(monthCalendar.root.querySelector('[part="month-header"]').getAttribute('role')).to.equal('heading');
});
it('should have heading roles on the weekdays', () => {
// iOS VoiceOver bug: visible text is spoken instead of aria-label otherwise.
var weekdays = monthCalendar.root.querySelectorAll('[part="weekday"]:not(:empty)');
Array.prototype.forEach.call(weekdays, weekday => {
expect(weekday.getAttribute('role')).to.equal('heading');
});
});
it('should have label properties on the weekdays', () => {
// Speak week days with full words instead of acronyms.
var weekdays = monthCalendar.root.querySelectorAll('[part="weekday"]:not(:empty)');
var weekdayLabels = Array.prototype.map.call(weekdays, weekday => {
return weekday.getAttribute('aria-label');
});
expect(weekdayLabels).to.eql(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
});
it('should have button roles and labels on date cells', () => {
// The date cells should be spoken with a full date.
var dateElements = monthCalendar.root.querySelectorAll('[part="date"]:not(:empty)');
expect(dateElements).to.not.be.empty;
Array.prototype.forEach.call(dateElements, dateElement => {
expect(dateElement.getAttribute('role')).to.equal('button');
expect(dateElement.getAttribute('aria-label')).to.be.ok;
});
expect(dateElements[0].getAttribute('aria-label')).to.equal('1 February 2016, Monday');
expect(dateElements[1].getAttribute('aria-label')).to.equal('2 February 2016, Tuesday');
});
it('should indicate today on date cells', done => {
monthCalendar.month = new Date();
setTimeout(() => {
var todayElement = monthCalendar.root.querySelector('[part="date"]:not(:empty)[today]');
expect(todayElement.getAttribute('aria-label')).to.match(/, Today$/);
done();
});
});
it('should have disabled state on disabled date cells', () => {
// just [disabled] attribute is not enough for screen readers, should
// also contain aria-disabled="true".
monthCalendar.maxDate = new Date(2016, 1, 10); // 10 February 2016
var dateElements = monthCalendar.root.querySelectorAll('[part="date"]:not(:empty)');
expect(dateElements[9].getAttribute('aria-disabled')).to.not.equal('true');
expect(dateElements[10].getAttribute('aria-disabled')).to.equal('true');
});
it('should not have button roles and label properties on empty cells', () => {
// The empty cells should not be spoken.
var emptyDateElements = monthCalendar.root.querySelectorAll('[part="date"]:empty');
expect(emptyDateElements).to.not.be.empty;
Array.prototype.forEach.call(emptyDateElements, emptyDateElement => {
expect(emptyDateElement.getAttribute('role')).to.not.equal('button');
expect(emptyDateElement.getAttribute('aria-label')).to.not.be.ok;
});
});
it('should have presentation roles on empty date cells', () => {
var emptyDateElements = monthCalendar.root.querySelectorAll('[part="date"]:empty');
Array.prototype.forEach.call(emptyDateElements, emptyElement => {
expect(emptyElement.getAttribute('role')).to.equal('presentation');
expect(emptyElement.getAttribute('aria-label')).to.be.empty;
});
});
describe('week numbers', () => {
beforeEach(done => {
monthCalendar.showWeekNumbers = true;
monthCalendar.set('i18n.firstDayOfWeek', 1);
setTimeout(done);
});
it('should have heading roles on week numbers', () => {
// iOS VoiceOver bug: visible text is spoken instead of aria-label otherwise.
var weekNumberElements = monthCalendar.root.querySelectorAll('[part="week-number"]');
Array.prototype.forEach.call(weekNumberElements, weekNumberElement => {
expect(weekNumberElement.getAttribute('role')).to.equal('heading');
});
});
it('should have label properties on week numbers', () => {
var weekNumberElements = monthCalendar.root.querySelectorAll('[part="week-number"]');
expect(weekNumberElements[0].getAttribute('aria-label')).to.equal('Week 5');
expect(weekNumberElements[1].getAttribute('aria-label')).to.equal('Week 6');
});
});
});
describe('announcements', () => {
// NOTE: See <iron-a11y-announcer> API
var datepicker;
beforeEach(() => {
datepicker = fixture('datepicker');
const overlayContent = datepicker.$.overlay.content.querySelector('#overlay-content');
overlayContent.$.monthScroller.bufferSize = 0;
overlayContent.$.yearScroller.bufferSize = 0;
});
function waitForAnnounce(callback) {
var listener = event => {
document.body.removeEventListener('iron-announce', listener);
callback(event.detail.text);
};
document.body.addEventListener('iron-announce', listener);
}
it('should request availability from IronA11yAnnouncer', done => {
var spy = sinon.spy(Polymer.IronA11yAnnouncer, 'requestAvailability');
fixture('datepicker');
setTimeout(() => {
expect(spy.called).to.be.true;
done();
});
});
it('should announce focused date on open', done => {
waitForAnnounce(text => {
expect(text).to.equal('Monday 1 February 2016');
done();
});
datepicker._focusedDate = new Date(2016, 1, 1);
datepicker.open();
});
it('should announce focused date changes when opened', done => {
datepicker.open();
waitForAnnounce(text => {
expect(text).to.equal('Tuesday 2 February 2016');
done();
});
datepicker._focusedDate = new Date(2016, 1, 2);
});
it('should not announce focused date changes when closed', done => {
var announceSpy = sinon.spy();
document.body.addEventListener('iron-announce', announceSpy);
datepicker._focusedDate = new Date(2016, 1, 2);
expect(announceSpy.called).to.be.false;
document.body.removeEventListener('iron-announce', announceSpy);
done();
});
it('should announce value on open', done => {
waitForAnnounce(text => {
expect(text).to.equal('Monday 1 February 2016');
done();
});
datepicker.value = '2016-02-01';
datepicker.open();
});
it('should announce initial position on open', done => {
waitForAnnounce(text => {
expect(text).to.equal('Monday 1 February 2016');
done();
});
datepicker.initialPosition = '2016-02-01';
datepicker.open();
});
it('should announce today', done => {
waitForAnnounce(text => {
expect(text.indexOf('Today')).to.equal(0);
done();
});
datepicker.open();
});
it('should announce week numbers if enabled', done => {
datepicker._focusedDate = new Date(2016, 1, 1);
datepicker.showWeekNumbers = true;
datepicker.set('i18n.firstDayOfWeek', 1);
waitForAnnounce(text => {
expect(text).to.match(/ Week 5$/);
done();
});
datepicker.open();
});
if (!ios) {
it('should announce once', done => {
datepicker._focusedDate = new Date(2016, 1, 1);
open(datepicker, () => {
var announceSpy = sinon.spy();
document.body.addEventListener('iron-announce', announceSpy);
datepicker._focusedDate = new Date(2016, 1, 2);
setTimeout(() => {
expect(announceSpy.callCount).to.be.equal(1);
document.body.removeEventListener('iron-announce', announceSpy);
done();
}, 1);
});
});
}
describe('i18n', () => {
beforeEach(() => {
datepicker.set('i18n.monthNames',
'tammikuu_helmikuu_maaliskuu_huhtikuu_toukokuu_kesäkuu_heinäkuu_elokuu_syyskuu_lokakuu_marraskuu_joulukuu'.split('_'));
datepicker.set('i18n.weekdays', 'sunnuntai_maanantai_tiistai_keskiviikko_torstai_perjantai_lauantai'.split('_'));
datepicker.set('i18n.week', 'viikko');
datepicker.set('i18n.today', 'Tänään');
});
it('should announce dates in correct locale', done => {
waitForAnnounce(text => {
expect(text).to.equal('maanantai 1 helmikuu 2016');
done();
});
datepicker._focusedDate = new Date(2016, 1, 1);
datepicker.open();
});
it('should announce today in correct locale', done => {
waitForAnnounce(text => {
expect(text.indexOf('Tänään')).to.equal(0);
done();
});
datepicker.open();
});
it('should announce week numbers in correct locale', done => {
datepicker._focusedDate = new Date(2016, 1, 1);
datepicker.showWeekNumbers = true;
datepicker.set('i18n.firstDayOfWeek', 1);
waitForAnnounce(text => {
expect(text).to.match(/ viikko 5$/);
done();
});
datepicker.open();
});
});
});
});
</script>
</body>
</html>