Debian Codegraph @

dijit/tests/form/robot/DateTextBox.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 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>doh.robot DateTextBox Test</title>
7
8 <style>
9 @import "../../../../util/doh/robot/robot.css";
10 </style>
11
12 <!-- required: dojo.js -->
13 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
14
15 <script type="text/javascript">
16 dojo.require("dijit.robotx");
17 dojo.require("dojo.date");
18 dojo.require("dijit.tests.helpers"); // functions to help test
19
20 dojo.ready(function(){
21 doh.robot.initRobot('../test_DateTextBox.html');
22
23 // refs to DateTextBox widgets
24 var american, german, localLong, pattern, handler;
25
26 // log of calls to onChange handler, and watch(value)
27 var changes = [], watches = [];
28
29 // ctrl-page-down / page-up will go forward/barck a year, except on chrome where
30 // it switches browser tabs. use alt instead
31 var yearModifierKey = dojo.isChrome ? {alt: true} : {ctrl: true};
32
33 doh.register("setup",
34 function setUp(){
35 // refs to DateTextBox widgets
36 american = dijit.byId('american');
37 german = dijit.byId('german');
38 localLong = dijit.byId('localLong');
39 pattern = dijit.byId('pattern');
40
41 // setup onChange handler to monitor onChange calls on american textbox
42 dojo.connect(american, 'onChange', function(val){
43 console.log('onchange w/value: ', val);
44 changes.push(val);
45 });
46
47 american.watch("value", function(attr, oldV, newV){
48 watches.push(newV);
49 });
50 }
51 );
52
53 doh.register("keyboard: direct input", {
54 name: "direct input",
55 timeout: 6000,
56 setUp: function(){
57 // clear the field
58 changes = [];
59 watches = [];
60 american.focus();
61 },
62 runTest: function(){
63 var d = new doh.Deferred(),
64 r1 = true,
65 r2 = true,
66 r3 = true,
67 r4 = true,
68 r5 = true,
69 r6 = false,
70 r7 = false,
71 r8 = true;
72
73 handler = dojo.connect(american, 'onChange', d.getTestCallback(function(){
74 doh.f(r1, "1 out of range");
75 doh.f(r2, "1/ out of range");
76 doh.f(r3, "1/3 out of range");
77 doh.f(r4, "1/3/ out of range");
78 doh.f(r5, "1/3/2 out of range");
79 doh.t(r6, "1/3/20 in range");
80 doh.t(r7, "1/3/200 in range");
81 doh.f(r8, "1/3/2005 out of range");
82 var value = american.get('value');
83 doh.is(0, dojo.date.compare(new Date(2005, 0, 3), value), 'actual value is ' + value);
84 doh.is(1, changes.length, 'one onchange event'); // #9018
85 doh.is(2, watches.length, 'one watch(value) event from the onblur');
86 doh.is(0, dojo.date.compare(new Date(2005, 0, 3), changes[0]),
87 'value reported by onchange: ' + changes[0] +
88 ', should be ' + new Date(2005, 0, 3));
89 doh.is(0, dojo.date.compare(new Date(2005, 0, 3), watches[1]),
90 'value reported by watch(value): ' + watches[1] +
91 ', should be ' + new Date(2005, 0, 3));
92 }));
93
94 american.set('value', null, false);
95
96 doh.robot.typeKeys('1', 1000, 200);
97 doh.robot.sequence(function(){
98 r1 = american._isDefinitelyOutOfRange();
99 }, 100);
100 doh.robot.typeKeys('/', 100, 200);
101 doh.robot.sequence(function(){
102 r2 = american._isDefinitelyOutOfRange();
103 }, 100);
104 doh.robot.typeKeys('3', 100, 200);
105 doh.robot.sequence(function(){
106 r3 = american._isDefinitelyOutOfRange();
107 }, 100);
108 doh.robot.typeKeys('/', 100, 200);
109 doh.robot.sequence(function(){
110 r4 = american._isDefinitelyOutOfRange();
111 }, 100);
112 doh.robot.typeKeys('2', 100, 200);
113 doh.robot.sequence(function(){
114 r5 = american._isDefinitelyOutOfRange();
115 }, 100);
116 doh.robot.typeKeys('0', 100, 200);
117 doh.robot.sequence(function(){
118 r6 = american._isDefinitelyOutOfRange();
119 }, 100);
120 doh.robot.typeKeys('0', 100, 200);
121 doh.robot.sequence(function(){
122 r7 = american._isDefinitelyOutOfRange();
123 }, 100);
124 doh.robot.typeKeys('5', 100, 200);
125 doh.robot.sequence(function(){
126 r8 = american._isDefinitelyOutOfRange();
127 }, 100);
128
129 doh.robot.keyPress(dojo.keys.TAB, 500, {}); // focus german
130
131 return d;
132 },
133 tearDown: function(){
134 dojo.disconnect(handler);
135 }
136 });
137
138 doh.register("keyboard: drop down", [
139 {
140 name: "initial popup display",
141 timeout: 6000,
142 setUp: function(){
143 // set to may 10
144 changes = [];
145 american.set('displayedValue', "", false);
146 watches = []; // put after set() so we can ignore the watch() published by set()
147 american.focus();
148 },
149 runTest: function(){
150 var d = new doh.Deferred(),
151 calendar;
152
153 handler = dojo.connect(american, 'openDropDown', function(){
154 dojo.disconnect(handler);
155 calendar = dijit.byId("american_popup");
156 handler = dojo.connect(calendar, 'focus', function(){
157 // Use setTimeout() because focus on IE9+ is asynchronous.
158 setTimeout(d.getTestCallback(function(){
159 // calendar exists and is shown
160 doh.t(calendar && isVisible(calendar), "calendar is visible");
161
162 // calendar is on the right month
163 doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box");
164
165 // and the right year
166 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
167 doh.is(1, selectedYearButtons.length, "current year is shown");
168 doh.is("2005", innerText(selectedYearButtons[0]), "current year is 2005");
169
170 // and the currently selected date is right too
171 var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode);
172 doh.is(1, selectedDays.length, "one day selected");
173 doh.is("10", innerText(selectedDays[0]), "correct day is selected");
174
175 // focus moved to the calendar
176 doh.is(10, innerText(dojo.global.dijit.focus.curNode), "focus on selected calendar cell");
177
178 doh.is(0, changes.length, "no onchange events yet");
179 doh.is(0, watches.length, "no watch(value) events yet");
180 }), 0);
181 });
182 });
183
184 doh.robot.typeKeys("5/10/2005", 1000, 1800);
185 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 700, {});
186
187 return d;
188 },
189 tearDown: function(){
190 dojo.disconnect(handler);
191 }
192 },
193
194 {
195 name: "forward two days",
196 timeout: 6000,
197 runTest: function(){
198 var d = new doh.Deferred();
199 var calendar = dijit.byId("american_popup");
200
201 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
202 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
203
204 doh.robot.sequence(d.getTestCallback(function(){
205 // calendar still exists and is shown
206 doh.t(calendar, "calendar popup exists");
207 doh.t(isVisible(calendar), "calendar is visible");
208
209 // selected day not changed (because no ENTER/SPACE)
210 var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode);
211 doh.is(1, selectedDays.length, "one day selected");
212 doh.is(10, innerText(selectedDays[0]), "correct day is selected");
213
214 // focus still on the calendar, moved forward 2 days
215 doh.is(12, innerText(dojo.global.dijit.focus.curNode), "focus");
216
217 doh.is(0, changes.length, "no onchange events yet");
218 doh.is(0, watches.length, "no watch(value) events yet");
219 }), 1000);
220
221 return d;
222 }
223 },
224
225 {
226 name: "back a day",
227 timeout: 6000,
228 runTest: function(){
229 var d = new doh.Deferred();
230 var calendar = dijit.byId("american_popup");
231
232 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
233
234 doh.robot.sequence(d.getTestCallback(function(){
235 // calendar still exists and is shown
236 doh.t(calendar, "calendar popup exists");
237 doh.t(isVisible(calendar), "calendar is visible");
238
239 // focus still on the calendar, moved back 1 day
240 doh.is(11, innerText(dojo.global.dijit.focus.curNode), "focus");
241
242 doh.is(0, changes.length, "no onchange events yet");
243 doh.is(0, watches.length, "no watch(value) events yet");
244 }), 1000);
245
246 return d;
247 }
248 },
249
250 {
251 name: "forward four weeks",
252 timeout: 6000,
253 runTest: function(){
254 var d = new doh.Deferred();
255 var calendar = dijit.byId("american_popup");
256
257 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {});
258 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {});
259 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {});
260 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 750, {});
261
262 doh.robot.sequence(d.getTestCallback(function(){
263 // calendar still exists and is shown
264 doh.t(calendar, "calendar popup exists");
265 doh.t(isVisible(calendar), "calendar is visible");
266
267 // should have advanced to next month
268 doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed");
269
270 // and focused day changed
271 doh.is(8, innerText(dojo.global.dijit.focus.curNode), "focus");
272
273 doh.is(0, changes.length, "no onchange events yet");
274 doh.is(0, watches.length, "no watch(value) events yet");
275 }), 1000);
276
277 return d;
278 }
279 },
280
281 {
282 name: "back three weeks",
283 timeout: 6000,
284 runTest: function(){
285 var d = new doh.Deferred();
286 var calendar = dijit.byId("american_popup");
287
288 doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {});
289 doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {});
290 doh.robot.keyPress(dojo.keys.UP_ARROW, 750, {});
291
292 doh.robot.sequence(d.getTestCallback(function(){
293 // calendar still exists and is shown
294 doh.t(calendar, "calendar popup exists");
295 doh.t(isVisible(calendar), "calendar is visible");
296
297 // should have scrolled back to previous month
298 doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed");
299
300 // focused day still the same
301 doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus");
302
303 doh.is(0, changes.length, "no onchange events yet");
304 doh.is(0, watches.length, "no watch(value) events yet");
305 }), 1000);
306
307 return d;
308 }
309 },
310
311 {
312 name: "forward two months",
313 timeout: 6000,
314 runTest: function(){
315 var d = new doh.Deferred();
316 var calendar = dijit.byId("american_popup");
317
318 doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, {});
319 doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, {});
320
321 doh.robot.sequence(d.getTestCallback(function(){
322 // calendar still exists and is shown
323 doh.t(calendar, "calendar popup exists");
324 doh.t(isVisible(calendar), "calendar is visible");
325
326 // focused day still the same
327 doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus");
328
329 // month changed
330 doh.is("July", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed");
331
332 doh.is(0, changes.length, "no onchange events yet");
333 doh.is(0, watches.length, "no watch(value) events yet");
334 }), 1000);
335
336 return d;
337 }
338 },
339
340 {
341 name: "back a month",
342 timeout: 6000,
343 runTest: function(){
344 var d = new doh.Deferred();
345 var calendar = dijit.byId("american_popup");
346
347 doh.robot.keyPress(dojo.keys.PAGE_UP, 750, {});
348
349 doh.robot.sequence(d.getTestCallback(function(){
350 // calendar still exists and is shown
351 doh.t(calendar, "calendar popup exists");
352 doh.t(isVisible(calendar), "calendar is visible");
353
354 // focused day still the same
355 doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus");
356
357 // month changed
358 doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "month changed");
359
360 doh.is(0, changes.length, "no onchange events yet");
361 doh.is(0, watches.length, "no watch(value) events yet");
362 }), 1000);
363
364 return d;
365 }
366 },
367
368 {
369 name: "forward two years",
370 timeout: 6000,
371 runTest: function(){
372 var d = new doh.Deferred();
373 var calendar = dijit.byId("american_popup");
374
375 doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, yearModifierKey);
376 doh.robot.keyPress(dojo.keys.PAGE_DOWN, 750, yearModifierKey);
377
378 doh.robot.sequence(d.getTestCallback(function(){
379 // calendar still exists and is shown
380 doh.t(calendar, "calendar popup exists");
381 doh.t(isVisible(calendar), "calendar is visible");
382
383 // focused day still the same (focused even though disabled)
384 doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus");
385
386 // same month
387 doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "same month");
388
389 // year changed
390 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
391 doh.is(1, selectedYearButtons.length, "current year is shown");
392 doh.is("2007", innerText(selectedYearButtons[0]), "year changed");
393
394 doh.is(0, changes.length, "no onchange events yet");
395 doh.is(0, watches.length, "no watch(value) events yet");
396 }), 1000);
397
398 return d;
399 }
400 },
401
402 {
403 name: "back a year",
404 timeout: 6000,
405 runTest: function(){
406 var d = new doh.Deferred();
407 var calendar = dijit.byId("american_popup");
408
409 doh.robot.keyPress(dojo.keys.PAGE_UP, 750, yearModifierKey);
410
411 doh.robot.sequence(d.getTestCallback(function(){
412 // calendar still exists and is shown
413 doh.t(calendar, "calendar popup exists");
414 doh.t(isVisible(calendar), "calendar is visible");
415
416 // focused day still the same
417 doh.is(18, innerText(dojo.global.dijit.focus.curNode), "focus");
418
419 // same month
420 doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "same month");
421
422 // year changed
423 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
424 doh.is(1, selectedYearButtons.length, "current year is shown");
425 doh.is("2006", innerText(selectedYearButtons[0]), "year changed");
426
427 doh.is(0, changes.length, "no onchange events yet");
428 doh.is(0, watches.length, "no watch(value) events yet");
429 }), 1000);
430
431 return d;
432 }
433 },
434
435 {
436 name: "first day of month",
437 timeout: 6000,
438 runTest: function(){
439 var d = new doh.Deferred();
440 var calendar = dijit.byId("american_popup");
441
442 doh.robot.keyPress(dojo.keys.HOME, 500, {});
443
444 doh.robot.sequence(d.getTestCallback(function(){
445 // calendar still exists and is shown
446 doh.t(calendar, "calendar popup exists");
447 doh.t(isVisible(calendar), "calendar is visible");
448
449 // focused on first day of month
450 doh.is(1, innerText(dojo.global.dijit.focus.curNode), "focus");
451
452 doh.is(0, changes.length, "no onchange events yet");
453 doh.is(0, watches.length, "no watch(value) events yet");
454 }), 1000);
455
456 return d;
457 }
458 },
459
460 {
461 name: "last day of month",
462 timeout: 6000,
463 runTest: function(){
464 var d = new doh.Deferred();
465 var calendar = dijit.byId("american_popup");
466
467 doh.robot.keyPress(dojo.keys.END, 500, {});
468
469 doh.robot.sequence(d.getTestCallback(function(){
470 // calendar still exists and is shown
471 doh.t(calendar, "calendar popup exists");
472 doh.t(isVisible(calendar), "calendar is visible");
473
474 // focused on last day of month
475 doh.is(30, innerText(dojo.global.dijit.focus.curNode), "focus");
476
477 doh.is(0, changes.length, "no onchange events yet");
478 doh.is(0, watches.length, "no watch(value) events yet");
479 }), 1000);
480
481 return d;
482 }
483 },
484
485 {
486 name: "select a date",
487 timeout: 6000,
488 runTest: function(){
489 var d = new doh.Deferred();
490
491 // select
492 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
493
494 doh.robot.sequence(d.getTestCallback(function(){
495 doh.is('6/30/2006', american.get('displayedValue'), 'displayed value of american');
496
497 var expectedVal = new Date(2006, 5, 30); // 6/30/2006
498 doh.is(0, dojo.date.compare(expectedVal, american.get('value')), 'wire value of american: ' + american.get('value'));
499
500 doh.is(1, changes.length, "onchange event fired");
501 doh.is(1, watches.length, "watch(value) event fired");
502 doh.is(0, dojo.date.compare(expectedVal, changes[0]), 'onchange of american: ' + changes[0]);
503 doh.is(0, dojo.date.compare(expectedVal, watches[0]), 'watch(value) of american: ' + watches[0]);
504
505 // focus moved back to <input>
506 doh.is("american", dojo.global.dijit.focus.curNode.id, "focus on <input>")
507 }), 1000);
508
509 return d;
510 }
511 },
512
513 {
514 name: "tab away",
515 timeout: 6000,
516 runTest: function(){
517 var d = new doh.Deferred();
518
519 handler = dojo.connect(american, '_onFocus', d.getTestCallback(function(){
520 doh.is(1, changes.length, "no new onchange events"); // #9018
521 doh.is(1, watches.length, "no new watch(value) events yet");
522 }));
523
524 doh.robot.keyPress(dojo.keys.TAB, 500, {});
525 doh.robot.keyPress(dojo.keys.TAB, 500, {shift:true});
526
527 return d;
528 },
529 tearDown: function(){
530 dojo.disconnect(handler);
531 }
532 }
533 ]);
534
535 // TODO: add key-repeat tests
536
537 doh.register("mouse: drop down", [
538 {
539 name: "initial popup display",
540 timeout: 6000,
541 setUp: function(){
542 // clear the field
543 changes = [];
544 american.set('displayedValue', "", false);
545 watches = []; // do it here to ignore watch() notification for above set() call
546 },
547 runTest: function(){
548 var d = new doh.Deferred();
549
550 handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){
551 var calendar = dijit.byId("american_popup");
552
553 // drop down automatically opened on click
554 doh.t(calendar && isVisible(calendar), "calendar is visible");
555
556 doh.is(0, changes.length, "no onchange events yet");
557 doh.is(0, watches.length, "no watch(value) events yet");
558 }));
559
560 doh.robot.mouseMoveAt(american._buttonNode, 0, 1);
561 doh.robot.mouseClick({left:true}, 500);
562
563 return d;
564 },
565 tearDown: function(){
566 dojo.disconnect(handler);
567 }
568 },
569
570 {
571 name: "close and reopen",
572 timeout: 6000,
573 runTest: function(){
574 var d = new doh.Deferred();
575
576 handler = dojo.connect(american, 'closeDropDown', function(){
577 dojo.disconnect(handler);
578
579 handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){
580 var calendar = dijit.byId("american_popup");
581
582 // calendar exists and is shown
583 doh.t(calendar && isVisible(calendar), "calendar is visible");
584
585 // calendar is on the right month
586 doh.is("May", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box");
587
588 // and the right year
589 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
590 doh.is(1, selectedYearButtons.length, "current year is shown");
591 doh.is("2005", innerText(selectedYearButtons[0]), "current year is 2005");
592
593 // and the currently selected date is right too
594 var selectedDays = dojo.query(".dijitCalendarSelectedDate", calendar.domNode);
595 doh.is(1, selectedDays.length, "one day selected");
596 doh.is("10", innerText(selectedDays[0]), "correct day is selected");
597
598 doh.is(0, changes.length, "no onchange events yet");
599 doh.is(0, watches.length, "no watch(value) events yet");
600 }));
601
602 // type a value
603 doh.robot.typeKeys("5/10/2005", 500, 1800);
604 // And open dropdown again (manually)
605 doh.robot.mouseMoveAt(american._buttonNode, 500, 1);
606 doh.robot.mouseClick({left:true}, 500);
607 });
608
609 // Close drop down
610 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
611
612 return d;
613 },
614 tearDown: function(){
615 dojo.disconnect(handler);
616 }
617 },
618
619 {
620 name: "advance a month",
621 timeout: 6000,
622 runTest: function(){
623 var d = new doh.Deferred();
624 var calendar = dijit.byId("american_popup"),
625 nextMonthButtons = dojo.query(".dijitCalendarIncrease", calendar.domNode);
626
627 doh.is(1, nextMonthButtons.length, "found next month button");
628
629 doh.robot.mouseMoveAt(nextMonthButtons[0], 100, 1); // delay to allow previous keyUp to occur
630 doh.robot.mouseClick({left:true}, 500);
631
632 doh.robot.sequence(d.getTestCallback(function(){
633 // calendar still exists and is shown
634 doh.t(calendar && isVisible(calendar), "calendar is visible");
635
636 // calendar moved to the next month
637 doh.is("June", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from may to june");
638
639 doh.is(0, changes.length, "no onchange events yet");
640 doh.is(0, watches.length, "no watch(value) events yet");
641 }), 1000);
642
643 return d;
644 }
645 },
646
647 {
648 name: "advance a month with the menu dropdown",
649 timeout: 6000,
650 runTest: function(){
651 var d = new doh.Deferred();
652 var calendar = dijit.byId("american_popup");
653
654 doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label");
655 doh.t(calendar.monthWidget.dropDown, "month dropdown exists");
656 doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible");
657
658 doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1);
659 doh.robot.mouseClick({left:true}, 500);
660
661 doh.robot.mouseMoveAt(function(){
662 return dojo.query("[month=6]", calendar.monthWidget.dropDown.domNode)[0];
663 }, 1000, 1);
664 doh.robot.mouseClick({left:true}, 500);
665
666 doh.robot.sequence(d.getTestCallback(function(){
667 // calendar still exists and is shown
668 doh.t(calendar && isVisible(calendar), "calendar is visible");
669
670 // calendar moved to the next month
671 doh.is("July", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from june to july");
672 var rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode),
673 firstRowDays = dojo.query("TD", rows[0]);
674 doh.is(7, firstRowDays.length, "7 days in first row");
675 doh.t(dojo.hasClass(firstRowDays[0], "dijitCalendarPreviousMonth"), "previous month class applied");
676 doh.is("26", innerText(firstRowDays[0]), "first day is june 26");
677 doh.is("1", innerText(firstRowDays[5]), "sixth day is june 1");
678
679 doh.is(0, changes.length, "no onchange events yet");
680 doh.is(0, watches.length, "no watch(value) events yet");
681 }), 1000);
682
683 return d;
684 }
685 },
686
687 {
688 name: "advance a year",
689 timeout: 6000,
690 runTest: function(){
691 var d = new doh.Deferred();
692
693 var calendar = dijit.byId("american_popup"),
694 nextYearButtons = dojo.query(".dijitCalendarNextYear", calendar.domNode);
695
696 doh.is(1, nextYearButtons.length, "found next year button");
697
698 doh.robot.mouseMoveAt(nextYearButtons[0], 0, 1);
699 doh.robot.mouseClick({left:true}, 500);
700
701 doh.robot.sequence(d.getTestCallback(function(){
702 // calendar still exists and is shown
703 doh.t(calendar && isVisible(calendar), "calendar is visible");
704
705 // calendar moved to the next year
706 var yearNodes = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
707 doh.is(1, yearNodes.length, "found year node");
708 doh.is("2006", innerText(yearNodes[0]), "moved from 2005 to 2006");
709
710 doh.is(0, changes.length, "no onchange events yet");
711 doh.is(0, watches.length, "no watch(value) events yet");
712 }), 1000);
713
714 return d;
715 }
716 },
717
718 {
719 name: "check disabled dates",
720 timeout: 6000,
721 runTest: function(){
722 var d = new doh.Deferred();
723
724 // Move forward another year, to see disabled days (this date text box is valid only to 2006)
725 var calendar = dijit.byId("american_popup"),
726 nextYearButtons = dojo.query(".dijitCalendarNextYear", calendar.domNode);
727
728 doh.is(1, nextYearButtons.length, "found next year button");
729
730 doh.robot.mouseMoveAt(nextYearButtons[0], 0, 1);
731 doh.robot.mouseClick({left:true}, 500);
732
733 doh.robot.sequence(d.getTestCallback(function(){
734 dojo.query(".dijitCalendarDateTemplate", calendar.domNode).forEach(function(node){
735 doh.t(dojo.hasClass(node, 'dijitCalendarDisabledDate'), 'every day in 2007 is disabled');
736 });
737 doh.is(0, changes.length, "no onchange events yet");
738 doh.is(0, watches.length, "no watch(value) events yet");
739 }), 500);
740
741 return d;
742 }
743 },
744
745 {
746 name: "check enabled dates",
747 timeout: 6000,
748 runTest: function(){
749 var d = new doh.Deferred();
750
751 // Move back a year, dates should be enabled again
752 var calendar = dijit.byId("american_popup"),
753 previousYearButtons = dojo.query(".dijitCalendarPreviousYear", calendar.domNode);
754
755 doh.is(1, previousYearButtons.length, "found previous year button");
756
757 doh.robot.mouseMoveAt(previousYearButtons[0], 0, 1);
758 doh.robot.mouseClick({left:true}, 500);
759
760 doh.robot.sequence(d.getTestCallback(function(){
761 dojo.query(".dijitCalendarDateTemplate", calendar.domNode).forEach(function(node){
762 doh.f(dojo.hasClass(node, 'dijitCalendarDisabledDate'), "every day in 2006 is enabled");
763 });
764 doh.is(0, changes.length, "no onchange events yet");
765 doh.is(0, watches.length, "no watch(value) events yet");
766 }), 500);
767
768 return d;
769 }
770 },
771
772 {
773 name: "check calendar display",
774 timeout: 6000,
775 runTest: function(){
776 var calendar = dijit.byId("american_popup"),
777 rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode);
778
779 doh.is(6, rows.length, "six weeks shown");
780 var firstRowDays = dojo.query("TD", rows[0]);
781 doh.is(7, firstRowDays.length, "7 days in first row");
782 doh.t(dojo.hasClass(firstRowDays[0], "dijitCalendarPreviousMonth"), "previous month class applied");
783 doh.is("25", innerText(firstRowDays[0]), "first day is june 25");
784 doh.is("1", innerText(firstRowDays[6]), "seventh day is july 1");
785
786 var lastRowDays = dojo.query("TD", rows[5]);
787 doh.t(dojo.hasClass(lastRowDays[3], 'dijitCalendarNextMonth'), "last row is for next month");
788 doh.is(0, changes.length, "no onchange events yet");
789 doh.is(0, watches.length, "no watch(value) events yet");
790 }
791 },
792
793 {
794 name: "hover a date",
795 timeout: 6000,
796 runTest: function(){
797 var d = new doh.Deferred();
798
799 var calendar = dijit.byId("american_popup"),
800 rows = dojo.query("TR.dijitCalendarWeekTemplate", calendar.domNode),
801 thirdRowDays = dojo.query("TD", rows[2]),
802 day = thirdRowDays[6];
803
804 // hover June 15
805 doh.is("15", innerText(day), "found july 15");
806 doh.robot.mouseMoveAt(day, 0, 1);
807
808 doh.robot.sequence(d.getTestCallback(function(){
809 doh.t(dojo.hasClass(day, 'dijitCalendarHoveredDate'), "hovered date has hover class");
810 doh.is(0, changes.length, "no onchange events yet");
811 doh.is(0, watches.length, "no watch(value) events yet");
812 }), 500);
813
814 return d;
815 }
816 },
817
818 {
819 name: "select a date",
820 timeout: 6000,
821 runTest: function(){
822 var d = new doh.Deferred();
823
824 // select June 15
825 doh.robot.mouseClick({left:true}, 500);
826
827 doh.robot.sequence(d.getTestCallback(function(){
828 doh.is('7/15/2006', american.get('displayedValue'), 'displayed value of american');
829
830 var expectedVal = new Date(2006, 6, 15); // 7/15/2006
831 doh.is(0, dojo.date.compare(expectedVal, american.get('value')), 'wire value of american: ' + american.get('value'));
832
833 doh.is(1, changes.length, "onchange event fired");
834 doh.is(1, watches.length, "watch(value) event fired");
835 doh.is(0, dojo.date.compare(expectedVal, changes[0]), 'onchange of american: ' + changes[0]);
836 doh.is(0, dojo.date.compare(expectedVal, watches[0]), 'watch(value) of american: ' + watches[0]);
837 }), 1000);
838
839 return d;
840 }
841 },
842
843 {
844 name: "tab away",
845 timeout: 6000,
846 runTest: function(){
847 var d = new doh.Deferred();
848
849 doh.robot.keyPress(dojo.keys.TAB, 500, {});
850
851 doh.robot.sequence(d.getTestCallback(function(){
852 doh.is(1, changes.length, "no new onchange events"); // #9018
853 doh.is(1, watches.length, "no new watch(value) events");
854 }), 1000);
855 return d;
856 }
857 }
858 ]);
859
860 // Tests that drop down displays correct year/month, and that correct cell is focused,
861 // based on this.value and this.dropDownDefaultValue
862 doh.register("focused popup value", [
863 {
864 name: "today",
865 timeout: 6000,
866 setUp: function(){
867 german.closeDropDown(true); // close drop down and focus widget
868 german.set('value', null);
869 german.set("dropDownDefaultValue", null);
870 },
871 runTest: function(){
872 var d = new doh.Deferred();
873
874 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
875
876 doh.robot.sequence(d.getTestCallback(function(){
877 var today = new Date();
878
879 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode);
880 doh.is(today.getFullYear(), innerText(selectedYearButtons[0]), "current year is selected");
881
882 var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode);
883 doh.is(0, selectedDates.length, "no selected date");
884 }), 500);
885
886 return d;
887 }
888 },
889 {
890 name: "dropDownDefaultValue",
891 timeout: 6000,
892 setUp: function(){
893 german.closeDropDown(true);
894 german.set('value', null);
895 german.set("dropDownDefaultValue", new Date(2000,11,21));
896 },
897 runTest: function(){
898 var d = new doh.Deferred();
899
900 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
901
902 doh.robot.sequence(d.getTestCallback(function(){
903 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode);
904 doh.is("2000", innerText(selectedYearButtons[0]), "specified default year is selected");
905
906 var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode);
907 doh.is(0, selectedDates.length, "no selected date");
908
909 doh.is("21", innerText(dojo.global.dijit.focus.curNode), "but focused on the 21st");
910 }), 500);
911
912 return d;
913 }
914 },
915
916 // Testing that value overrides dropDownDefaultValue
917 {
918 name: "textbox value",
919 timeout: 6000,
920 setUp: function(){
921 german.closeDropDown(true);
922 german.set("dropDownDefaultValue", new Date(2000,11,21));
923 german.set('value', new Date(2004,10,25));
924 },
925 runTest: function(){
926 var d = new doh.Deferred();
927
928 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
929
930 doh.robot.sequence(d.getTestCallback(function(){
931 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", german.dropDown.domNode);
932 doh.is("2004", innerText(selectedYearButtons[0]), "textbox year is selected");
933
934 var selectedDates = dojo.query(".dijitCalendarSelectedDate", german.dropDown.domNode);
935 doh.is(1, selectedDates.length, "one selected date");
936 doh.is("25", innerText(selectedDates[0]), "25th is selected");
937
938 doh.is("25", innerText(dojo.global.dijit.focus.curNode), "and also focused on the 25th");
939 }), 500);
940
941 return d;
942 }
943 },
944 {
945 name: "close",
946 timeout: 3000,
947 runTest: function(){
948 var d = new doh.Deferred();
949 handler = dojo.connect(german, 'closeDropDown', d.getTestCallback(function(){}));
950 // Close the drop down so it doesn't interfere with the next test by covering up the
951 // <input> that we want to focus.
952 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
953 return d;
954 },
955 tearDown: function(){
956 dojo.disconnect(handler);
957 }
958 }
959 ]);
960
961 // Testing that canceling an edit doesn't select anything
962 doh.register("cancel edit", {
963 name: "no value",
964 timeout: 6000,
965 runTest: function(){
966 var d = new doh.Deferred();
967
968 var wasBlank = !pattern.get("value");
969
970 handler = dojo.connect(pattern, 'openDropDown', function(){
971 dojo.disconnect(handler);
972 var calendar = dijit.byId("pattern_popup");
973 var wasVisible = calendar && isVisible(calendar);
974
975 handler = dojo.connect(pattern, 'closeDropDown', d.getTestCallback(function(){
976 doh.t(wasBlank, "initially blank");
977 doh.t(wasVisible, "calendar was visible");
978 var calendar = dijit.byId("pattern_popup");
979 doh.f(calendar && isVisible(calendar), "calendar popup destroyed or hidden");
980 doh.t(!pattern.get("value"), "no value set into DateTextBox")
981 }));
982
983 // close the drop down
984 doh.robot.mouseMoveAt("pattern", 0, 1, pattern.domNode.offsetWidth + 20, pattern.domNode.offsetHeight/2);
985 doh.robot.mouseClick({left:true}, 500);
986 });
987
988 // open the drop down
989 doh.robot.mouseMoveAt(pattern._buttonNode, 100, 1); // delay to allow previous keyUp to occur
990 doh.robot.mouseClick({left:true}, 500);
991
992 return d;
993 },
994 tearDown: function(){
995 dojo.disconnect(handler);
996 }
997 });
998
999 doh.register("month drop down edge case", [
1000 {
1001 name: "initial popup display",
1002 timeout: 6000,
1003 setUp: function(){
1004 american.set('value', new Date(2006, 11, 31), false);
1005 },
1006 runTest: function(){
1007 var d = new doh.Deferred();
1008
1009 handler = dojo.connect(american, 'openDropDown', d.getTestCallback(function(){
1010 var calendar = dijit.byId("american_popup");
1011
1012 // calendar exists and is shown
1013 doh.t(calendar && isVisible(calendar), "calendar is visible");
1014
1015 // calendar is on the right month
1016 doh.is("December", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "calendar starts on month selected in input box");
1017
1018 // and the right year
1019 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
1020 doh.is(1, selectedYearButtons.length, "current year is shown");
1021 doh.is("2006", innerText(selectedYearButtons[0]), "current year");
1022
1023 // and the currently focused date is the 31'st
1024 doh.is("31", innerText(dojo.query(".dijitCalendarSelectedDate", calendar.domNode)[0]), "correct day is selected");
1025 }));
1026
1027 doh.robot.mouseMoveAt(american._buttonNode, 100, 1); // delay to allow previous mouseUp to occur
1028 doh.robot.mouseClick({left:true}, 500);
1029
1030 return d;
1031 },
1032 tearDown: function(){
1033 dojo.disconnect(handler);
1034 }
1035 },
1036
1037 // Switching to February to test that movement works even though there is no Feb 31st.
1038 {
1039 name: "switch to february",
1040 timeout: 6000,
1041 runTest: function(){
1042 var d = new doh.Deferred();
1043 var calendar = dijit.byId("american_popup");
1044
1045 doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label");
1046 doh.t(calendar.monthWidget.dropDown, "month dropdown exists");
1047 doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible");
1048
1049 doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1);
1050 doh.robot.mouseClick({left:true}, 500);
1051
1052 doh.robot.mouseMoveAt(function(){
1053 return dojo.query("[month=1]", calendar.monthWidget.dropDown.domNode)[0];
1054 }, 1000, 1);
1055 doh.robot.mouseClick({left:true}, 500);
1056
1057 doh.robot.sequence(d.getTestCallback(function(){
1058 // calendar still exists and is shown
1059 doh.t(calendar, "calendar popup exists");
1060 doh.t(isVisible(calendar), "calendar is visible");
1061
1062 // calendar moved to feb 2006
1063 doh.is("February", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from December to February");
1064 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
1065 doh.is(1, selectedYearButtons.length, "current year is shown");
1066 doh.is("2006", innerText(selectedYearButtons[0]), "current year");
1067 }), 500);
1068
1069 return d;
1070 }
1071 },
1072
1073 // Switching to December to make sure that drop down isn't cut off
1074 {
1075 name: "switch back to december",
1076 timeout: 6000,
1077 runTest: function(){
1078 var d = new doh.Deferred();
1079 var calendar = dijit.byId("american_popup");
1080
1081 doh.is(1, dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode).length, "found month label");
1082 doh.t(calendar.monthWidget.dropDown, "month dropdown exists");
1083 doh.f(isVisible(calendar.monthWidget.dropDown), "month dropdown is not visible");
1084
1085 doh.robot.mouseMoveAt(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0], 0, 1);
1086 doh.robot.mouseClick({left:true}, 500);
1087
1088 doh.robot.mouseMoveAt(function(){
1089 return dojo.query("[month=11]", calendar.monthWidget.dropDown.domNode)[0];
1090 }, 1000, 1);
1091 doh.robot.mouseClick({left:true}, 500);
1092
1093 doh.robot.sequence(d.getTestCallback(function(){
1094 // calendar still exists and is shown
1095 doh.t(calendar, "calendar popup exists");
1096 doh.t(isVisible(calendar), "calendar is visible");
1097
1098 // calendar moved to dec 2006
1099 doh.is("December", innerText(dojo.query(".dijitCalendarCurrentMonthLabel", calendar.domNode)[0]), "moved from june to july");
1100 var selectedYearButtons = dojo.query(".dijitCalendarSelectedYear", calendar.domNode);
1101 doh.is(1, selectedYearButtons.length, "current year is shown");
1102 doh.is("2006", innerText(selectedYearButtons[0]), "current year");
1103 }), 1000);
1104
1105 return d;
1106 }
1107 },
1108
1109 {
1110 name: "cancel",
1111 timeout: 3000,
1112 runTest: function(){
1113 var d = new doh.Deferred();
1114
1115 handler = dojo.connect(american, 'closeDropDown', d.getTestCallback(function(){
1116 var calendar = dijit.byId("american_popup");
1117 doh.f(calendar && isVisible(calendar), "calendar isn't visible");
1118 }));
1119 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
1120
1121 return d;
1122 },
1123 tearDown: function(){
1124 dojo.disconnect(handler);
1125 }
1126 }
1127 ]);
1128
1129 doh.register("clicking input", [
1130 {
1131 name: "click on input",
1132 timeout: 10000,
1133 runTest: function(){
1134 var d = new doh.Deferred();
1135
1136 handler = dojo.connect(localLong.focusNode, 'onfocus', function(){
1137 dojo.disconnect(handler);
1138 var calendar = dijit.byId("localLong_popup");
1139 var wasVisible = calendar && isVisible(calendar);
1140 handler = dojo.connect(localLong, 'openDropDown', d.getTestCallback(function(){
1141 doh.f(wasVisible, "calendar isn't visible");
1142 calendar = dijit.byId("localLong_popup");
1143 doh.t(calendar && isVisible(calendar), "calendar is visible");
1144 }));
1145 doh.robot.mouseMoveAt(localLong._buttonNode, 0, 1);
1146 doh.robot.mouseClick({left:true}, 500);
1147 });
1148
1149 doh.robot.mouseMoveAt(localLong.focusNode, 100, 1); // delay to allow previous keyUp to occur
1150 doh.robot.mouseClick({left:true}, 500);
1151
1152 return d;
1153 },
1154 tearDown: function(){
1155 dojo.disconnect(handler);
1156 localLong.closeDropDown();
1157 }
1158 }
1159 ]);
1160
1161 doh.run();
1162 });
1163 </script>
1164 </head>
1165 </html>