Debian Codegraph @

dijit/tests/form/robot/Select.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 Select 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_Select.html');
22
23 // refs to parts of s1 Select
24 var s1, s1menu, Tenessee, Virginia, Washington, // s1 select
25 s2, s2menu, s8a, s8a_menu, s8b, s8b_menu, s3, s3_menu; // long list selects
26
27 // log of calls to onChange handler
28 var changes = [];
29
30 var focus; // dijit/focus
31
32 doh.register("setup",
33 function setUp(){
34 s1 = dijit.byId('s1');
35 s1_menu = dijit.byId('s1_menu');
36 doh.t(s1, "s1 select exists");
37 doh.t(s1_menu, "s1 menu exists");
38
39 s2 = dijit.byId('s2');
40 s2_menu = dijit.byId('s2_menu');
41 s8a = dijit.byId('s8a');
42 s8a_menu = dijit.byId('s8a_menu');
43 s8b = dijit.byId('s8b');
44 s8b_menu = dijit.byId('s8b_menu');
45 s3 = dijit.byId('s3');
46 s3_menu = dijit.byId('s3_menu');
47 s13 = dijit.byId('s13');
48 s13_menu = dijit.byId('s13_menu');
49 s14 = dijit.byId('s14');
50 s14_menu = dijit.byId('s14_menu');
51
52 form = dijit.byId('form');
53
54 // preload menus since first load can take a while
55 var doNothing = function(){};
56 s1.loadDropDown(doNothing);
57 dijit.byId('s5').loadDropDown(doNothing);
58 dijit.byId('s6').loadDropDown(doNothing);
59 s8a.loadDropDown(doNothing);
60 s8b.loadDropDown(doNothing);
61
62 // modules in test page
63 focus = dojo.global.require("dijit/focus");
64 }
65 );
66
67 doh.register("mouse", [
68 {
69 name: "two clicks to select",
70 timeout: 10000,
71 runTest: function(){
72 var d = new doh.Deferred();
73
74 // click to open drop down
75 doh.robot.mouseMoveAt(s1.domNode, 0, 1);
76 doh.robot.mouseClick({left:true}, 500);
77 doh.robot.sequence(d.getTestErrback(function(){
78 doh.t(isVisible(s1_menu), "drop down menu displayed after click");
79 doh.is("true", s1.domNode.getAttribute('aria-expanded'), 'aria-expanded');
80 doh.is("listbox", s1_menu.domNode.getAttribute('role'), 'menu role');
81 doh.is(5, dojo.query("tr", s1_menu.domNode).length, "5 options in menu");
82
83 var selectedOptions = dojo.query(".dijitSelectSelectedOption .dijitMenuItemLabel", s1_menu.domNode);
84 doh.is(1, selectedOptions.length, "one selected option");
85 doh.is("Virginia", innerText(selectedOptions[0]), "Virginia highlighted");
86
87 Washington = dojo.query("tr", s1_menu.domNode)[2];
88 doh.t(Washington, "Washington is another menu choice");
89 }), 1000);
90
91 // select an option in the drop down
92 doh.robot.mouseMoveAt(function(){
93 // function wrapper because Washington isn't defined until about sequence() runs
94 return Washington;
95 }, 0, 1);
96 doh.robot.mouseClick({left:true}, 500);
97 doh.robot.sequence(d.getTestErrback(function(){
98 doh.t(isHidden(s1_menu), "clicking choice hides menu");
99 doh.is("false", s1.domNode.getAttribute('aria-expanded'), 'aria-expanded');
100
101 doh.is("Washington", innerText(s1.containerNode), "select shows selected option");
102 doh.is("WA", s1.get("value"), "get(value) after selecting Washington");
103 }), 1000);
104
105 // click to open drop down again
106 doh.robot.mouseMoveAt(s1.domNode, 0, 1);
107 doh.robot.mouseClick({left:true}, 500);
108 doh.robot.sequence(d.getTestErrback(function(){
109 doh.t(isVisible(s1_menu), "drop down menu displayed after third click");
110
111 var selectedOptions = dojo.query(".dijitSelectSelectedOption .dijitMenuItemLabel", s1_menu.domNode);
112 doh.is(1, selectedOptions.length, "one selected option");
113 doh.is("Washington", innerText(selectedOptions[0]), "Washington highlighted");
114 }), 1000);
115
116 // clicking away should close the drop down
117 doh.robot.mouseMove(10, 10, 500);
118 doh.robot.mouseClick({left:true}, 500);
119 doh.robot.sequence(d.getTestCallback(function(){
120 doh.t(isHidden(s1_menu), "clicking away hides menu");
121 }), 1000);
122
123 return d;
124 }
125 },
126
127 {
128 name: "mouse down, slide, mouse up",
129 timeout: 15000,
130 setUp: function(){
131 s1.set("value", "VA");
132 },
133 runTest: function(){
134 var d = new doh.Deferred();
135
136 // mouse-down to open drop down
137 doh.robot.mouseMoveAt(s1.domNode, 0, 1);
138 doh.robot.mousePress({left:true}, 500);
139 doh.robot.sequence(d.getTestErrback(function(){
140 doh.t(isVisible(s1_menu), "drop down menu displayed after mouse down");
141 doh.is(5, dojo.query("tr", s1_menu.domNode).length, "5 options in menu");
142
143 var selectedOptions = dojo.query(".dijitSelectSelectedOption .dijitMenuItemLabel", s1_menu.domNode);
144 doh.is(1, selectedOptions.length, "one selected option");
145 doh.is("Virginia", innerText(selectedOptions[0]), "Virginia highlighted");
146
147 Washington = dojo.query("tr", s1_menu.domNode)[2];
148 doh.t(Washington, "Washington is another menu choice");
149 }), 1000);
150
151 // select an option in the drop down
152 doh.robot.mouseMoveAt(function(){
153 // function wrapper because Washington isn't defined until above sequence() runs
154 return Washington;
155 }, 0, 1);
156 doh.robot.mouseRelease({left:true}, 500);
157 doh.robot.sequence(d.getTestErrback(function(){
158 doh.t(isHidden(s1_menu), "clicking choice hides menu");
159
160 doh.is("Washington", innerText(s1.containerNode), "select shows selected option");
161 doh.is("WA", s1.get("value"), "get(value) after selecting Washington");
162 }), 1000);
163
164 // mouse down to open drop down again
165 doh.robot.mouseMoveAt(s1.domNode, 0, 1);
166 doh.robot.mousePress({left:true}, 500);
167 doh.robot.sequence(d.getTestErrback(function(){
168 doh.t(isVisible(s1_menu), "drop down menu displayed after second mouse down");
169
170 var selectedOptions = dojo.query(".dijitSelectSelectedOption .dijitMenuItemLabel", s1_menu.domNode);
171 doh.is(1, selectedOptions.length, "one selected option");
172 doh.is("Washington", innerText(selectedOptions[0]), "Washington highlighted");
173 }), 1000);
174
175 // mouse up away from node should leave drop down open
176 doh.robot.mouseMove(10, 10, 500);
177 doh.robot.mouseRelease({left:true}, 500);
178 doh.robot.sequence(d.getTestErrback(function(){
179 doh.t(isVisible(s1_menu), "mouse up away from menu leaves menu open");
180 }), 500);
181
182 // then another mouse click should close it
183 doh.robot.mouseClick({left:true}, 500);
184 doh.robot.sequence(d.getTestCallback(function(){
185 doh.t(isHidden(s1_menu), "clicking on blank screen hides menu");
186 }), 1000);
187
188 return d;
189 }
190 },
191 {
192 name: "maxHeight",
193 timeout: 10000,
194 runTest: function(){
195 var d = new doh.Deferred();
196
197 // open drop down
198 doh.robot.mouseMoveAt(s8a.domNode, 0, 1);
199 doh.robot.mouseClick({left:true}, 500);
200 doh.robot.sequence(d.getTestErrback(function(){
201 doh.t(isVisible(s8a_menu.domNode), "drop down menu displayed after mouse down");
202
203 var pos = dojo.position(s8a_menu.domNode.parentNode); // scrollbar on wrapper
204 doh.t(pos.h >= 200, "height at least 200: " + pos.h);
205 doh.t(pos.h < 220, "height including borders not much more than 200: " + pos.h);
206 }), 1000);
207
208 // close drop down
209 doh.robot.mouseMove(10, 10, 500, 1);
210 doh.robot.mouseClick({left:true}, 500);
211 doh.robot.sequence(d.getTestCallback(function(){
212 doh.t(isHidden(s8a_menu), "clicking on blank screen hides menu");
213 }), 1000);
214
215 return d;
216 }
217 },
218
219 // Not sure if this is good or not, but sometimes menu can overlap
220 // the select itself. In this case, mouse up should leave the menu open
221 {
222 name: "menu overlaps select",
223 timeout: 6000,
224 runTest: function(){
225 var d = new doh.Deferred(),
226 overlapping = false;
227
228 // open drop down
229 doh.robot.mouseMoveAt(s8b.domNode, 0, 1);
230 doh.robot.mouseClick({left:true}, 500);
231 doh.robot.sequence(d.getTestErrback(function(){
232 doh.t(isVisible(s8b_menu.domNode), "drop down menu displayed after mouse click");
233
234 var select = dojo.position(s8b.domNode),
235 menu = dojo.position(s8b_menu.domNode);
236 doh.t(menu.h >= 220, "menu has big height: " + menu.h);
237
238 // Sometimes the menu overlaps and (at least on chrome/win) sometimes it doesn't.
239 // Not sure why the behavior changes but not treating it as a bug.
240 overlapping = menu.y < select.y && menu.y+menu.h > select.y+select.h;
241 }), 1000);
242
243 // clicking again should select the option from the menu
244 doh.robot.mouseClick({left:true}, 500);
245 doh.robot.sequence(d.getTestCallback(function(){
246 if(overlapping){
247 doh.t(isHidden(s8b_menu), "clicking again selects something from menu");
248 }
249 }), 1000);
250
251 return d;
252 }
253 }
254
255 ]);
256
257 doh.register("keyboard", [
258 {
259 name: "tabIndex",
260 timeout: 10000,
261 setUp: function(){
262 dojo.byId("htmlSelect2").focus();
263 dijit.byId("s2").set("disabled", true);
264 },
265 runTest: function(){
266 var d = new doh.Deferred();
267
268 // tab to s1
269 doh.robot.keyPress(dojo.keys.TAB, 500, {});
270 doh.robot.sequence(d.getTestErrback(function(){
271 doh.is("s1", dojo.global.dijit.focus.curNode.id)
272
273 // Make sure _KeyNavMixin superclass didn't set tabIndex to -1.
274 doh.is("0", dijit.byId("s1").domNode.tabIndex, "tabIndex")
275 }), 1000);
276
277 // tab to button after s1
278 doh.robot.keyPress(dojo.keys.TAB, 500, {});
279 doh.robot.sequence(d.getTestErrback(function(){
280 doh.is("s1button", dojo.global.dijit.focus.curNode.id)
281 }), 1000);
282
283 // tab again should skip disabled s2, and go to s3
284 doh.robot.keyPress(dojo.keys.TAB, 500, {});
285 doh.robot.sequence(d.getTestCallback(function(){
286 doh.is("s3", dojo.global.dijit.focus.curNode.id)
287 }), 1000);
288
289 return d;
290 },
291 tearDown: function(){
292 dijit.byId("s2").set("disabled", false);
293 }
294 },
295 {
296 name: "selecting",
297 timeout: 9000,
298 setUp: function(){
299 dojo.byId("htmlSelect2").focus();
300 },
301 runTest: function(){
302 var d = new doh.Deferred();
303 var nextFocused, previousSelectionFocused, wasVisible, stillVisible, widgetFocused;
304
305 // tab to s1
306 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
307 doh.robot.sequence(function(){
308 widgetFocused = dojo.global.dijit.focus.curNode.id == "s1";
309 }, 1000);
310
311 // down arrow to open drop down and focus first item
312 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
313 doh.robot.sequence(function(){
314 wasVisible = isVisible(s1_menu);
315 previousSelectionFocused = dojo.query("tr", s1_menu.domNode)[2] == dojo.global.dijit.focus.curNode;
316 }, 1000);
317
318 // down arrow to next menu choice
319 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
320 doh.robot.sequence(function(){
321 stillVisible = isVisible(s1_menu);
322 nextFocused = dojo.query("tr", s1_menu.domNode)[3] == dojo.global.dijit.focus.curNode;
323 }, 500);
324
325 // ENTER to select option
326 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
327 doh.robot.sequence(d.getTestCallback(function(){
328 doh.t(widgetFocused, "widget focus");
329 doh.t(wasVisible, "drop down menu displayed after down arrow");
330 doh.t(previousSelectionFocused, "focused on previously selected item")
331 doh.t(stillVisible, "drop down menu still displayed");
332 doh.t(nextFocused, "focused on next menu item")
333 doh.t(isHidden(s1_menu), "drop down menu closes after ENTER key");
334 doh.is("FL", s1.get("value"));
335 }), 1000);
336
337 return d;
338 },
339 tearDown: function(){
340 dijit.byId("s1").set("value", "VA");
341 }
342 },
343 {
344 name: "ESC to close menu",
345 timeout: 9000,
346 setUp: function(){
347 dojo.byId("htmlSelect2").focus();
348 },
349 runTest: function(){
350 var d = new doh.Deferred();
351 var nextFocused, wasVisible, widgetFocused;
352
353 // tab to s1
354 doh.robot.keyPress(dojo.keys.TAB, 1000, {});
355 doh.robot.sequence(function(){
356 widgetFocused = dojo.global.dijit.focus.curNode.id == "s1";
357 }, 1000);
358
359 // down arrow to open drop down and focus first item
360 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
361 doh.robot.sequence(function(){
362 wasVisible = isVisible(s1_menu);
363 }, 1000);
364 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
365 doh.robot.sequence(function(){
366 nextFocused = dojo.query("tr", s1_menu.domNode)[2] == dojo.global.dijit.focus.curNode;
367 }, 500);
368
369 // ESC to close menu
370 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
371 doh.robot.sequence(d.getTestCallback(function(){
372 doh.t(widgetFocused, "widget focus");
373 doh.t(wasVisible, "drop down menu displayed after down arrow");
374 doh.t(nextFocused, "focused next menu item")
375 doh.t(isHidden(s1_menu), "drop down menu closes after ENTER key");
376 doh.is("VA", s1.get("value"), "value unchanged");
377 }), 1000);
378
379 return d;
380 },
381 tearDown: function(){
382 dijit.byId("s1").set("value", "VA");
383 }
384 },
385 {
386 name: "single letter search after failed multiple letter search, no dropdown",
387 timeout: 9000,
388 setUp: function(){
389 s2.set("value", "CA");
390 s2.focus();
391 },
392 runTest: function(){
393 var d = new doh.Deferred();
394
395 // c search fails to find CA due to multi-character searching
396 doh.robot.typeKeys("aaaaaaac", 1000, 1200);
397
398 doh.robot.sequence(d.getTestCallback(function(){
399 doh.is("AZ", s2.get("value"), "hidden value");
400 doh.f(isVisible(s2_menu), "no menu");
401 }), 1000);
402
403 return d;
404 }
405 },
406 {
407 name: "multiple letter search after failed multiple letter search, no dropdown",
408 timeout: 9000,
409 runTest: function(){
410 var d = new doh.Deferred();
411
412 // ala suffix fails to find either alabama or alaska due to multi-character searching
413 doh.robot.typeKeys("aaaaaaaaala", 1000, 1400);
414
415 doh.robot.sequence(d.getTestCallback(function(){
416 doh.is("AR", s2.get("value"), "hidden value");
417 doh.f(isVisible(s2_menu), "no menu");
418 }), 1000);
419
420 return d;
421 }
422 },
423 {
424 name: "multiple letter searching from current, no dropdown",
425 timeout: 9000,
426 runTest: function(){
427 var d = new doh.Deferred();
428
429 // search for Alabama
430 doh.robot.typeKeys("al", 1000, 1600); // al search finds alabama
431
432 doh.robot.sequence(d.getTestCallback(function(){
433 doh.is("AL", s2.get("value"), "hidden value");
434 doh.f(isVisible(s2_menu), "no menu");
435 }), 1000);
436
437 return d;
438 }
439 },
440 {
441 name: "multiple letter searching find next, no dropdown",
442 timeout: 9000,
443 runTest: function(){
444 var d = new doh.Deferred();
445
446 doh.robot.typeKeys("alas", 1000, 1600); // s search finds alaska
447
448 doh.robot.sequence(d.getTestCallback(function(){
449 doh.is("AK", s2.get("value"), "hidden value");
450 doh.f(isVisible(s2_menu), "no menu");
451 }), 1000);
452
453 return d;
454 }
455 },
456 {
457 name: "single letter searching, no dropdown",
458 timeout: 9000,
459 runTest: function(){
460 var d = new doh.Deferred();
461
462 // c search finds CA
463 doh.robot.typeKeys("c", 500, 500);
464
465 doh.robot.sequence(d.getTestCallback(function(){
466 doh.is("CA", s2.get("value"), "hidden value");
467 doh.f(isVisible(s2_menu), "no menu");
468 }), 1000);
469
470 return d;
471 }
472 },
473 {
474 name: "multi letter searching with SPACE, no dropdown",
475 timeout: 9000,
476 runTest: function(){
477 var d = new doh.Deferred();
478
479 // c search fails to find CA due to multi-character searching
480 doh.robot.typeKeys("new m", 500, 1200);
481
482 doh.robot.sequence(d.getTestCallback(function(){
483 doh.is("NM", s2.get("value"), "hidden value");
484 doh.f(isVisible(s2_menu), "no menu");
485 }), 1000);
486
487 return d;
488 }
489 },
490 {
491 name: "single letter searching from dropdown",
492 timeout: 9000,
493 setUp: function(){
494 s2.set("value", "CA");
495 },
496 runTest: function(){
497 var d = new doh.Deferred();
498
499 // down arrow to open drop down and search with several a's
500 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
501 doh.robot.typeKeys("aaaaaaac", 1000, 1200); // c search fails to find CA due to multi-character searching
502
503 // SPACE to close menu
504 doh.robot.keyPress(dojo.keys.SPACE, 1100, {}); // long delay so that multi-letter searching is deactivated
505 doh.robot.sequence(d.getTestCallback(function(){
506 doh.is("AZ", s2.get("value"), "hidden value");
507 }), 1000);
508
509 return d;
510 }
511 },
512 {
513 name: "multiple letter searching no match from dropdown",
514 timeout: 9000,
515 runTest: function(){
516 var d = new doh.Deferred();
517
518 // ENTER to open drop down and search with several a's
519 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
520 doh.robot.typeKeys("aaaaaaaaala", 1000, 1400); // ala suffix fails to find either alabama or alaska
521
522 // ENTER to close menu
523 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
524 doh.robot.sequence(d.getTestCallback(function(){
525 doh.is("AR", s2.get("value"), "hidden value");
526 }), 1000);
527
528 return d;
529 }
530 },
531 {
532 name: "multiple letter searching from current from dropdown",
533 timeout: 9000,
534 runTest: function(){
535 var d = new doh.Deferred();
536 var wasVisible;
537
538 // SPACE to open drop down and search with several a's
539 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
540 doh.robot.typeKeys("al", 1000, 1600); // al search finds alabama
541 doh.robot.sequence(function(){
542 wasVisible = isVisible(s2_menu);
543 }, 1000);
544
545 // SPACE to close menu
546 doh.robot.keyPress(dojo.keys.SPACE, 1100, {}); // long delay so that multi-letter searching is deactivated
547 doh.robot.sequence(d.getTestCallback(function(){
548 doh.t(wasVisible, "no auto selection");
549 doh.is("AL", s2.get("value"), "hidden value");
550 }), 1000);
551
552 return d;
553 }
554 },
555 {
556 name: "multiple letter searching find next from dropdown",
557 timeout: 9000,
558 runTest: function(){
559 var d = new doh.Deferred();
560 var wasVisible;
561
562 // down arrow to open drop down and search with several a's
563 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
564 doh.robot.typeKeys("alas", 1000, 1600); // s search finds alaska
565 doh.robot.sequence(function(){
566 wasVisible = isVisible(s2_menu);
567 }, 1000);
568
569 // ENTER to close menu
570 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
571 doh.robot.sequence(d.getTestCallback(function(){
572 doh.t(wasVisible, "no auto selection");
573 doh.is("AK", s2.get("value"), "hidden value");
574 }), 1000);
575
576 return d;
577 }
578 },
579 {
580 name: "toolbar",
581 timeout: 10000,
582 setUp: function(){
583 dojo.byId("beforeToolbar").focus();
584 },
585 runTest: function(){
586 var d = new doh.Deferred();
587
588 // tab into toolbar, then arrow to select
589 doh.robot.keyPress(dojo.keys.TAB, 500, {});
590 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
591
592 // select Alabama
593 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
594 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
595 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
596
597 // go to right toggle button and click it
598 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
599 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
600
601 // go to left toggle button and click it
602 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
603 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
604 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
605
606 doh.robot.sequence(d.getTestCallback(function(){
607 doh.is("AL", dijit.byId("toolbarSelect").get("value"), "select value");
608 doh.t(dijit.byId("toggle1").get("checked"), "first toggle button");
609 doh.t(dijit.byId("toggle2").get("checked"), "second toggle button");
610 }), 1000);
611
612 return d;
613 }
614 }
615 ]);
616
617 doh.register("display", [
618 {
619 name: "empty drop down",
620 timeout: 6000,
621 runTest: function(){
622 var d = new doh.Deferred();
623
624 // Open widget w/no choices
625 var s6 = dijit.byId("s6");
626 doh.robot.mouseMoveAt(s6.domNode, 0, 1);
627 doh.robot.mouseClick({left:true}, 500);
628 doh.robot.sequence(d.getTestCallback(function(){
629 var menu = dijit.byId("s6_menu"),
630 trs = dojo.query("tr", menu.domNode);
631 doh.is(1, trs.length, "one entry in menu");
632 doh.is("", innerText(dojo.query(".dijitMenuItemLabel", trs[0])), "blank");
633 }), 500);
634
635 return d;
636 }
637 },
638
639 // Currently (for better or worse) the select's width changes based on which option
640 // is selected. Make sure that the drop down is wide enough to show all entries,
641 // even when a narrow entry is selected.
642 {
643 name: "width",
644 timeout: 10000,
645 runTest: function(){
646 var d = new doh.Deferred();
647
648 var s5 = dijit.byId("s5"),
649 s5_menu = dijit.byId("s5_menu"),
650 menuSize;
651
652 // originally s5 is narrow
653 var s5origSize = dojo.position(s5.domNode);
654
655 // Open drop down menu and make sure it's wider than the select
656 // (to display "no move" and "no copy" choices)
657 doh.robot.mouseMoveAt(s5.domNode, 0, 1);
658 doh.robot.mouseClick({left:true}, 500);
659 doh.robot.sequence(d.getTestErrback(function(){
660 menuSize = dojo.position(s5_menu.domNode);
661 doh.t(menuSize.w > s5origSize.w, "menu (" + menuSize.w + ") wider than select (" + s5origSize.w + ")");
662 }), 1000);
663
664 // Select last entry in the drop down. Should make the select wider.
665 doh.robot.mouseMoveAt(function(){
666 return dojo.query("tr", s5_menu.domNode)[4];
667 }, 500, 1);
668 doh.robot.mouseClick({left:true}, 500);
669 doh.robot.sequence(d.getTestCallback(function(){
670 var s5newSize = dojo.position(s5.domNode);
671 doh.t(s5newSize.w > s5origSize.w, "select changed width from " + s5origSize.w + " to " + s5newSize.w);
672 }), 500);
673
674 return d;
675 }
676 }
677 ]);
678
679 doh.register("required", [
680 function initial_value(){
681 doh.t(!s3.get('value'), "initial blank value");
682 doh.t(!s3.options[0].value, "blank option");
683 doh.t(s3.get('required'), "required");
684 doh.f(s3.isValid(), "should not be valid");
685 },
686 {
687 name: "select blank option",
688 timeout: 6000,
689 runTest: function(){
690 var d = new doh.Deferred();
691
692 // Open drop down menu
693 doh.robot.mouseMoveAt(s3.domNode, 0, 1);
694 doh.robot.mouseClick({left:true}, 500);
695 // Select blank option
696 doh.robot.mouseMoveAt(function(){
697 return dojo.query("tr", s3_menu.domNode)[0];
698 }, 1000, 1);
699 doh.robot.mouseClick({left:true}, 500);
700 doh.robot.sequence(d.getTestCallback(function(){
701 doh.t(isHidden(s3_menu), "drop down menu closes after selection");
702 doh.t(!s3.get('value'), "blank value");
703 doh.t(!s3.options[0].value, "blank option");
704 doh.f(s3.isValid(), "should not be valid");
705 }), 1000);
706
707 return d;
708 }
709 },
710 {
711 name: "select option w/ blank present",
712 timeout: 6000,
713 runTest: function(){
714 var d = new doh.Deferred();
715
716 // Open drop down menu
717 doh.robot.mouseMoveAt(s3.domNode, 0, 1);
718 doh.robot.mouseClick({left:true}, 500);
719 // Select 4th option
720 doh.robot.mouseMoveAt(function(){
721 return dojo.query("tr", s3_menu.domNode)[4];
722 }, 1000, 1);
723 doh.robot.mouseClick({left:true}, 500);
724 doh.robot.sequence(d.getTestCallback(function(){
725 doh.t(isHidden(s3_menu), "drop down menu closes after selection");
726 doh.is("AZ", s3.get('value'), "Arizona");
727 doh.f(!s3.options[0].value, "no blank option");
728 doh.t(s3.isValid(), "should be valid");
729 }), 1000);
730
731 return d;
732 }
733 },
734 {
735 name: "select option w/o blank present",
736 timeout: 6000,
737 runTest: function(){
738 var d = new doh.Deferred();
739
740 // Open drop down menu
741 doh.robot.mouseMoveAt(s3.domNode, 0, 1);
742 doh.robot.mouseClick({left:true}, 500);
743 // Select 4th option
744 doh.robot.mouseMoveAt(function(){
745 return dojo.query("tr", s3_menu.domNode)[4];
746 }, 1000, 1);
747 doh.robot.mouseClick({left:true}, 500);
748 doh.robot.sequence(d.getTestCallback(function(){
749 doh.t(isHidden(s3_menu), "drop down menu closes after selection");
750 doh.is("AR", s3.get('value'), "Arkansas");
751 doh.t(s3.isValid(), "should be valid");
752 }), 1000);
753
754 return d;
755 }
756 }
757 ]);
758
759 doh.register("form submit", [
760 {
761 name: "first validate",
762 timeout: 5000,
763 runTest: function(){
764 // First validate() should focus s13 and display a tooltip.
765 // (s13 is also required, but has a value from previous tests)
766 var d = new doh.Deferred();
767
768 var handle = dijit.focus.watch("curNode", d.getTestErrback(function(name, oval, nval){
769 if(!nval){ return; } // ignore spurious event on IE
770 console.log("focused on", nval && (nval.id || nval.innerHTML));
771 doh.is("s13", nval.id, "focused on first required select");
772 handle.unwatch();
773 setTimeout(d.getTestCallback(function(){
774 // Tooltip should appear with error message
775 masterTT = dojo.global.dijit._masterTT;
776 doh.t(masterTT && isVisible(masterTT.domNode), "visible");
777 doh.is("s13", masterTT.aroundNode.id, "tooltip for s13");
778 doh.is("This value is required.", dojo.trim(innerText(masterTT.domNode)));
779 }), 750);
780 }));
781
782 // Validate the form programatically
783 dijit.byId("form").validate();
784
785 return d;
786 }
787 },
788 {
789 name: "select non-blank option for s13",
790 timeout: 6000,
791 runTest: function(){
792 var d = new doh.Deferred();
793
794 // Open drop down menu
795 doh.robot.mouseMoveAt(s13.domNode, 0, 1);
796 doh.robot.mouseClick({left:true}, 500);
797 // Select 4th option
798 doh.robot.mouseMoveAt(function(){
799 return dojo.query("tr", s13_menu.domNode)[4];
800 }, 1000, 1);
801 doh.robot.mouseClick({left:true}, 500);
802 doh.robot.sequence(d.getTestCallback(function(){
803 doh.t(isHidden(s13_menu), "drop down menu closes after selection");
804 doh.is("AZ", s13.get('value'), "Arizona");
805 doh.t(s13.isValid(), "should be valid");
806 }), 1000);
807
808 return d;
809 }
810 },
811 {
812 name: "revalidate",
813 timeout: 5000,
814 runTest: function(){
815 // Second validate() should focus s14 and display a tooltip
816 var d = new doh.Deferred();
817
818 var handle = dijit.focus.watch("curNode", d.getTestErrback(function(name, oval, nval){
819 if(!nval){ return; } // ignore spurious event on IE
820 if(nval.id == "submit"){ return; } // ignore focus onto submit button
821 doh.is("s14", nval.id, "focused on second required select");
822 handle.unwatch();
823 setTimeout(d.getTestCallback(function(){
824 // Tooltip should appear with error message
825 masterTT = dojo.global.dijit._masterTT;
826 doh.t(masterTT && isVisible(masterTT.domNode), "visible");
827 doh.is("s14", masterTT.aroundNode.id, "tooltip for s14");
828 doh.is("This value is required.", dojo.trim(innerText(masterTT.domNode)));
829 }), 750);
830 }));
831
832 // Press button to submit the form
833 doh.robot.mouseMoveAt("submit", 0, 1);
834 doh.robot.mouseClick({left:true}, 500);
835
836 return d;
837 }
838 }
839 ]);
840
841 doh.register("validation in dialog", [
842 {
843 name: "show and validate dialog",
844 timeout: 5000,
845 runTest: function(){
846 var d = new doh.Deferred();
847
848 // Show dialog
849 doh.robot.mouseMoveAt("dlg1OpenBtn", 0, 1);
850 doh.robot.mouseClick({left: true}, 500);
851
852 // Clicking validate button should show "required but empty" tooltip on the Select
853 doh.robot.mouseMoveAt("dlg1ValidateBtn", 0, 1);
854 doh.robot.mouseClick({left: true}, 500);
855 doh.robot.sequence(d.getTestCallback(function(){
856 doh.is("dlg1Select", focus.curNode && focus.curNode.id, "focused on select");
857 var masterTT = dijit.Tooltip._masterTT;
858 doh.t(masterTT && isVisible(masterTT.domNode), "tooltip shown");
859 }), 750);
860 return d;
861 }
862 },
863 {
864 name: "hide dialog",
865 timeout: 5000,
866 runTest: function(){
867 // Hiding the dialog should make the validation tooltip disappear
868 var d = new doh.Deferred();
869
870 doh.is("dlg1Select", focus.curNode && focus.curNode.id, "focused on select");
871
872 // Close dialog via ESCAPE key because on FF, robot when run from runTests.html has
873 // problems positioning mouse over the close icon. It strangely positions a few
874 // hundred pixels above the close icon, perhaps due to the iframes and scrolling.
875 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
876 doh.robot.sequence(d.getTestCallback(function(){
877 doh.t(isHidden(dojo.byId("dlg1")), "dialog hidden");
878 var masterTT = dijit.Tooltip._masterTT;
879 doh.t(isHidden(masterTT.domNode), "tooltip hidden");
880 }), 750);
881 return d;
882 }
883 },
884 {
885 name: "show again",
886 timeout: 5000,
887 runTest: function(){
888 var d = new doh.Deferred();
889
890 // Show dialog again. Presumably focus is already on the open button, so can
891 // keyboard trigger it.
892 doh.robot.keyPress(dojo.keys.SPACE, 500, {});
893
894 // Opening the dialog focuses the select, which is invalid since it's got no value.
895 // Since this is the second time it's being focused, it should popup the tooltip
896 // immediately.
897 doh.robot.sequence(d.getTestCallback(function(){
898 doh.t(isVisible(dojo.byId("dlg1")), "dialog shown again");
899 doh.is("dlg1Select", focus.curNode.id, "focused on select");
900 var masterTT = dijit.Tooltip._masterTT;
901 doh.t(masterTT && isVisible(masterTT.domNode), "tooltip shown");
902 }), 750);
903 return d;
904 }
905 }
906 ]);
907
908 doh.run();
909 });
910 </script>
911 </head>
912 </html>