Debian Codegraph @

dijit/tests/form/robot/_autoComplete_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 ComboBox/FilteringSelect General and A11Y Tests</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"></script>
13
14 <script type="text/javascript">
15 dojo.require("dijit.robotx");
16 dojo.require("dojo.aspect");
17 dojo.require("dijit.tests.helpers"); // functions to help test
18 dojo.require("dijit.form._TextBoxMixin"); // selectInputText
19
20 // TODO: provide URL toggle for FilteringSelect
21 var testWidget = "dijit.form.ComboBox";
22 var qstr = window.location.search.substr(1);
23 if(qstr.length){
24 var qparts = qstr.split("&");
25 for(var x=0; x<qparts.length; x++){
26 var tp = qparts[x].split("=");
27 if(tp[0] == "testWidget"){
28 testWidget = tp[1];
29 }
30 }
31 }
32 isComboBox = testWidget=="dijit.form.ComboBox";
33 dojo.ready(function(){
34
35 doh.robot.initRobot('../_autoComplete.html?testWidget='+testWidget);
36
37 var arrowlessComboBoxes=['arrowless'];
38
39 var robot_typeValue = function(combo, text, value, expectedText){
40 if(value===undefined) value = text;
41 if(expectedText===undefined) expectedText = text;
42 var d = new doh.Deferred();
43
44 // setup watch() on "value" and "displayedValue"
45 var dv, v;
46 var h1 = combo.watch("displayedValue", function(name, oldVal, newVal){ dv = newVal; });
47 var h2 = combo.watch("value", function(name, oldVal, newVal){ v = newVal; });
48
49 combo.focusNode.focus();
50 combo.itemError = false;
51 doh.robot.sequence(function(){ combo.set("value", null); }, 500);
52 doh.robot.typeKeys(text.replace(/^(.).*$/, "$1"), 500);
53 doh.robot.typeKeys(text.replace(/^./, ""), 1500);
54 doh.robot.keyPress(dojo.keys.ENTER, 1500);
55
56 doh.robot.sequence(d.getTestCallback(function(){
57 // general tests
58 doh.is(value, combo.get("value"), "combo.get(value)");
59 doh.is(expectedText, combo.focusNode.value, "expectedText");
60 doh.f(combo._opened, "not opened");
61 doh.f(combo.itemError, "no itemError");
62
63 // watch() tests
64 doh.is(expectedText, dv, "watch of displayedValue");
65 doh.is(value, v, "watch of value");
66 h1.unwatch();
67 h2.unwatch();
68 }), 2000);
69 return d;
70 };
71
72 var findMenuItem = function(combo, text){
73 var node = combo.dropDown.domNode.firstChild;
74 while(innerText(node).indexOf(text) < 0 && node.nextSibling){
75 node = node.nextSibling;
76 }
77 return node;
78 };
79
80 // Select a value from the drop down using the keyboard, using "more choices" button to page as necessary
81 var robot_a11ySelectValue = function(combo, text, value, expectedText){
82 if(!value) value = text;
83 if(!expectedText) expectedText = text;
84 var d = new doh.Deferred();
85
86 // setup watch() on "value", "displayedValue", "item"
87 var dv, v, i;
88 var h1 = combo.watch("displayedValue", function(name, oldVal, newVal){ dv = newVal; });
89 var h2 = combo.watch("value", function(name, oldVal, newVal){ v = newVal; });
90 var h3 = combo.watch("item", function(name, oldVal, newVal){ i = newVal; });
91
92 combo.focusNode.focus();
93 combo.itemError = false;
94 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
95
96 doh.robot.mouseMoveAt(combo.focusNode, 0); // get cursor out of the way so that wiggling doesn't mess up test
97 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500);
98 var repeat = function(){
99 var node = findMenuItem(combo, text);
100 var isMoreChoices = node == combo.dropDown.nextButton;
101 var selected = combo.dropDown.getHighlightedOption() || combo.dropDown.domNode.firstChild;
102 while(selected != node){
103 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 300);
104 selected = selected.nextSibling;
105 }
106 doh.robot.keyPress(dojo.keys.ENTER, 500);
107 if(isMoreChoices){
108 // can go faster since the data will have loaded by now
109 doh.robot.sequence(repeat, 1000);
110 }else{
111 doh.robot.sequence(d.getTestCallback(function(){
112 doh.is(value, combo.get("value"), "combo.get(value)");
113 doh.is(expectedText, combo.focusNode.value, "expectedText");
114 doh.f(combo._opened, "not opened");
115 doh.f(combo.itemError, "no itemError");
116
117 // watch() tests
118 doh.is(expectedText, dv, "watch of displayedValue");
119 doh.is(value, v, "watch of value");
120 doh.is(value, isComboBox ? i[combo.searchAttr] : combo.store.getIdentity(i), "watch of item");
121 h1.unwatch();
122 h2.unwatch();
123 h3.unwatch();
124 }), 500);
125 }
126
127 };
128 // first time, wait for the data to come in
129 doh.robot.sequence(repeat, 3000);
130 return d;
131 };
132
133 // Wait for data stores to finish loading before starting tests
134 doh.register("wait for data store load",
135 dojo.map(["store", "store2", "stateStore", "dijitStore"], function(name){
136 return {
137 name: "wait for " + name,
138 timeout: 5000,
139 runTest: function(){
140 var d = new doh.Deferred();
141 dojo.global[name].fetch({
142 onComplete: function(){
143 d.callback(true);
144 },
145 onError: function(e){
146 d.errback(e);
147 }
148 });
149 return d;
150 }
151 };
152 })
153 );
154
155 // Verify that all of the form values are correct at init
156 doh.register("verify values",
157 {
158 name:"verifyValues",
159 runTest:function(){
160 // Spot check of initial conditions of widgets and DOM nodes
161
162 doh.is("California", dijit.byId("setvaluetest").get("displayedValue"), "state1 displayed value");
163 doh.is(isComboBox ? "California" : "CA", dijit.byId("setvaluetest").get("value"), "state1 value");
164 doh.is("not fired yet!", dojo.byId("oc1").value, "state1 onChange hasn't fired");
165
166 // Test that dojo.query() finds hidden field, see #8660
167 var elems = dojo.doc.getElementsByName("state2");
168 doh.is(1, elems.length, "exactly one node with name=state2");
169 doh.is(isComboBox ? "California" : "CA", elems[0].value, "state2 submit value");
170 var qelems = dojo.query("input[name=state2]");
171 doh.is(1, qelems.length, "dojo.query() returns exactly one node with name=state2");
172 doh.is(isComboBox ? "California" : "CA", qelems[0].value, "state2 dojo.query value");
173
174 doh.is(1, dojo.query("input[name=state3]").length,
175 "Just one input inside of " + testWidget + " w/name specified");
176 if(!isComboBox){
177 // Filtering select should have two inputs, but the displayed one is hidden
178 doh.is(2, dojo.query("input", dijit.byId("combo3").domNode).length-dojo.query("input[readOnly]", dijit.byId("combo3").domNode).length,
179 "Two inputs inside of filteringSelect");
180 }
181
182 doh.is("sticks & stones", dijit.byId("specialchars").get("displayedValue"), "specialchars get('displayValue')");
183 doh.is(isComboBox ? "sticks & stones" : "sticks", dijit.byId("specialchars").get("value"), "specialchars value");
184 doh.is("sticks & stones", dojo.query("input[id=specialchars]")[0].value, "specialchars display value via DOMNode");
185 doh.is(isComboBox ? "sticks & stones" : "sticks", dojo.query("input[name=specialchars]")[0].value, "specialchars submit value via DOMNode");
186 }
187 }
188 );
189
190 var comboIds=['setvaluetest','datatest','combo3','combobox4','arrowless','descending'];
191 for(var i=0; i<comboIds.length; i++){
192 doh.register("query input by name",{
193 name:comboIds[i],
194 combo:comboIds[i],
195 runTest:function(){
196 this.combo = dijit.byId(this.combo);
197 var queried=dojo.query("input[name="+(this.combo.valueNode||this.combo.focusNode).name+"]");
198 doh.is(1,queried.length,"Expected 1 combo with name "+(this.combo.valueNode||this.combo.focusNode).name+", found "+queried.length);
199 doh.is(this.combo.valueNode||this.combo.focusNode,queried[0],"Combo's valueNode did not match the one found by dojo.query.");
200 }
201 });
202 }
203
204 doh.register("set('displayedValue', ...)", [
205 // Set displayedValue to Kentucky.
206 // This should be a valid assignment.
207 {
208 timeout:5000,
209 name:"valid",
210 runTest:function(){
211 var d = new doh.Deferred(),
212 combo = dijit.byId("setvaluetest");
213
214 var dv, v;
215 combo.watch("displayedValue", function(name, oldVal, newVal){ dv = newVal; });
216 combo.watch("value", function(name, oldVal, newVal){ v = newVal; });
217
218 combo.set('displayedValue', 'Kentucky');
219 doh.robot.sequence(d.getTestCallback(function(){
220 var oc1=dojo.byId('oc1');
221 doh.is(isComboBox ? "Kentucky" : "KY", combo.get("value"), "get('value')");
222 doh.is(isComboBox ? "Kentucky" : "KY", oc1.value, "onChange");
223 if(!isComboBox){
224 doh.t(combo.isValid(), "isValid()");
225 }
226 doh.is(isComboBox ? "Kentucky" : "KY", v, "watch of value");
227 doh.is("Kentucky", dv, "watch of displayedValue")
228 }), 900);
229 return d;
230 }
231 },
232
233 // Set displayedValue to Canada.
234 // This should be an invalid assignment for FilteringSelect, but ok for ComboBox.
235 {
236 timeout:5000,
237 name:"invalid",
238 runTest:function(){
239 var d = new doh.Deferred(),
240 combo = dijit.byId("setvaluetest");
241 combo.set('displayedValue', 'Canada');
242 doh.robot.sequence(d.getTestCallback(function(){
243 var oc1=dojo.byId('oc1');
244 doh.is(isComboBox ? "Canada" : "", combo.get("value"), "get('value')");
245 doh.is(isComboBox ? "Canada" : "", oc1.value, "onChange");
246 if(!isComboBox){
247 doh.f(combo.isValid(), "isValid()");
248 }
249 }), 900);
250 return d;
251 }
252 }
253 ]);
254
255 doh.register("set('value', ...)", [
256 // Set value to null.
257 // This should be an invalid assignment for FilteringSelect, but ok for ComboBox.
258 {
259 timeout:5000,
260 name:"nullvalue",
261 runTest:function(){
262 var d = new doh.Deferred(),
263 combo = dijit.byId("setvaluetest");
264 combo.set("value", null);
265 doh.robot.sequence(d.getTestCallback(function(){
266 var oc1=dojo.byId('oc1');
267 doh.is("", combo.get("value"), "get('value')");
268 doh.is("", oc1.value, "onChange");
269 if(!isComboBox){
270 doh.f(combo.isValid(), "isValid()");
271 }
272 }), 900);
273 return d;
274 }
275 }
276
277 // TODO: test some other set("value") calls
278 ]);
279
280 doh.register("back compat", [
281 function fetch_optionTags(){
282 // Make sure that myComboBox.store.fetch() still works even though
283 // ComboBox is using the new dojo.store API
284 var d = new doh.Deferred();
285 doh.t(dijit.byId("setvaluetest").store, "store exists");
286 doh.t(dojo.isFunction(dijit.byId("setvaluetest").store.fetch), "fetch exists");
287 dijit.byId("setvaluetest").store.fetch({
288 onBegin: d.getTestCallback(function(total){
289 doh.is(61, total, "# records");
290 })
291 });
292 return d;
293 },
294 function fetch_externalStore(){
295 // Make sure that myComboBox.store.fetch() still works even though
296 // ComboBox is using the new dojo.store API
297 var d = new doh.Deferred();
298 doh.t(dijit.byId("datatest").store, "store exists");
299 doh.t(dojo.isFunction(dijit.byId("datatest").store.fetch), "fetch exists");
300 dijit.byId("datatest").store.fetch({
301 onBegin: d.getTestCallback(function(total){
302 doh.is(61, total, "# records");
303 })
304 });
305 return d;
306 },
307 {
308 timeout:60000,
309 name:"fetch() called with string",
310 runTest:function(){
311 // Make sure typing into a ComboBox connected to an
312 // old dojo.data store calls store.fetch() with a String argument rather than a Regex
313
314 var d = new doh.Deferred();
315 combo = dijit.byId("datatest");
316
317 doh.t("fetch" in combo.store,
318 "combo.store has fetch() method (i.e. it's the old dojo.data API)");
319
320 combo.focusNode.focus();
321 doh.robot.sequence(function(){ combo.set("value", null); }, 500);
322
323 // Keypress (below) will trigger a call to store.fetch, which will then call this code.
324 doh.robot.sequence(function(){
325 var handle = dojo.aspect.after(combo.store, "fetch", d.getTestErrback(function(args){
326 handle.remove();
327 doh.isNot(null, args && args.query && args.query.name,
328 "args.query.name set");
329 doh.is("string", typeof args.query.name, "typeof searchAttr");
330 }), true);
331 }, 500);
332 doh.robot.keyPress("k", 500);
333
334 // Code below merely to let ComboBox finish any pending requests, so "datatest" ComboBox
335 // doesn't grab focus in the middle of with the "direct input" test below.
336 doh.robot.keyPress(dojo.keys.ENTER, 500);
337 doh.robot.sequence(function(){
338 d.callback(true);
339 }, 500);
340
341 return d;
342 }
343 }
344 ]);
345
346 !isComboBox && doh.register("FilteringSelect back-compat", [
347 function setDisplayedValue(){
348 // Make sure that set("displayedValue", ...) on a FilteringSelect connected to an
349 // old dojo.data store calls store.fetch() with a String argument rather than a Regex
350 var combo = dijit.byId("datatest");
351 doh.t("fetch" in combo.store, "combo.store has fetch() method (i.e. it's the old dojo.data API)");
352 var handle = dojo.aspect.after(combo.store, "fetch", function(args){
353 handle.remove();
354 doh.isNot(null, args && args.query && args.query.name, "args.query.name set");
355 doh.is("string", typeof args.query.name, "typeof searchAttr");
356 }, true);
357 combo.set("displayedValue", "Kentucky");
358 }
359 ]);
360
361 doh.register("direct input", [
362 // Type a valid value and press Enter
363 {
364 timeout:60000,
365 name:"valid value",
366 combo:"setvaluetest",
367 runTest:function(){
368 return robot_typeValue(dijit.byId(this.combo), "California", isComboBox? undefined : "CA", isComboBox? undefined : "California");
369 }
370 },
371
372 // Type an invalid value and press Enter
373 {
374 timeout:60000,
375 name:"invalid value",
376 combo:"setvaluetest",
377 runTest:function(){
378 return robot_typeValue((this.combo = dijit.byId(this.combo)), "zxcxarax", isComboBox?"zxcxarax":"");
379 }
380 },
381
382 // Check on the invalid value from the previous test
383 {
384 timeout:60000,
385 name:"invalid value 2",
386 combo:"setvaluetest",
387 runTest:function(){
388 this.combo = dijit.byId(this.combo);
389 if(isComboBox){
390 doh.is("zxcxarax", this.combo.get("value"), "Expected value of zxcxarax, got "+this.combo.get("value")+", text is:"+this.combo.focusNode.value);
391 doh.t(this.combo.isValid(), "Bad value not permitted in ComboBox. Value is: "+this.combo.get("value")+", text is:"+this.combo.focusNode.value);
392 }else{
393 doh.is("", this.combo.get("value"), "Expected value of '', got "+this.combo.get("value")+", text is:"+this.combo.focusNode.value);
394 doh.t(!this.combo.isValid(), "Bad value permitted in FilteringSelect. Value is: "+this.combo.get("value")+", text is:"+this.combo.focusNode.value);
395 }
396 doh.t(!this.combo.itemError, "Should not have an itemError");
397 },
398 tearDown:function(){
399 this.combo.set("value", isComboBox?"Alaska":"AK");
400 }
401 }
402 ]);
403
404 // Test that enter key submits the form, but only when nothing is selected in the drop down
405 doh.register("enter key", {
406 timeout:60000,
407 name:"submit",
408 runTest:function(){
409 dojo.global.formSubmitted = false;
410 var d = new doh.Deferred();
411 var combo = dijit.byId("setvaluetest");
412 combo.focus();
413
414 // Initial conditions:
415 doh.robot.sequence(d.getTestErrback(function(){
416 var popup = dijit.byId('setvaluetest_popup');
417 doh.t(!popup || isHidden(popup), "popup hidden");
418 }), 500);
419
420 // Down arrow opens the drop down
421 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500);
422 doh.robot.sequence(d.getTestErrback(function(){
423 var popup = dijit.byId('setvaluetest_popup');
424 doh.t(popup && isVisible(popup), "popup visible");
425 }), 500);
426
427 // Enter key should select value and close drop down but not submit form
428 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // highlight value
429 doh.robot.keyPress(dojo.keys.ENTER, 500);
430 doh.robot.sequence(d.getTestErrback(function(){
431 var popup = dijit.byId('setvaluetest_popup');
432 doh.t(!popup || isHidden(popup), "popup hidden");
433 doh.f(dojo.global.formSubmitted, "form not submitted yet")
434 }), 500);
435
436 // Enter key again should submit form
437 doh.robot.keyPress(dojo.keys.ENTER, 500);
438 doh.robot.sequence(d.getTestCallback(function(){
439 var popup = dijit.byId('setvaluetest_popup');
440 doh.t(!popup || isHidden(popup), "popup hidden");
441 doh.t(dojo.global.formSubmitted, "form submitted")
442 }), 500);
443
444 return d;
445 }
446 });
447
448 doh.register("drop down navigation / keyboard", [
449 // Select a value from the drop down using the keyboard,
450 // use "more choices" button to page as necessary
451 {
452 timeout:60000,
453 name:"setvaluetest_a11y",
454 combo:"setvaluetest",
455 runTest:function(){
456 return robot_a11ySelectValue(dijit.byId(this.combo), "Texas", isComboBox? "Texas" : "TX", "Texas");
457 }
458 }
459 ]);
460
461 // Test that drop down choices are filtered to values matching what user has typed
462 doh.register("filtering of drop down", [
463 {
464 timeout:60000,
465 name:"type C",
466 runTest:function(){
467 var d = new doh.Deferred();
468 var combo = dijit.byId("setvaluetest");
469 combo.itemError = false;
470
471 combo.focusNode.focus();
472
473 // Filter drop down list to entries starting with "C"
474 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
475 doh.robot.keyPress("C", 100);
476
477 doh.robot.sequence(d.getTestCallback(function(){
478 // Check that drop down list has appeared, and contains California, Colorado, Connecticut
479 var list = dojo.byId("setvaluetest_popup");
480 doh.t(list, "drop down exists");
481 doh.t(isVisible(list), "drop down is visible");
482
483 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
484 doh.is(3, entries.length, "three entries in drop down: " + list.innerHTML);
485 doh.is("California (CA)", innerText(entries[0]), "list #1");
486 doh.is("Colorado (CO)", innerText(entries[1]), "list #2");
487 doh.is("Connecticut (CT)", innerText(entries[2]), "list #3");
488
489 // Check that search-string highlighting is working
490 doh.is('<span class=dijitcomboboxhighlightmatch>c</span>onnecticut (ct)', entries[2].innerHTML.toLowerCase().replace(/"/g, ""), //balanced"
491 "highlighting is working");
492 doh.f(combo.itemError, testWidget + " item mismatch");
493 }), 900);
494
495 return d;
496 }
497 },
498 {
499 timeout:60000,
500 name:"type 'o' after 'C'",
501 runTest:function(){
502 var d = new doh.Deferred();
503 var combo = dijit.byId("setvaluetest");
504 combo.itemError = false;
505
506 // Filter drop down list to entries starting with "Co"
507 doh.robot.keyPress("o", 100);
508
509 doh.robot.sequence(d.getTestCallback(function(){
510 // Check that drop down list is still there, and California has disappeared
511 var list = dojo.byId("setvaluetest_popup");
512 doh.t(list, "drop down exists");
513 doh.t(isVisible(list), "drop down is visible");
514
515 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
516 doh.is(2, entries.length, "three entries in drop down: " + list.innerHTML);
517 doh.is("Colorado (CO)", innerText(entries[0]), "list #1");
518 doh.is("Connecticut (CT)", innerText(entries[1]), "list #2");
519 doh.f(combo.itemError, testWidget + " item mismatch");
520 }), 900);
521
522 return d;
523 }
524 },
525 {
526 timeout:60000,
527 name:"type backspace",
528 runTest:function(){
529 var d = new doh.Deferred();
530 var combo = dijit.byId("setvaluetest");
531 combo.itemError = false;
532
533 doh.robot.keyPress(dojo.keys.BACKSPACE, 100);
534
535 doh.robot.sequence(d.getTestCallback(function(){
536 // List should again contain California
537 var list = dojo.byId("setvaluetest_popup");
538 doh.t(list, "drop down exists");
539 doh.t(isVisible(list), "drop down is visible");
540
541 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
542 doh.is(3, entries.length, "three entries in drop down: " + list.innerHTML);
543 doh.is("California (CA)", innerText(entries[0]), "list #1");
544 doh.is("Colorado (CO)", innerText(entries[1]), "list #2");
545 doh.is("Connecticut (CT)", innerText(entries[2]), "list #3");
546 doh.f(combo.itemError, testWidget + " item mismatch");
547 }), 900);
548
549 return d;
550 }
551 }
552
553 // TODO: make separate test group for testing highlighting, and then check
554 // - matching of anywhere in string (id=arrowless)
555 // - highlightmatch=none (combobox4)
556 ]);
557
558 // Test auto complete
559 doh.register("auto-complete", [
560 {
561 timeout:60000,
562 name:"no auto-complete",
563 runTest:function(){
564 var d = new doh.Deferred();
565 var combo = dijit.byId("setvaluetest");
566
567 combo.focusNode.focus();
568 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
569
570 // Filter drop down list to entries starting with "C"
571 doh.robot.keyPress("C", 100);
572
573 // Then tab away
574 doh.robot.keyPress(dojo.keys.TAB, 500);
575
576 doh.robot.sequence(d.getTestCallback(function(){
577 // Check that drop down list has disappeared
578 var list = dojo.byId("setvaluetest_popup");
579 doh.t(!list || isHidden(list), "drop down is visible");
580
581 // Since autocomplete=false the contents should just be what the user typed
582 doh.is('C', combo.focusNode.value);
583 if(!isComboBox){
584 doh.f(dijit.byId("setvaluetest").isValid(), "FilteringSelect shouldn't be valid");
585 }
586 doh.f(dijit.byId("setvaluetest").itemError, testWidget + " item mismatch");
587 }), 900);
588
589 return d;
590 }
591 },
592 {
593 timeout:60000,
594 name:"auto-complete writes suggested letters in input box",
595 runTest:function(){
596 var d = new doh.Deferred();
597 var combo = dijit.byId("datatest"); // auto-complete = true
598
599 combo.focusNode.focus();
600 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
601
602 // Filter drop down list to entries starting with "C"
603 doh.robot.keyPress("C", 100);
604
605 doh.robot.sequence(d.getTestCallback(function(){
606 var list = dojo.byId("datatest_popup");
607 doh.t(isVisible(list), "drop down is visible");
608
609 doh.is('California', combo.focusNode.value, "'alifornia' automatically appended to user input");
610 }), 900);
611
612 return d;
613 }
614 },
615 {
616 timeout:60000,
617 name:"auto-complete changes suggestion based on more typed letters",
618 runTest:function(){
619 var d = new doh.Deferred();
620 var combo = dijit.byId("datatest");
621
622 // Further filter drop down to entries starting with "Co" (Colorado and Connectictut).
623 // Note that this depends on (and tests that) "alifornia" is selected (aka highlighted),
624 // so that the "o" keypress erases it and replaces the input box text with "Co"
625 doh.robot.keyPress("o", 100);
626
627 doh.robot.sequence(d.getTestCallback(function(){
628 doh.is('Colorado', combo.focusNode.value, "suggestion changed from California to Colorado");
629 }), 900);
630
631 return d;
632 }
633 },
634 {
635 timeout:60000,
636 name:"tab-away auto-selects value",
637 runTest:function(){
638 var d = new doh.Deferred();
639 var combo = dijit.byId("datatest");
640
641 // Then tab away
642 doh.robot.keyPress(dojo.keys.TAB, 500);
643
644 doh.robot.sequence(d.getTestCallback(function(){
645 // Check that drop down list has disappeared
646 var list = dojo.byId("datatest_popup");
647 doh.t(!list || isHidden(list), "drop down is hidden");
648
649 doh.is(isComboBox ? "Colorado" : "CO", combo.get("value"));
650 if(!isComboBox){
651 doh.t(combo.isValid(), "FilteringSelect should be valid");
652 }
653 }), 900);
654
655 return d;
656 }
657 }
658 ]);
659
660 // TODO: test ESC key or click on screen background or click on another widget to close drop down
661
662 // TODO: click test for arrowless
663
664 !isComboBox && doh.register("reverse lookup query options", [
665 {
666 timeout: 60000,
667 name: "delaware",
668 runTest: function(){
669 var d = new doh.Deferred();
670 var combo = dijit.byId("arrowless");
671
672 combo.set("value", null);
673 combo.focusNode.focus();
674
675 doh.robot.typeKeys("delaware", 500, 100);
676 doh.robot.keyPress(dojo.keys.TAB, 1000);
677
678 doh.robot.sequence(d.getTestCallback(function(){
679 // Value should have been converted to "Delaware" (in upper case) and marked as valid
680 doh.is("Delaware", combo.focusNode.value);
681 doh.is("", combo.state, "marked as valid");
682 }), 1000);
683
684 return d;
685 }
686 }
687 ]);
688
689 // Race condition tests based on slow store:
690 // Test that drop down choices are filtered to values matching what user has typed
691 doh.register("race conditions", [
692 // Test when queries return in different order than issued
693 {
694 timeout:60000,
695 name:"query canceling on new input (#8950)",
696 runTest: function(){
697 var d = new doh.Deferred();
698 var combo = dijit.byId("slow");
699 combo.set('displayedValue', null, false);
700
701 combo.focusNode.focus();
702 // this test is very timing-sensitive
703 // preload states.json for slow networks
704 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000);
705 doh.robot.sequence(function(){ dojo.global.slowStateStore.log = []; }, 2000, 100); // clear log of query on * messages
706
707 // Filter drop down list to entries starting with "C"
708 doh.robot.typeKeys("c", 500, 100);
709 doh.robot.typeKeys("o", 300, 100); // 300ms > searchDelay, so C* query has been sent (but not yet returned results) when the o is typed
710
711 doh.robot.sequence(d.getTestCallback(function(){
712 // The query "c*" should be canceled when "co*" is started
713 var log = dojo.global.slowStateStore.log;
714 doh.is(4, log.length, "4 events on data store");
715 doh.is("start c*", log[0].type + " " + log[0].query.name);
716 doh.is("cancel c*", log[1].type + " " + log[1].query.name);
717 doh.is("start co*", log[2].type + " " + log[2].query.name);
718 doh.is("end co*", log[3].type + " " + log[3].query.name);
719
720 // Check that drop down list has appeared, and contains only Colorado and Connecticut (not California)
721 var list = dojo.byId("slow_popup");
722 doh.t(list, "drop down exists");
723 doh.t(isVisible(list), "drop down is visible");
724
725 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
726 doh.is(2, entries.length, "two entries in drop down: " + list.innerHTML);
727 doh.is("Colorado", innerText(entries[0]), "list #1");
728 doh.is("Connecticut", innerText(entries[1]), "list #2");
729 }), 1000, 500);
730
731 return d;
732 }
733 },
734
735 // Test that drop down doesn't show up after ENTER keypress, and also that
736 // searchDelay is preventing intermediate queries.
737 {
738 timeout:60000,
739 name:"pressing enter before search returns",
740 setUp: function(){
741 dojo.global.slowStateStore.log = [];
742 },
743 runTest: function(){
744 var d = new doh.Deferred();
745 var combo = dijit.byId("slow");
746
747 dojo.global.formSubmitted = false;
748 dijit.form._TextBoxMixin.selectInputText(combo.focusNode);
749
750 // Start to filter drop down list to entries starting with "Co"
751 doh.robot.typeKeys("C", 500, 0);
752 doh.robot.typeKeys("o", 300, 0); // 300ms > searchDelay, so C* query has been sent (but not yet returned results) when the o is typed
753
754 // But then hit ENTER after we've started the query to the data store, but
755 // before the data store returns query results... that should cancel the query.
756 doh.robot.keyPress(dojo.keys.ENTER, 300); // 300ms > searchDelay
757
758 doh.robot.sequence(d.getTestCallback(function(){
759 var log = dojo.global.slowStateStore.log;
760 var len = log.length;
761 doh.t(len >= 4, "log length " + len);
762 doh.is("start C*", log[0].type + " " + log[0].query.name);
763 doh.is("cancel C*", log[1].type + " " + log[1].query.name);
764 doh.is("start Co*", log[2].type + " " + log[2].query.name);
765 doh.is("cancel Co*", log[3].type + " " + log[3].query.name);
766
767 // also, form SHOULD have submitted because no popup was visible
768 doh.t(dojo.global.formSubmitted, "form submitted");
769
770 var list = dojo.byId("slow_popup");
771 doh.t(!list || isHidden(list), "drop down is *not* visible");
772
773 doh.is("Co", combo.get('displayedValue'), "auto-complete didn't fire");
774 }), 1200, 500);
775
776 return d;
777 }
778 }
779 ]);
780
781 // disabled tests+standard tests
782 doh.register("disabled", [
783
784 // Test that correct styling is applied
785 {
786 timeout:1000,
787 name:"disabled styling",
788 combo:"combo3",
789 runTest:function(){
790 this.combo = dijit.byId(this.combo);
791 doh.is(true, this.combo.get('disabled'));
792 doh.is(true, this.combo.focusNode.disabled);
793 }
794 },
795
796 // Test that you can't focus a disabled combobox
797 {
798 timeout: 5000,
799 name:"tab over disabled elements",
800 runTest: function(){
801 var d = new doh.Deferred();
802
803 dojo.byId("datatestDijit").focus();
804
805 doh.robot.sequence(d.getTestErrback(function(){
806 // use sequence because focus on IE9+ is asynchronous
807 doh.is("datatestDijit", dojo.global.dijit.focus.curNode.id, "focused on elem before disabled combo");
808 }), 100);
809
810 // Tab over the disabled ComboBox
811 doh.robot.keyPress(dojo.keys.TAB, 100);
812
813 doh.robot.sequence(d.getTestCallback(function(){
814 doh.is("combobox4", dojo.global.dijit.focus.curNode.id, "focused on 'enable' button after disabled combo");
815 }), 200);
816
817 return d;
818 }
819 }
820 ]);
821
822 // now enable it and test that it can be used
823 doh.register("enabled", [
824 {
825 timeout:30000,
826 name:"combo3_enabledStyle",
827 setUp: function(){
828 dijit.byId("combo3").set("disabled", false);
829 },
830 runTest:function(){
831 var combo = dijit.byId("combo3");
832 doh.is(false, combo.get('disabled'));
833 doh.is(false, combo.focusNode.disabled);
834 }
835 }
836 ]);
837
838 doh.register("specialchars", [
839 {
840 timeout:10000,
841 name:"specialchars_type",
842 combo:"specialchars",
843 runTest:function(){
844 return robot_typeValue(dijit.byId(this.combo), "sticks & stones", isComboBox? undefined : "sticks");
845 }
846 },
847 {
848 timeout:10000,
849 name:"specialchars_a11y",
850 combo:"specialchars",
851 runTest:function(){
852 return robot_a11ySelectValue(dijit.byId(this.combo), "more\\less", isComboBox? undefined : "more");
853 }
854 },
855 {
856 timeout:10000,
857 name:"specialchars_escape",
858 combo:"specialchars",
859 runTest:function(){
860 var combo = dijit.byId(this.combo);
861 combo.focusNode.focus();
862 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
863 var d = new doh.Deferred();
864 doh.robot.typeKeys("3 *", 500, 600);
865 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
866 doh.robot.sequence(d.getTestCallback(function(){
867 doh.is("3 *", combo.focusNode.value);
868 }), 500);
869 return d;
870 }
871 },
872 {
873 timeout:10000,
874 name:"specialchars_highlight",
875 combo:"specialchars",
876 runTest:function(){
877 var combo = dijit.byId(this.combo);
878 combo.queryExpr = '*${0}*';
879 combo.focusNode.focus();
880 doh.robot.sequence(function(){ combo.set("value", null); }, 500);
881 var d = new doh.Deferred();
882 doh.robot.typeKeys("t", 1, 100);
883 doh.robot.sequence(d.getTestCallback(function(){
884 var item = findMenuItem(combo, 'riches to');
885 doh.t(item, 'item "rags --> riches to" should be visible');
886 doh.is('rags --&gt; riches <>t<>o',item.innerHTML.replace(/<[^>]*>/g,'<>'), '"t" in "to" should be highlighted');
887 }), 1000, 500);
888 return d;
889 }
890 }
891 ]);
892
893 doh.register("japanese", [
894 {
895 timeout:60000,
896 name:"japanese_a11y",
897 combo:"japanese",
898 runTest:function(){
899 return robot_a11ySelectValue((this.combo = dijit.byId(this.combo)), "\u6771\u533A (East)", isComboBox? undefined : "higashiku");
900 },
901 tearDown:function(){
902 this.combo.set("value", isComboBox?"\u6771\u533A (East)":"higashiku");
903 }
904 },
905
906 {
907 timeout:20000,
908 name:"japanese_type",
909 runTest:function(){
910 var d = new doh.Deferred(),
911 s0 = null,
912 s1 = null,
913 s2 = null,
914 s3 = null,
915 s4 = null,
916 s5 = null,
917 combo = dijit.byId("japanese");
918
919 combo.focusNode.focus();
920
921 doh.robot.keyPress(dojo.keys.END, 1000);
922
923 doh.robot.typeKeys("x", 500, 200);
924 doh.robot.sequence(function(){
925 s0 = combo.state;
926 }, 500);
927 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
928 doh.robot.sequence(function(){
929 s1 = combo.state;
930 }, 500);
931 doh.robot.typeKeys("xx", 500, 400);
932 doh.robot.sequence(function(){
933 s2 = combo.state;
934 }, 500);
935 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
936 doh.robot.sequence(function(){
937 s3 = combo.state;
938 }, 500);
939 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
940 doh.robot.sequence(function(){
941 s4 = combo.state;
942 }, 500);
943 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
944 doh.robot.sequence(function(){
945 s5 = combo.state;
946 }, 500);
947 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
948 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
949 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
950 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
951 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
952 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
953 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
954 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500);
955 doh.robot.keyPress(dojo.keys.ENTER, 500);
956 doh.robot.sequence(dojo.hitch(this, function(){
957 if(!isComboBox){
958 doh.is("Error", s0, "s0");
959 doh.is("Incomplete", s1, "s1");
960 doh.is("Error", s2, "s2");
961 doh.is("Error", s3, "s3");
962 doh.is("Incomplete", s4, "s4");
963 doh.is("Incomplete", s5, "s5");
964 }
965 if(combo.get("value") == (isComboBox?"\u6771\u897F (Touzai)":"touzai") && combo.focusNode.value=="\u6771\u897F (Touzai)"){
966 d.callback(true);
967 }else{
968 d.errback(combo.id+" was supposed to have a value of "+(isComboBox?"\u6771\u897F (Touzai)":"touzai")+". Text is "+combo.focusNode.value+", value is "+combo.get("value"));
969 }
970 }), 1000);
971 return d;
972 }
973 }
974 ]);
975
976 doh.register("readOnly", [
977 {
978 timeout:5000,
979 name:"cannot type",
980 combo: "labelFunc",
981 runTest:function(){
982 var d = new doh.Deferred(),
983 combo = dijit.byId(this.combo),
984 initVal = combo.get('value');
985 combo.set('readOnly', true);
986 combo.focus();
987 doh.robot.typeKeys("xz", 1000, 500);
988 doh.robot.sequence(d.getTestCallback(function(){
989 doh.t(combo.isValid(), 'isValid');
990 doh.is(initVal, combo.get('value'), 'changed from ' + initVal + ' to ' + combo.get('value'));
991 }), 500, 500);
992 return d;
993 },
994 tearDown:function(){
995 dijit.byId(this.combo).set("readOnly", false);
996 }
997 }
998 ]);
999
1000 // Labelfunc tests. See also initial tests on "setvaluetest" ComboBox.
1001 doh.register("labelFunc", [
1002 {
1003 timeout:60000,
1004 name:"labelFunc_keyboardSelect",
1005 combo:"labelFunc",
1006 runTest:function(){
1007 return robot_a11ySelectValue((this.combo = dijit.byId(this.combo)), "texas", isComboBox? "Texas" : "TX", "Texas");
1008 },
1009 tearDown:function(){
1010 this.combo.set("value", isComboBox? "Texas" : "TX");
1011 }
1012 },
1013
1014 {
1015 timeout:60000,
1016 name:"labelFunc_type",
1017 combo:"labelFunc",
1018 runTest:function(){
1019 return robot_typeValue((this.combo = dijit.byId(this.combo)), "Alabama", isComboBox ? "Alabama" : "AL", "Alabama");
1020 }
1021 },
1022
1023 {
1024 timeout:60000,
1025 name: "richtext",
1026 runTest: function(){
1027 var d = new doh.Deferred(),
1028 w = dijit.byId("richtexttest");
1029
1030 // testing that input has right data
1031 doh.is("h1", w.focusNode.value, "initial focus value");
1032 w.set("value", "h2");
1033 doh.is("h2", w.focusNode.value, "set() focus value");
1034
1035 w.focus();
1036
1037 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 100);
1038
1039 doh.robot.sequence(d.getTestCallback(function(){
1040 var list = dojo.byId("richtexttest_popup");
1041 doh.t(list, "drop down exists");
1042 doh.t(isVisible(list), "drop down is visible");
1043
1044 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
1045 doh.is("<h1>h1</h1>", dojo.trim(entries[0].innerHTML).toLowerCase(), "list #1 is rich text");
1046 }), 500);
1047
1048 return d;
1049 }
1050 }
1051 ]);
1052
1053 // The specifying a sort order and an initial filter to ComboBox
1054 doh.register("filter and sort params", [
1055 {
1056 timeout:60000,
1057 name:"sort order",
1058 runTest:function(){
1059 var d = new doh.Deferred();
1060 var combo = dijit.byId("progCombo3");
1061
1062 combo.focusNode.focus();
1063 doh.robot.sequence(function(){ combo.set("value", null); }, 1000);
1064
1065 // Show list, should be in reverse order
1066 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 100);
1067
1068 doh.robot.sequence(d.getTestCallback(function(){
1069 var list = dojo.byId("progCombo3_popup");
1070 doh.t(list, "drop down exists");
1071 doh.t(isVisible(list), "drop down is visible");
1072
1073 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
1074 doh.is("United States of America", innerText(entries[0]), "list #1");
1075 }), 900);
1076
1077 return d;
1078 }
1079 },
1080 {
1081 timeout:60000,
1082 name:"initial filter, descending sort",
1083 runTest:function(){
1084 var d = new doh.Deferred();
1085 var combo = dijit.byId("progCombo3");
1086
1087 // Filter drop down list to entries starting with "A"
1088 doh.robot.keyPress("A", 100);
1089
1090 doh.robot.sequence(d.getTestCallback(function(){
1091 // Check that drop down list *doesn't* contain Africa (since it's a continent),
1092 // just Argentina and Australia, in descending sort order
1093 var list = dojo.byId("progCombo3_popup");
1094 doh.t(list, "drop down exists");
1095 doh.t(isVisible(list), "drop down is visible");
1096
1097 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
1098 doh.is(2, entries.length, "two countries (but no continents) in drop down: " + list.innerHTML);
1099 doh.is("Australia", innerText(entries[0]), "list #1");
1100 doh.is("Argentina", innerText(entries[1]), "list #2");
1101 }), 900);
1102
1103 return d;
1104 }
1105 }
1106 ]);
1107
1108 // The specifying a sort order and an initial filter to ComboBox
1109 doh.register("blur", [
1110 {
1111 timeout:60000,
1112 name:"tooltip prompt",
1113 runTest:function(){
1114 var d = new doh.Deferred();
1115 var combo = dijit.byId("labelFunc");
1116
1117 combo.set("value", null);
1118 combo.focusNode.focus();
1119
1120 // blur
1121 doh.robot.keyPress(dojo.keys.TAB, 1000);
1122
1123 doh.robot.sequence(d.getTestCallback(function(){
1124 doh.t(!combo._message, "no tooltip on blur");
1125 }), 1000);
1126
1127 return d;
1128 }
1129 },
1130 {
1131 timeout:60000,
1132 name:"empty but required",
1133 runTest:function(){
1134 var d = new doh.Deferred();
1135 var combo = dijit.byId("combobox4");
1136
1137 combo.set("value", null);
1138 combo.focusNode.focus();
1139
1140 // blur
1141 doh.robot.keyPress(dojo.keys.TAB, 1000);
1142
1143 doh.robot.sequence(d.getTestCallback(function(){
1144 doh.t(combo.state == "Error", "required field has error on blur");
1145 }), 1000);
1146
1147 return d;
1148 }
1149 }
1150 ]);
1151
1152 doh.register("wrap", [
1153 {
1154 timeout:10000,
1155 name:"wrap without More choices",
1156 runTest:function(){
1157 var d = new doh.Deferred();
1158 var combo = dijit.byId("preservetitletest");
1159
1160 combo.set('pageSize', 5); // remove More choices
1161 combo.focusNode.focus();
1162
1163 // Show list, should be in reverse order
1164 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000); // wait for focus
1165 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // wait for dropdown to open
1166 for(var i=1; i < 14; i++){
1167 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 250); // down arrow and wrap twice
1168 }
1169 for(i=0; i < 4; i++){
1170 doh.robot.keyPress(dojo.keys.UP_ARROW, 250); // up arrow and wrap at most once
1171 }
1172 doh.robot.keyPress(dojo.keys.ENTER, 500); // select current item
1173 doh.robot.sequence(d.getTestCallback(function(){
1174 doh.is(isComboBox ? "Vermont" : "vt", combo.get("value"), "wrap get('value')");
1175 }), 1000);
1176
1177 return d;
1178 }
1179 },
1180 {
1181 timeout:10000,
1182 name:"wrap with More choices",
1183 runTest:function(){
1184 var d = new doh.Deferred();
1185 var combo = dijit.byId("preservetitletest");
1186
1187 combo.set('pageSize', 4); // add More choices
1188 combo.focusNode.focus();
1189
1190 // Show list, should be in reverse order
1191 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000); // wait for focus
1192 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // wait for dropdown to open
1193 for(var i=1; i < 14; i++){
1194 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 250); // down arrow and wrap twice
1195 }
1196 for(i=0; i < 5; i++){
1197 doh.robot.keyPress(dojo.keys.UP_ARROW, 200); // up arrow and wrap at most once
1198 }
1199 doh.robot.keyPress(dojo.keys.ENTER, 500); // select current item
1200 doh.robot.sequence(d.getTestCallback(function(){
1201 doh.is(isComboBox ? "Massachusetts" : "ma", combo.get("value"), "wrap get('value')");
1202 }), 1000);
1203
1204 return d;
1205 }
1206 },
1207 {
1208 timeout:10000,
1209 name:"wrap and TAB from Prev choices",
1210 runTest:function(){
1211 var d = new doh.Deferred();
1212 var combo = dijit.byId("preservetitletest");
1213
1214 combo.set('pageSize', 4); // add More choices
1215 combo.set("value", isComboBox ? "Maine" : "me", true); // fires onChange
1216 combo.set("value", isComboBox ? "Connecticut" : "ct", false); // temporary value
1217 combo.focusNode.focus();
1218
1219 // Show list, should be in reverse order
1220 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000); // wait for focus
1221 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // wait for dropdown to open
1222 for(var i=1; i < 5; i++){
1223 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 250); // down arrow to More choices
1224 }
1225 doh.robot.keyPress(dojo.keys.ENTER, 500); // select More choices
1226 doh.robot.keyPress(dojo.keys.UP_ARROW, 1000); // up arrow to Previous choices
1227 doh.robot.keyPress(dojo.keys.TAB, 500); // select current item
1228 doh.robot.sequence(d.getTestCallback(function(){
1229 doh.is(isComboBox ? "Maine" : "me", combo.get("value"), "Previous choice reverts value");
1230 }), 1000);
1231
1232 return d;
1233 }
1234 }
1235 ]);
1236
1237 var pageSize, combo;
1238 // Test more choices
1239 doh.register("Select More choices", [
1240 {
1241 timeout:10000,
1242 name:"no auto-complete",
1243 setUp: function(){
1244 combo = dijit.byId("setvaluetest");
1245 pageSize = combo.get('pageSize');
1246 combo.set('pageSize', 1);
1247 combo.set('displayedValue', null, false);
1248 combo.focusNode.focus();
1249 },
1250 runTest: function(){
1251 var d = new doh.Deferred();
1252
1253 // select more choices and press Enter
1254 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1500); // open dropdown
1255 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // select Alabama
1256 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // select more choices
1257 doh.robot.keyPress(dojo.keys.ENTER, 500);
1258
1259 doh.robot.sequence(d.getTestCallback(function(){
1260 // Check that drop down list has disappeared
1261 var list = dojo.byId("setvaluetest_popup");
1262 doh.t(list && isVisible(list), "drop down is visible");
1263 doh.is(combo.dropDown.getHighlightedOption(), findMenuItem(combo, "Alaska"), "Alaska is selected");
1264
1265 doh.t(combo.focused, "widget is focused");
1266
1267 // Since the user down arrowed thru the choices, the value should be the current selection
1268 doh.is('Alaska', combo.focusNode.value);
1269 if(!isComboBox){
1270 doh.t(combo.isValid(true), "FilteringSelect should be valid");
1271 }
1272 }), 1000, 500);
1273
1274 return d;
1275 },
1276 tearDown: function(){
1277 combo.set('pageSize', pageSize);
1278 combo.closeDropDown();
1279 }
1280 },
1281 {
1282 timeout:10000,
1283 name:"auto-complete",
1284 setUp: function(){
1285 combo = dijit.byId("datatest");
1286 pageSize = combo.get('pageSize');
1287 combo.set('pageSize', 1);
1288 combo.set('displayedValue', null, false);
1289 combo.focusNode.focus();
1290 },
1291 runTest: function(){
1292 var d = new doh.Deferred();
1293
1294 // select more choices and press Enter
1295 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1500); // open dropdown
1296 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // select Alabama
1297 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); // select more choices
1298 doh.robot.keyPress(dojo.keys.ENTER, 500);
1299
1300 doh.robot.sequence(d.getTestCallback(function(){
1301 // Check that drop down list has disappeared
1302 var list = dojo.byId("datatest_popup");
1303 doh.t(list && isVisible(list), "drop down is visible");
1304 doh.is(combo.dropDown.getHighlightedOption(), findMenuItem(combo, "Alaska"), "Alaska is selected");
1305
1306 doh.t(combo.focused, "widget is focused");
1307
1308 // Since the user down arrowed thru the choices, the value should be the current selection
1309 doh.is('Alaska', combo.focusNode.value);
1310 if(!isComboBox){
1311 doh.t(combo.isValid(true), "FilteringSelect should be valid");
1312 }
1313 }), 1000, 500);
1314
1315 return d;
1316 },
1317 tearDown: function(){
1318 combo.set('pageSize', pageSize);
1319 combo.closeDropDown();
1320 }
1321 }
1322 ]);
1323
1324 doh.register("onChange", [
1325 {
1326 timeout:6000,
1327 name:"11062",
1328 runTest:function(){
1329 var d = new doh.Deferred();
1330 var combo = dijit.byId("progCombo");
1331 var status = "not called";
1332 var connectHandle = combo.connect(combo, "onChange", function(){
1333 status = "called";
1334 });
1335 combo.focusNode.focus();
1336 doh.robot.keyPress(dojo.keys.TAB, 500); // blur
1337
1338 doh.robot.sequence(d.getTestCallback(function(){
1339 combo.disconnect(connectHandle);
1340 doh.is("not called", status, "onChange should not have been called");
1341 }), 500);
1342
1343 return d;
1344 }
1345 },
1346 {
1347 timeout:2000,
1348 name:"10988.0",
1349 runTest:function(){
1350 var d = new doh.Deferred();
1351 var combo = dijit.byId("progCombo");
1352 var value = isComboBox ? 'Kentucky' : 'KY';
1353 combo._lastValueReported = combo._lastValue = value;
1354 var status = "not called";
1355 var connectHandle = combo.connect(combo, "onChange", function(v){
1356 status = "called with " + v;
1357 });
1358 combo.set('value', value, true);
1359 doh.robot.sequence(d.getTestCallback(function(){
1360 combo.disconnect(connectHandle);
1361 combo._pendingOnChange = false;
1362 doh.is("not called", status, "onChange should not have been called");
1363 }), 500);
1364 return d;
1365 }
1366 },
1367 {
1368 timeout:2000,
1369 name:"10988.1",
1370 runTest:function(){
1371 var d = new doh.Deferred();
1372 var combo = dijit.byId("progCombo");
1373 var value1 = isComboBox ? 'Kentucky' : 'KY';
1374 var value2 = isComboBox ? 'Texas' : 'TX';
1375 combo._lastValueReported = combo._lastValue = value1;
1376 var status = "not called";
1377 var connectHandle = combo.connect(combo, "onChange", function(v){
1378 status = "called with " + v;
1379 });
1380 combo.set('value', value2, false);
1381 doh.robot.sequence(d.getTestCallback(function(){
1382 combo.disconnect(connectHandle);
1383 combo._pendingOnChange = false;
1384 doh.is("not called", status, "onChange should not have been called");
1385 }), 500);
1386 return d;
1387 }
1388 },
1389 {
1390 timeout:2000,
1391 name:"10988.2",
1392 runTest:function(){
1393 var d = new doh.Deferred();
1394 var combo = dijit.byId("progCombo");
1395 var value1 = isComboBox ? 'Kentucky' : 'KY';
1396 var value2 = isComboBox ? 'Texas' : 'TX';
1397 combo._lastValueReported = combo._lastValue = value2;
1398 var status = "not called";
1399 var connectHandle = combo.connect(combo, "onChange", function(v){
1400 status = "called with " + v;
1401 });
1402 combo.set('value', value1, false);
1403 combo.set('value', value2);
1404 doh.robot.sequence(d.getTestCallback(function(){
1405 combo.disconnect(connectHandle);
1406 combo._pendingOnChange = false;
1407 doh.is("called with "+value2, status, "onChange should have been called with "+value2);
1408 }), 500);
1409 return d;
1410 }
1411 },
1412 {
1413 timeout:2000,
1414 name:"10988.3",
1415 runTest:function(){
1416 var d = new doh.Deferred();
1417 var combo = dijit.byId("progCombo");
1418 var value1 = isComboBox ? 'Kentucky' : 'KY';
1419 var value2 = isComboBox ? 'Texas' : 'TX';
1420 combo._lastValueReported = combo._lastValue = value2;
1421 var status = "not called";
1422 var connectHandle = combo.connect(combo, "onChange", function(v){
1423 status = "called with " + v;
1424 });
1425 combo.set('value', value1, false);
1426 combo.set('value', value2, false);
1427 combo.set('value', value2, true);
1428 doh.robot.sequence(d.getTestCallback(function(){
1429 combo.disconnect(connectHandle);
1430 combo._pendingOnChange = false;
1431 doh.is("called with "+value2, status, "onChange should have been called with "+value2);
1432 }), 500);
1433 return d;
1434 }
1435 },
1436 {
1437 timeout:2000,
1438 name:"10988.4",
1439 runTest:function(){
1440 var d = new doh.Deferred();
1441 var combo = dijit.byId("progCombo");
1442 var value = isComboBox ? 'Kentucky' : 'KY';
1443 combo._lastValueReported = combo._lastValue = value;
1444 var status = "not called";
1445 var connectHandle = combo.connect(combo, "onChange", function(v){
1446 status = "called with " + v;
1447 });
1448 combo.set('value', value, false);
1449 combo.set('value', value, true);
1450 doh.robot.sequence(d.getTestCallback(function(){
1451 combo.disconnect(connectHandle);
1452 combo._pendingOnChange = false;
1453 doh.is("not called", status, "onChange should not have been called");
1454 }), 500);
1455 return d;
1456 }
1457 },
1458 {
1459 timeout:2000,
1460 name:"10988.5",
1461 runTest:function(){
1462 var d = new doh.Deferred();
1463 var combo = dijit.byId("progCombo");
1464 var value1 = isComboBox ? 'Kentucky' : 'KY';
1465 var value2 = isComboBox ? 'Texas' : 'TX';
1466 combo._lastValueReported = combo._lastValue = value2;
1467 var status = "not called";
1468 var connectHandle = combo.connect(combo, "onChange", function(v){
1469 status = "called with " + v;
1470 });
1471 combo.set('value', value1, false);
1472 combo.set('value', value2, true);
1473 combo.set('value', value1, false);
1474 doh.robot.sequence(d.getTestCallback(function(){
1475 combo.disconnect(connectHandle);
1476 combo._pendingOnChange = false;
1477 doh.is("called with "+value2, status, "onChange should have been called with "+value2);
1478 }), 500);
1479 return d;
1480 }
1481 },
1482 {
1483 timeout:2000,
1484 name:"10988.6",
1485 runTest:function(){
1486 var d = new doh.Deferred();
1487 var combo = dijit.byId("progCombo");
1488 var value1 = isComboBox ? 'Kentucky' : 'KY';
1489 var value2 = isComboBox ? 'Texas' : 'TX';
1490 combo._lastValueReported = combo._lastValue = value1;
1491 var status = "not called";
1492 var connectHandle = combo.connect(combo, "onChange", function(v){
1493 status = "called with " + v;
1494 });
1495 combo.set('value', value2, true);
1496 doh.robot.sequence(d.getTestCallback(function(){
1497 combo.disconnect(connectHandle);
1498 combo._pendingOnChange = false;
1499 doh.is("called with "+value2, status, "onChange should have been called with true"+value2);
1500 }), 500);
1501 return d;
1502 }
1503 },
1504 {
1505 timeout:2000,
1506 name:"10988.7",
1507 runTest:function(){
1508 var d = new doh.Deferred();
1509 var combo = dijit.byId("progCombo");
1510 var value1 = isComboBox ? 'Kentucky' : 'KY';
1511 var value2 = isComboBox ? 'Texas' : 'TX';
1512 combo._lastValueReported = combo._lastValue = value2;
1513 var status = "not called";
1514 var connectHandle = combo.connect(combo, "onChange", function(v){
1515 status = "called with " + v;
1516 });
1517 combo.set('value', value1, false);
1518 combo.set('value', value1, true);
1519 doh.robot.sequence(d.getTestCallback(function(){
1520 combo.disconnect(connectHandle);
1521 combo._pendingOnChange = false;
1522 doh.is("called with "+value1, status, "onChange should have been called with "+value1);
1523 }), 500);
1524 return d;
1525 }
1526 }
1527 ]);
1528
1529 doh.register("destroy", [
1530 {
1531 timeout: 1000,
1532 name: "destroy",
1533 runTest: function(){
1534 var d = new doh.Deferred();
1535 doh.robot.sequence(d.getTestCallback(function(){
1536 dijit.byId("combo_01").destroy();
1537 doh.is(undefined, dojo.byId("combo_01"), 'widget was removed');
1538 doh.f(dojo.byId('destroyDiv').firstChild, 'container node is empty');
1539 }), 0);
1540 return d;
1541 }
1542 }
1543 ]);
1544
1545 dojo.forEach(
1546 [
1547 { attrs: { ignoreCase:true, highlightMatch:"first", queryExpr:"${0}*" }, results: { AA: "<>A<>A", Aa: "<>A<>a", aA: "<>a<>A", aa: "<>a<>a" } },
1548 { attrs: { ignoreCase:false, highlightMatch:"first", queryExpr:"${0}*" }, results: { aA: "<>a<>A", aa: "<>a<>a" } },
1549 { attrs: { ignoreCase:true, highlightMatch:"all", queryExpr:"${0}*" }, results: { AA: "<>A<>A", Aa: "<>A<>a", aA: "<>a<>A", aa: "<>a<>a" } },
1550 { attrs: { ignoreCase:true, highlightMatch:"all", queryExpr:"*${0}*" }, results: { AA: "<>A<><>A<>", Aa: "<>A<><>a<>", aA: "<>a<><>A<>", aa: "<>a<><>a<>" } },
1551 { attrs: { ignoreCase:false, highlightMatch:"all", queryExpr:"*${0}*" }, results: { Aa: "A<>a<>", aA: "<>a<>A", aa: "<>a<><>a<>" } },
1552 { attrs: { ignoreCase:false, highlightMatch:"none", queryExpr:"*${0}*" }, results: { Aa: "Aa", aA: "aA", aa: "aa" } },
1553 { attrs: { ignoreCase:true, highlightMatch:"all", queryExpr:"*${0}" }, results: { AA: "A<>A<>", Aa: "A<>a<>", aA: "a<>A<>", aa: "a<>a<>" } },
1554 { attrs: { ignoreCase:false, highlightMatch:"first", queryExpr:"*${0}" }, results: { Aa: "A<>a<>", aa: "a<>a<>" } }
1555 ], function(test){
1556 doh.register("highlight", [
1557 {
1558 timeout: 6000,
1559 name: dojo.toJson(test.attrs),
1560 setUp: function(){
1561 combo = dijit.byId("highlight");
1562 dojo.mixin(combo, test.attrs);
1563 combo.focusNode.focus();
1564 },
1565 runTest: function(){
1566 var d = new doh.Deferred();
1567 doh.robot.keyPress(dojo.keys.BACKSPACE, 1000);
1568 doh.robot.typeKeys("a", 1, 100);
1569 doh.robot.sequence(d.getTestCallback(function(){
1570 dojo.forEach(["AA","Aa","aA","aa"], function(idx){
1571 var item = findMenuItem(combo, idx);
1572 if(idx in test.results){
1573 var expected = test.results[idx];
1574 var actual = item.innerHTML.replace(/\/?span\s*[^>]*@?/ig, "");
1575 doh.is(expected, actual, idx);
1576 }else{
1577 doh.t(item == combo.dropDown.nextButton, "too many menu items: " + idx);
1578 }
1579 });
1580 }), 1000, 500);
1581 return d;
1582 },
1583 tearDown: function(){
1584 combo.closeDropDown();
1585 }
1586 }
1587 ]);
1588 }
1589 );
1590
1591 doh.register("custom class", [
1592 // Select a value from the drop down using the keyboard,
1593 // use "more choices" button to page as necessary
1594 {
1595 timeout: 60000,
1596 name:" customstore_a11y",
1597 combo: "subclass",
1598 runTest: function(){
1599 return robot_a11ySelectValue(dijit.byId(this.combo), "Delaware", isComboBox ? "Delaware" : "DE", "Delaware");
1600 }
1601 }
1602 ]);
1603
1604 doh.register("aria-autocomplete (#9089)", [
1605 {
1606 timeout: 1000,
1607 name:"aria-autocomplete with autoComplete enabled",
1608 combo: "autocompleteon",
1609 runTest: function(){
1610 var combo = dijit.byId(this.combo);
1611 doh.is("both", combo.focusNode.getAttribute("aria-autocomplete"), "aria-autocomplete on combo is 'both'");
1612 }
1613 },
1614 {
1615 timeout: 1000,
1616 name:"aria-autocomplete with autoComplete disabled",
1617 combo: "autocompleteoff",
1618 runTest: function(){
1619 var combo = dijit.byId(this.combo);
1620 doh.is("list", combo.focusNode.getAttribute("aria-autocomplete"), "aria-autocomplete on combo is 'list'");
1621 }
1622 }
1623 ]);
1624
1625 doh.run();
1626 });
1627 </script>
1628 </head>
1629 </html>