Debian Codegraph @

dijit/tests/form/robot/_autoComplete_mouse.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 Mouse 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.window");
17 dojo.require("dijit.tests.helpers"); // functions to help test
18
19 // TODO: provide URL toggle for FilteringSelect
20 var testWidget = "dijit.form.ComboBox";
21 var qstr = window.location.search.substr(1);
22 if(qstr.length){
23 var qparts = qstr.split("&");
24 for(var x=0; x<qparts.length; x++){
25 var tp = qparts[x].split("=");
26 if(tp[0] == "testWidget"){
27 testWidget = tp[1];
28 }
29 }
30 }
31 isComboBox = testWidget=="dijit.form.ComboBox";
32 dojo.ready(function(){
33 var pageSize, combo;
34
35 var findMenuItem = function(combo, text){
36 var node = combo.dropDown.domNode.firstChild;
37 while(((node.innerText || node.textContent).indexOf(text) < 0) && node.nextSibling){
38 node = node.nextSibling;
39 }
40 return node;
41 };
42
43 doh.robot.initRobot('../_autoComplete.html?testWidget='+testWidget);
44
45 // Wait for data stores to finish loading before starting tests
46 doh.register("wait for data store load",
47 dojo.map(["store", "store2", "stateStore", "dijitStore"], function(name){
48 return {
49 name: "wait for " + name,
50 timeout: 5000,
51 runTest: function(){
52 var d = new doh.Deferred();
53 dojo.global[name].fetch({
54 onComplete: function(){
55 d.callback(true);
56 },
57 onError: function(e){
58 d.errback(e);
59 }
60 });
61 return d;
62 }
63 };
64 })
65 );
66
67 doh.register("drop down navigation / mouse", [
68 {
69 timeout:6000,
70 name:"open drop down",
71 runTest:function(){
72 var d = new doh.Deferred();
73
74 combo = dijit.byId("setvaluetest");
75
76 // Open drop down
77 doh.robot.mouseMoveAt(combo._buttonNode, 0, 0);
78 doh.robot.mouseClick({left:true}, 500);
79
80 doh.robot.sequence(d.getTestCallback(function(){
81 var list = combo.dropDown.domNode,
82 entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
83 doh.t(isVisible(list), "list is visible");
84 doh.is(31, entries.length, "30 elements plus next button");
85 doh.is("California", combo.focusNode.value, "displayed value hasn't changed");
86 }), 1500, 100);
87
88 return d;
89 }
90 },
91
92 {
93 timeout:9000,
94 name:"next page",
95 runTest:function(){
96 var d = new doh.Deferred();
97
98 combo = dijit.byId("setvaluetest");
99 var list = combo.dropDown.domNode;
100
101 doh.t(isVisible(list), "list is still visible");
102
103 dojo.window.scrollIntoView(combo.dropDown.nextButton);
104 doh.robot.mouseMoveAt(combo.dropDown.nextButton, 1, 0);
105 doh.robot.mouseClick({left:true}, 1000);
106
107 doh.robot.sequence(d.getTestCallback(function(){
108 var entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
109 doh.is("Minnesota (MN)", innerText(entries[1]), "first entry on second page of drop down");
110 doh.is("California", combo.focusNode.value, "displayed value hasn't changed");
111 }), 1500, 1000);
112
113 return d;
114 }
115 },
116
117 {
118 timeout:9000,
119 name:"last page",
120 runTest:function(){
121 var d = new doh.Deferred();
122
123 combo = dijit.byId("setvaluetest");
124 dojo.window.scrollIntoView(combo.dropDown.nextButton);
125 doh.robot.mouseMoveAt(combo.dropDown.nextButton, 1, 0);
126 doh.robot.mouseClick({left:true}, 1000);
127
128 doh.robot.sequence(d.getTestCallback(function(){
129 var list = combo.dropDown.domNode,
130 entries = dojo.query(".dijitMenuItem", list).filter(isVisible);
131 doh.is(2, entries.length, "previous choices + wyoming");
132 doh.is("Wyoming (WY)", innerText(entries[1]));
133 }), 1500, 1000);
134
135 return d;
136 }
137 },
138
139 {
140 timeout:9000,
141 name:"previous page",
142 runTest:function(){
143 var d = new doh.Deferred();
144
145 combo = dijit.byId("setvaluetest");
146 dojo.window.scrollIntoView(combo.dropDown.previousButton);
147 doh.robot.mouseMoveAt(combo.dropDown.previousButton, 0, 0);
148 doh.robot.mouseClick({left:true}, 1000);
149
150 doh.robot.sequence(d.getTestCallback(function(){
151 var list = combo.dropDown.domNode,
152 entries = dojo.query(".dijitMenuItem", list);
153 doh.is(32, entries.length, "30 states, plus next and previous button");
154 doh.is("Minnesota (MN)", innerText(entries[1]));
155 doh.is("Wisconsin (WI)", innerText(entries[30]));
156 doh.is("California", combo.focusNode.value, "displayed value hasn't changed");
157 }), 1500, 1000);
158
159 return d;
160 }
161 },
162
163 {
164 timeout:6000,
165 name:"select value",
166 runTest:function(){
167 var d = new doh.Deferred();
168
169 combo = dijit.byId("setvaluetest");
170 var nj = findMenuItem(combo, "New Jersey (NJ)");
171 dojo.window.scrollIntoView(nj);
172
173 doh.robot.mouseMoveAt(function(){ return nj }, 500, 0);
174 doh.robot.mouseClick({left:true}, 500);
175
176 doh.robot.sequence(d.getTestCallback(function(){
177 doh.is(isComboBox ? "New Jersey" : "NJ", dijit.byId("setvaluetest").get("value"),
178 "selected New Jersey from drop down");
179 var count = dijit.byId("setvaluetest").labelFuncCounts['NJ'];
180 doh.is(2, count, "# custom labelFunc calls");
181 }), 1000, 500);
182
183 return d;
184 }
185 },
186
187 {
188 timeout:6000,
189 name:"blur value",
190 runTest:function(){
191 var d = new doh.Deferred();
192
193 combo = dijit.byId("setvaluetest");
194 // focus combo
195 doh.robot.mouseMoveAt(combo.focusNode, 500, 0);
196 doh.robot.mouseClick({left:true}, 500);
197 // blur
198 doh.robot.mouseMoveAt('sv1_4', 500, 0);
199 doh.robot.mouseClick({left:true}, 500);
200
201 doh.robot.sequence(d.getTestCallback(function(){
202 doh.is(isComboBox ? "New Jersey" : "NJ", dijit.byId("setvaluetest").get("value"),
203 "New Jersey still set after blur");
204 var count = dijit.byId("setvaluetest").labelFuncCounts['NJ'];
205 doh.is(2, count, "# custom labelFunc calls unchanged after blur");
206 }), 1000, 500);
207
208 return d;
209 }
210 }
211 ]);
212
213
214 // For back-compat with 1.0 need to report click events, even clicks on the button
215 // (which by default is stopped in _HasDropDown)
216 // Remove for 2.0.
217 doh.register("onClick", [
218 {
219 timeout: 5000,
220 name: "click on button",
221 runTest: function(){
222 var d = new doh.Deferred();
223
224 combo = dijit.byId("setvaluetest");
225 handle = dojo.global.dojo.connect(combo, "onClick", d.getTestCallback(function(){
226 // If we hit here it's OK, if no click event then fail with timeout
227 console.log("hit onClick callback");
228 }));
229
230 dojo.window.scrollIntoView(combo.domNode);
231
232 doh.robot.mouseMoveAt(combo._buttonNode, 1000, 0);
233 doh.robot.mouseClick({left:true}, 500);
234
235 return d;
236 },
237 tearDown: function(){
238 dojo.disconnect(handle);
239 combo.closeDropDown();
240 }
241 },
242 {
243 timeout: 5000,
244 name: "click on input",
245 runTest: function(){
246 var d = new doh.Deferred();
247
248 combo = dijit.byId("setvaluetest");
249 handle = dojo.global.dojo.connect(combo, "onClick", d.getTestCallback(function(){
250 // If we hit here it's OK, if no click event then fail with timeout
251 console.log("hit onClick callback");
252 }));
253
254 dojo.window.scrollIntoView(combo.domNode);
255
256 doh.robot.mouseMoveAt(combo.focusNode, 1000, 0);
257 doh.robot.mouseClick({left:true}, 500);
258
259 return d;
260 },
261 tearDown: function(){
262 dojo.disconnect(handle);
263 combo.closeDropDown();
264 }
265 }
266 ]);
267
268 // Test clicking more choices / previous choices buttons doesn't affect value in <input> area
269 doh.register("auto-complete", [
270 {
271 timeout:10000,
272 name:"open drop down",
273 setUp: function(){
274 combo = dijit.byId("datatest");
275 pageSize = combo.get('pageSize');
276 combo.set('pageSize', 1);
277 combo.set('displayedValue', null, false);
278 },
279 runTest: function(){
280 var d = new doh.Deferred();
281 handle = dojo.connect(combo, "openDropDown", function(){
282 setTimeout(d.getTestCallback(function(){
283 var list = combo.dropDown.domNode;
284 doh.t(list && isVisible(list), "drop down is visible");
285
286 // Clicking "more choices" shouldn't change value in ComboBox
287 doh.is('Alabama', combo.focusNode.value, "focus value");
288 if(!isComboBox){
289 doh.t(combo.isValid(true), "FilteringSelect should be valid");
290 }
291 }), 0);
292 });
293
294 doh.robot.mouseMoveAt(combo.focusNode, 500, 0);
295 doh.robot.mouseClick({left:true}, 500);
296
297 doh.robot.typeKeys("a", 1500); // will open dropdown
298
299 return d;
300 },
301 tearDown: function(){
302 dojo.disconnect(handle);
303 }
304 },
305 {
306 timeout:10000,
307 name:"click more choices",
308 runTest: function(){
309 var d = new doh.Deferred();
310 handle = dojo.connect(combo, "openDropDown", function(){
311 setTimeout(d.getTestCallback(function(){
312 var list = combo.dropDown.domNode;
313 doh.t(list && isVisible(list), "drop down is visible");
314 doh.is(findMenuItem(combo, "Alaska"), combo.dropDown.getHighlightedOption(), "Alaska is highlighted");
315
316 doh.t(combo.focused, "widget is focused");
317 }), 0);
318 });
319
320 doh.robot.mouseMoveAt(combo.dropDown.nextButton, 1000, 0); // move to More choices
321 doh.robot.mouseClick({left:true}, 1000); // will display new drop down
322
323 return d;
324 },
325 tearDown: function(){
326 dojo.disconnect(handle);
327 combo.set('pageSize', pageSize);
328 combo.closeDropDown();
329 }
330 }
331 ]);
332
333 // disabled tests+standard tests
334 doh.register("disabled", [
335 {
336 timeout:6000,
337 name: "focus by mouse",
338 runTest:function(){
339 var d = new doh.Deferred();
340 combo = dijit.byId("combo3");
341
342 doh.robot.mouseMoveAt(combo.focusNode, 500, 0);
343 doh.robot.mouseClick({left:true}, 500);
344
345 doh.robot.sequence(d.getTestCallback(function(){
346 if(!dojo.isWebKit){ // webkit bug, see #11064 - TODO: verify this is fixed now
347 doh.isNot(combo, dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode), "click doesn't focus disabled combo");
348 }
349 }), 1000, 500);
350
351 return d;
352 }
353 },
354 {
355 timeout:6000,
356 name:"dropdown button",
357 runTest:function(){
358 var d = new doh.Deferred();
359 combo = dijit.byId("combo3");
360
361 // Press Arrow Button
362 doh.robot.mouseMoveAt(combo._buttonNode, 500, 0);
363 doh.robot.mouseClick({left:true}, 500);
364
365 // Assert that nothing happened
366 doh.robot.sequence(d.getTestCallback(function(){
367 doh.f(combo.dropDown, "User was able to open the menu on a disabled ComboBox!");
368
369 // Testcase for #8923, uncomment when that bug is fixed
370 //doh.isNot(combo, dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode), "button-click doesn't focus disabled combo");
371 }), 1000, 500);
372 return d;
373 }
374 }
375 ]);
376
377 doh.register("#9898", [
378 {
379 timeout: 9000,
380 name: "firefox mouse problem",
381 combo: "labelFunc",
382 handle: null,
383 setUp: function(){
384 combo = dijit.byId(this.combo);
385 },
386 runTest: function(){ // very hard to hit due to timing
387 var d = new doh.Deferred();
388 dojo.byId("native").scrollIntoView(false); // force to bottom of screen
389 // jump through hoops to increase the odds of hitting the problem
390 handle = combo.connect(combo, 'loadDropDown', // when drop down is about to be displayed, set up 1 time event handlers
391 function(){
392 var popup = dijit.byId("labelFunc_popup"); // combobox results
393 var old = dojo.global.dojo._setMarginBox; // menu is about to be shrunk to fit the viewport, so stop this
394 dojo.global.dojo._setMarginBox = dojo.hitch(dojo.global,
395 function(){
396 dojo.global.dojo._setMarginBox = old; // restore original _setMarginBox
397 });
398 var old2 = popup._focusOptionNode;
399 popup._focusOptionNode = // LI option is about to be highlighted, so stop that as well
400 function(node){
401 popup._focusOptionNode = old2; // restore original _focusOptionNode
402 };
403 doh.robot.mouseRelease({left:true}, 0); // invoke popup._onMouseUp
404 doh.robot.sequence(d.getTestCallback(function(){
405 doh.t(isVisible(popup.domNode), "list is visible");
406 }), 1000, 500);
407 }
408 );
409 doh.robot.mouseMoveAt(combo._buttonNode, 1000, 0);
410 doh.robot.mousePress({left:true}, 500); // mousedown on the arrow image
411
412 return d;
413 },
414 tearDown: function(){
415 combo.disconnect(handle);
416 combo.closeDropDown();
417 }
418 }
419 ]);
420
421 doh.register("#10431", [
422 {
423 timeout: 9000,
424 name: "untouched blank value and required",
425 combo: "japanese",
426 setUp: function(){
427 combo = dijit.byId(this.combo);
428 },
429 runTest: function(){
430 doh.is("", combo.get("value"), "value");
431 doh.is("", combo.get('displayedValue'), "displayedValue");
432 doh.f(combo.isValid(), "isValid");
433 doh.is("Incomplete", combo.state, "state");
434 },
435 tearDown: function(){
436 combo.closeDropDown();
437 }
438 },
439 {
440 timeout: 9000,
441 name: "blurred blank value and required",
442 combo: "japanese",
443 setUp: function(){
444 combo = dijit.byId(this.combo);
445 },
446 runTest: function(){
447 var d = new doh.Deferred();
448 doh.robot.mouseMoveAt(combo.focusNode, 500, 0);
449 doh.robot.mouseClick({left:true}, 500);
450 doh.robot.keyPress(dojo.keys.TAB, 1000);
451
452 doh.robot.sequence(d.getTestCallback(dojo.hitch(this, function(){
453 doh.is("", combo.get("value"), "value");
454 doh.is("", combo.get('displayedValue'), "displayedValue");
455 doh.f(combo.isValid(), "isValid");
456 doh.is("Error", combo.state, "state");
457 })), 1000, 500);
458 return d;
459 },
460 tearDown: function(){
461 combo.closeDropDown();
462 }
463 }
464 ]);
465
466 doh.run();
467 });
468 </script>
469 </head>
470 </html>