Debian Codegraph @

dijit/tests/robot/Calendar_a11y.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>doh.robot Calendar A11Y Test</title>
6
7 <style>
8 @import "../../../util/doh/robot/robot.css";
9 </style>
10
11 <!-- required: dojo.js -->
12 <script type="text/javascript" src="../../../dojo/dojo.js"
13 data-dojo-config="isDebug: true"></script>
14
15 <script type="text/javascript">
16 require([
17 "doh/runner", "dojo/robotx",
18 "dojo/_base/array", "dojo/date", "dojo/date/locale", "dojo/dom", "dojo/keys", "dojo/_base/lang",
19 "dojo/query", "dojo/sniff",
20 "dijit/tests/helpers", "dojo/domReady!"
21 ], function(doh, robot, array, date, datelocale, dom, keys, lang, query, has, helpers){
22
23 robot.initRobot('../test_Calendar.html');
24
25 doh.register(function setup(){
26 // get pointer to registry in the iframe
27 registry = robot.window.require("dijit/registry");
28 dfocus = robot.window.require("dijit/focus");
29 });
30
31 // refs to Calendar widgets
32 var cal1, cal5;
33
34 // log of calls to onChange handler
35 var changes = [];
36
37 doh.register("API", [
38 function noValue(){
39 // refs to Calendar widget
40 cal1 = registry.byId('calendar1');
41
42 // Although Calendar and DateTextBox prototypes defined value as Date("")
43 // (so that the parser knows value is a Date rather than a string),
44 // the convention is to use null to represent a blank DateTextBox or Calendar w/no selection
45 doh.is(null, registry.byId("calendar1").get("value"), 'initial get("value"), no selection');
46
47 cal1.set("value", new Date(2009, 8, 16));
48 doh.is(0, date.compare(new Date(2009, 8, 16), cal1.get('value')), 'get("value") after set');
49
50 cal1.set("value", null);
51 doh.is(null, cal1.get("value"), 'get("value") after set to null');
52 },
53
54 function initialValue(){
55 cal5 = registry.byId("calendar5");
56
57 var selectedDate = query(".dijitCalendarSelectedDate", cal5.domNode);
58 doh.is(1, selectedDate.length, "date is selected");
59 doh.is("14", helpers.innerText(selectedDate[0]), "selected date");
60
61 var selectedMonth = query(".dijitCalendarCurrentMonthLabel", cal5.domNode);
62 doh.is(1, selectedMonth.length, "month is selected");
63 doh.is("March", helpers.innerText(selectedMonth[0]), "selected month");
64
65 var selectedYear = query(".dijitCalendarSelectedYear", cal5.domNode);
66 doh.is(1, selectedYear.length, "year is selected");
67 doh.is("2008", helpers.innerText(selectedYear[0]), "selected year");
68 }
69 ]);
70
71 // Test aria roles, etc.
72 doh.register("aria", function(){
73 // test all days are loaded correctly
74 var dateCells = registry.byId("calendar1").dateCells;
75 array.forEach(dateCells, function(cellNode){
76 doh.is("false", cellNode.getAttribute("aria-selected"), "aria-selected should be false at startup");
77 doh.is(undefined, cellNode.getAttribute("aria-disabled should be undefined at startup"), "aria-disabled");
78 });
79
80 // disable weekends
81 array.forEach(registry.toArray(), function(c){
82 if(c.isDisabledDate){
83 c.isDisabledDate = datelocale.isWeekend;
84 c._populateGrid();
85 }
86 });
87
88 // select a day
89 registry.byId("calendar1").set("value", new Date(2009, 8, 15));
90
91 array.forEach(dateCells, function(cellNode, index){
92 var selected = cellNode.getAttribute("aria-selected");
93 var disabled = cellNode.getAttribute("aria-disabled");
94 helpers.innerText(cellNode)==="15" ? doh.is("true", selected, "aria-selected should be true: "+helpers.innerText(cellNode))
95 : doh.is("false", selected, "aria-selected should still be true: "+helpers.innerText(cellNode));
96 (index%7==0) || (index%7==6) ? doh.is("true", disabled, "aria-disabled should be true for weekends: "+index)
97 : doh.t((disabled==undefined || disabled=="" || disabled=="false"), "aria-disabled should still be undefined, 'false', or ''. Index was: "+index+" Value was: "+disabled);
98 });
99
100 // enable all again
101 array.forEach(registry.toArray(), function(c){
102 if(c.isDisabledDate){
103 c.isDisabledDate = function(){return false;};
104 c._populateGrid();
105 }
106 });
107
108 // select a different day
109 registry.byId("calendar1").set("value", new Date(2009, 8, 17));
110
111 array.forEach(dateCells, function(cellNode, index){
112 var selected = cellNode.getAttribute("aria-selected");
113 var disabled = cellNode.getAttribute("aria-disabled");
114 helpers.innerText(cellNode)==="17" ? doh.is("true", selected, "aria-selected should be true for day 17: "+helpers.innerText(cellNode))
115 : doh.is("false", selected, "aria-selected should be false again: "+helpers.innerText(cellNode));
116 doh.t((disabled==undefined || disabled=="" || disabled=="false"), "aria-disabled should be undefined, 'false', or '' again");
117 });
118
119 });
120
121 // Tabindex test makes sure that there's exactly one tab stop on the calendar at all times
122 doh.register("tabindex", [
123 {
124 name: "forward",
125 timeout: 10000,
126 setUp: function(){
127 cal1.set("value", new Date(2009, 8, 16));
128
129 dom.byId("before").focus();
130 },
131 runTest: function(){
132 var d = new doh.Deferred();
133
134 // Tab in
135 robot.keyPress(keys.TAB, 1000, {});
136 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
137 doh.is(16, helpers.innerText(dfocus.curNode), "first tab goes to selected day");
138 })), 500);
139
140 // Move around some
141 robot.keyPress(keys.RIGHT_ARROW, 0, {});
142 robot.keyPress(keys.DOWN_ARROW, 500, {});
143 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
144 doh.is(24, helpers.innerText(dfocus.curNode), "move around some");
145 })), 500);
146
147 // Tab out
148 robot.keyPress(keys.TAB, 500, {});
149 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
150 doh.is("after", dfocus.curNode.id, "next tab leaves calendar");
151 })), 500);
152
153 return d;
154 }
155 },
156 {
157 name: "reverse",
158 timeout: 10000,
159 runTest: function(){
160 var d = new doh.Deferred();
161
162 // shift-tab back into calendar, should go to previously focused day
163 robot.keyPress(keys.TAB, 500, {shift: true});
164 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
165 doh.is(24, helpers.innerText(dfocus.curNode), "shift-tab returns to previously focused day");
166 })), 500);
167
168 // shift-tab out
169 robot.keyPress(keys.TAB, 500, {shift: true});
170 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
171 doh.is("before", dfocus.curNode.id, "next shift-tab leaves calendar");
172 })), 500);
173
174 return d;
175 }
176 },
177 {
178 name: "advance a month",
179 timeout: 10000,
180 runTest: function(){
181 var d = new doh.Deferred();
182
183 // Tab in
184 robot.keyPress(keys.TAB, 500, {});
185 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
186 doh.is(24, helpers.innerText(dfocus.curNode), "first tab goes to selected day");
187 })), 500);
188
189 // Move to next month
190 robot.keyPress(keys.PAGE_DOWN, 0, {});
191 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
192 doh.is(24, helpers.innerText(dfocus.curNode), "moved to same day, but new month");
193 })), 500);
194
195 // Tab out
196 robot.keyPress(keys.TAB, 500, {});
197 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
198 doh.is("after", dfocus.curNode.id, "next tab leaves calendar");
199 })), 500);
200
201 return d;
202 }
203 },
204 {
205 name: "reverse again",
206 timeout: 10000,
207 runTest: function(){
208 var d = new doh.Deferred();
209
210 // shift-tab back into calendar, should go to previously focused day
211 robot.keyPress(keys.TAB, 500, {shift: true});
212 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
213 doh.is(24, helpers.innerText(dfocus.curNode), "shift-tab returns to previously focused day");
214 })), 500);
215
216 // shift-tab out
217 robot.keyPress(keys.TAB, 500, {shift: true});
218 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
219 doh.is("before", dfocus.curNode.id, "next shift-tab leaves calendar");
220 })), 500);
221
222 return d;
223 }
224 }
225 ]);
226
227 // Make sure that all the navigation and selection keystrokes work
228 doh.register("navigation", [
229 {
230 name: "arrow navigation",
231 timeout: 10000,
232 setUp: function(){
233 // refs to Calendar widget
234 cal1 = registry.byId('calendar1');
235 cal1.set("value", new Date(2009, 8, 16));
236
237 // setup onChange handler to monitor onChange calls on cal1
238 cal1.on("change", function(val){
239 console.log('onchange w/value: ', val);
240 changes.push(val);
241 });
242 },
243 runTest: function(){
244 var d = new doh.Deferred();
245
246 robot.sequence(function(){
247 // monitor onchange events
248 changes = [];
249 cal1.focus();
250 }, 500);
251
252 // Initial conditions
253 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
254 // 16th is selected
255 var selected = query(".dijitCalendarSelectedDate", cal1.domNode);
256 doh.is(1, selected.length, "one selected node");
257 doh.is("16", helpers.innerText(selected[0]));
258
259 // initial focus is on selected value
260 doh.is("16", helpers.innerText(dfocus.curNode));
261
262 // and get("value") working
263 doh.is(0, date.compare(new Date(2009, 8, 16), cal1.get('value')), 'get("value")');
264 })), 1000);
265
266 // Mouse moves around focus without changing value
267 robot.keyPress(keys.RIGHT_ARROW, 500, {});
268 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
269 // focus moved from 16 to 17
270 doh.is(17, helpers.innerText(dfocus.curNode));
271
272 doh.is(0, date.compare(new Date(2009, 8, 16), cal1.get('value')), 'value unchanged');
273
274 // 16th is still selected
275 var selected = query(".dijitCalendarSelectedDate", cal1.domNode);
276 doh.is(1, selected.length, "one selected node");
277 doh.is("16", helpers.innerText(selected[0]));
278 })), 500);
279 robot.keyPress(keys.RIGHT_ARROW, 0, {});
280 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
281 doh.is(18, helpers.innerText(dfocus.curNode));
282 })), 500);
283 robot.keyPress(keys.DOWN_ARROW, 0, {});
284 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
285 doh.is(25, helpers.innerText(dfocus.curNode));
286 })), 500);
287 robot.keyPress(keys.LEFT_ARROW, 0, {});
288 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
289 doh.is(24, helpers.innerText(dfocus.curNode));
290 })), 500);
291 robot.keyPress(keys.UP_ARROW, 0, {});
292 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
293 doh.is(17, helpers.innerText(dfocus.curNode));
294 })), 500);
295 robot.keyPress(keys.UP_ARROW, 0, {});
296 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
297 doh.is(10, helpers.innerText(dfocus.curNode));
298 })), 500);
299 robot.keyPress(keys.ENTER, 0, {});
300
301 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
302 var value = cal1.get('value');
303 doh.is(0, date.compare(new Date(2009, 8, 10), value), 'actual value is ' + value);
304 doh.is(1, changes.length, 'onchange events');
305 doh.is(0, date.compare(new Date(2009, 8, 10), changes[0]),
306 'value reported by onchange: ' + changes[0] +
307 ', should be ' + new Date(2009, 8, 10));
308 })), 1000);
309 return d;
310 }
311 },
312 {
313 name: "month navigation",
314 timeout: 5000,
315 setUp: function(){
316 // refs to Calendar widget
317 cal1 = registry.byId('calendar1');
318 cal1.set("value", new Date(2008, 0, 31));
319 },
320 runTest: function(){
321 var d = new doh.Deferred();
322
323 robot.sequence(function(){
324 cal1.focus();
325 }, 500);
326
327 robot.keyPress(keys.PAGE_DOWN, 1000, {});
328 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
329 // focus moved from jan 31 to feb 29
330 doh.is(29, helpers.innerText(dfocus.curNode));
331
332 doh.is(0, date.compare(new Date(2008, 0, 31), cal1.get('value')), 'value unchanged (first page down)');
333
334 // month label should have changed
335 var monthLabel = query(".dijitCalendarCurrentMonthLabel", cal1.domNode);
336 doh.is(1, monthLabel.length, "one month label");
337 doh.is("February", helpers.innerText(monthLabel[0]));
338
339 // jan 31 from previous month still visible, should be shown as selected
340 var selected = query(".dijitCalendarSelectedDate", cal1.domNode);
341 doh.is(1, selected.length, "no selected node");
342 })), 500);
343
344 robot.keyPress(keys.PAGE_DOWN, 500, {});
345 robot.sequence(d.getTestErrback(lang.hitch(this, function(){
346 // focus moved from jan 31 to feb 29
347 doh.is(29, helpers.innerText(dfocus.curNode));
348
349 doh.is(0, date.compare(new Date(2008, 0, 31), cal1.get('value')), 'value unchanged (second page down)');
350
351 // since january no longer visible, no selected date should be visible
352 var selected = query(".dijitCalendarSelectedDate", cal1.domNode);
353 doh.is(0, selected.length, "no selected node");
354 })), 500);
355
356 robot.keyPress(keys.SPACE, 500, {});
357 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
358 var value = cal1.get('value');
359 doh.is(0, date.compare(new Date(2008, 2, 29), value), 'actual value is ' + value);
360 })), 1000);
361
362 return d;
363 }
364 },
365 {
366 name: "month+year navigation",
367 timeout: 5000,
368 setUp: function(){
369 // refs to Calendar widget
370 cal1 = registry.byId('calendar1');
371 cal1.set("value", new Date(2008, 1, 15));
372 },
373 runTest: function(){
374 var d = new doh.Deferred();
375
376 robot.sequence(function(){
377 cal1.focus();
378 }, 500);
379
380 robot.keyPress(keys.END, 1000, {});
381 // Chrome switches tabs with ctrl+page up/down (not even a keydown is generated), yet not Safari.
382 // I don't see a way to do feature-detection since browser window focus is lost.
383 robot.keyPress(keys.PAGE_DOWN, 500, has("chrome") ? {alt:true} : {ctrl:true});
384 robot.keyPress(keys.PAGE_UP, 500, has("chrome") ? {alt:true} : {ctrl:true});
385 robot.keyPress(keys.PAGE_UP, 500, has("chrome") ? {alt:true} : {ctrl:true});
386 robot.keyPress(keys.ENTER, 500);
387
388 robot.sequence(d.getTestCallback(lang.hitch(this, function(){
389 var value = cal1.get('value');
390 doh.is(0, date.compare(new Date(2007, 1, 28), value), 'actual value is ' + value);
391 })), 1000);
392
393 return d;
394 }
395 }
396 ]);
397
398 doh.run();
399 });
400 </script>
401 </head>
402 </html>