Debian Codegraph @

dijit/tests/form/robot/TimeTextBox.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 TimeTextBox 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.stamp");
18 dojo.require("dijit.tests.helpers"); // functions to help test
19
20 dojo.ready(function(){
21 doh.robot.initRobot('../test_TimeTextBox.html');
22
23 var w;
24 doh.register("keyboard", [
25 {
26 name: "select",
27 timeout: 10000,
28 runTest: function(){
29 var d = new doh.Deferred();
30
31 w = dijit.byId('q1');
32 dojo.global.formValue = null;
33
34 // focus field... drop down shouldn't open yet
35 w.focus();
36 doh.robot.sequence(d.getTestErrback(function(){
37 var popup = dijit.byId('q1_popup');
38 doh.t(!popup || isHidden(popup), "popup hidden");
39 }), 500);
40
41 // open drop down
42 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
43 doh.robot.sequence(d.getTestErrback(function(){
44 var popup = dijit.byId('q1_popup');
45 doh.t(popup && isVisible(popup), "popup visible");
46 }), 500);
47
48 // advance from 5:45PM to 6PM
49 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
50 doh.robot.sequence(d.getTestErrback(function(){
51 var popup = dijit.byId('q1_popup');
52 doh.t(popup && isVisible(popup), "popup still visible");
53
54 // for screenreader (and to be like ComboBox), navigated value should be in <input>
55 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
56 doh.is("T18:00:00", val, "6PM was selected");
57
58 doh.is(null, dojo.global.formValue, "no form submit");
59 }), 500);
60
61 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
62
63 doh.robot.sequence(d.getTestErrback(function(){
64 var popup = dijit.byId('q1_popup');
65 doh.t(!popup || isHidden(popup), "popup hidden again");
66
67 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
68 doh.is("T18:00:00", val, "6PM was selected");
69
70 doh.is(null, dojo.global.formValue, "no form submit");
71 }), 500);
72
73 // ENTER key while drop down is closed should submit the form
74 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
75 doh.robot.sequence(d.getTestCallback(function(){
76 doh.isNot(null, dojo.global.formValue, "form was submitted");
77 }), 500);
78
79 return d;
80 },
81 tearDown: function(){
82 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
83 w.closeDropDown();
84 }
85 },
86 {
87 name: "select original value",
88 timeout: 6000,
89 runTest: function(){
90 var d = new doh.Deferred();
91
92 w = dijit.byId('q1');
93 dojo.global.formValue = null;
94
95 // focus field... drop down shouldn't open yet
96 w.focus();
97 doh.robot.sequence(d.getTestErrback(function(){
98 var popup = dijit.byId('q1_popup');
99 doh.t(!popup || isHidden(popup), "popup hidden");
100 }), 500);
101
102 // open drop down
103 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
104 doh.robot.sequence(d.getTestErrback(function(){
105 var popup = dijit.byId('q1_popup');
106 doh.t(popup && isVisible(popup), "popup visible");
107 }), 500);
108
109 // select the initial value
110 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
111 doh.robot.sequence(d.getTestErrback(function(){
112 var popup = dijit.byId('q1_popup');
113 doh.t(!popup || isHidden(popup), "popup hidden again");
114
115 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
116 doh.is("T18:00:00", val, "6PM was selected (again)");
117
118 doh.is(null, dojo.global.formValue, "no form submit");
119 }), 500);
120
121 // ENTER key while drop down is closed should submit the form
122 doh.robot.keyPress(dojo.keys.ENTER, 500, {});
123 doh.robot.sequence(d.getTestCallback(function(){
124 doh.isNot(null, dojo.global.formValue, "form was submitted");
125 }), 500);
126
127 return d;
128 },
129 tearDown: function(){
130 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
131 w.closeDropDown();
132 }
133 },
134 {
135 name: "cancel",
136 timeout: 6000,
137 runTest: function(){
138 var d = new doh.Deferred();
139
140 w = dijit.byId('q1');
141 dojo.global.formValue = null;
142
143 // focus field... drop down shouldn't open yet
144 w.focus();
145 doh.robot.sequence(d.getTestErrback(function(){
146 var popup = dijit.byId('q1_popup');
147 doh.t(!popup || isHidden(popup), "popup hidden");
148 }), 500);
149
150 // open drop down
151 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
152 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 100, {}); // needed to prevent FF8 bug: reset on ESC
153 doh.robot.sequence(d.getTestErrback(function(){
154 var popup = dijit.byId('q1_popup');
155 doh.t(popup && isVisible(popup), "popup visible");
156 }), 500);
157
158 // close drop down
159 doh.robot.keyPress(dojo.keys.ESCAPE, 500, {});
160
161 doh.robot.sequence(d.getTestCallback(function(){
162 var popup = dijit.byId('q1_popup');
163 doh.t(!popup || isHidden(popup), "popup hidden again");
164
165 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
166 doh.is("T18:00:00", val, "same value as before");
167 }), 500);
168 return d;
169 },
170 tearDown: function(){
171 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
172 w.closeDropDown();
173 }
174 },
175 {
176 name: "partial input",
177 timeout: 10000,
178 setUp: function(){
179 // clear the field
180 w = dijit.byId('q2');
181 w.set('value', null, false);
182 },
183 runTest: function(){
184 var d = new doh.Deferred();
185
186 // focus field... drop down shouldn't open yet
187 w.focus();
188 doh.robot.sequence(d.getTestErrback(function(){
189 var popup = dijit.byId('q2_popup');
190 doh.t(!popup || isHidden(popup), "popup hidden");
191 }), 1000);
192
193 // do partial input
194 doh.robot.typeKeys('12', 500, 400);
195
196 doh.robot.sequence(d.getTestErrback(function(){
197 // partial input shouldn't be flagged as an error, because probably
198 // the user just hasn't finished typing yet
199 doh.f(w.isValid(), 'fully invalid');
200 doh.t(w._isValidSubset(), 'partially valid');
201 doh.isNot("Error", w.state, 'no error shown');
202
203 // typing caused drop down to open
204 var popup = dijit.byId('q2_popup');
205 doh.t(popup && isVisible(popup), "popup visible");
206
207 // drop down list should be filtered to times starting with 12:,
208 // and they should appear in chronological order
209 var children = dojo.query(".dijitTimePickerItem", popup.domNode);
210 doh.is(8, children.length, "# of items in drop down");
211 doh.is("12:00 AM", innerText(children[0]));
212 doh.is("12:15 AM", innerText(children[1]));
213 doh.is("12:30 AM", innerText(children[2]));
214 doh.is("12:45 AM", innerText(children[3]));
215 doh.is("12:00 PM", innerText(children[4]));
216 doh.is("12:15 PM", innerText(children[5]));
217 doh.is("12:30 PM", innerText(children[6]));
218 doh.is("12:45 PM", innerText(children[7]));
219 }), 1000);
220
221 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
222 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
223
224 doh.robot.sequence(d.getTestErrback(function(){
225 // dropdown list should still be filtered
226 var popup = dijit.byId('q2_popup');
227 var children = dojo.query(".dijitTimePickerItem", popup.domNode);
228 doh.is(8, children.length, "# of items in drop down after down arrow keys");
229
230 // for screenreader (and to be like ComboBox), navigated value should be in <input>
231 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
232 doh.is("T00:15:00", val, "12:15 was selected");
233
234 // Setup handler to fire when TAB keypress below fires
235 onFocus(d.getTestCallback(function(){
236 var popup = dijit.byId('q2_popup');
237 doh.t(!popup || isHidden(popup), "popup hidden again");
238
239 doh.is("q3", dojo.global.dijit.focus.curNode.id, "tab moved to next input widget");
240 }));
241 }), 1000);
242
243 // tab away to close drop down
244 doh.robot.keyPress(dojo.keys.TAB, 500, {});
245
246 return d;
247 },
248 tearDown: function(){
249 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
250 w.closeDropDown();
251 }
252 },
253 {
254 name: "invalid input",
255 timeout: 10000,
256 setUp: function(){
257 // clear the field
258 w = dijit.byId('q2');
259 w.set('value', null, false);
260 },
261 runTest: function(){
262 var d = new doh.Deferred();
263
264 // focus field... drop down shouldn't open yet
265 w.focus();
266
267 // do partial input
268 doh.robot.typeKeys('12a', 500, 600);
269
270 doh.robot.sequence(d.getTestErrback(function(){
271 // partial input shouldn't be flagged as an error, because probably
272 // the user just hasn't finished typing yet
273 doh.f(w.isValid(), 'fully invalid');
274 doh.f(w._isValidSubset(), 'subset invalid');
275 doh.is("Error", w.state, 'error shown');
276
277 // typing caused drop down to open
278 var popup = dijit.byId('q2_popup');
279 doh.t(popup && isVisible(popup), "popup visible");
280
281 // illegal pattern, so all entries are in the drop down
282 var children = dojo.query(".dijitTimePickerItem", popup.domNode);
283 doh.is(96, children.length, "# of items in drop down");
284 }), 1000);
285
286 // tab away to close drop down
287 doh.robot.keyPress(dojo.keys.TAB, 500, {});
288
289 doh.robot.sequence(d.getTestCallback(function(){
290 doh.f(w._opened, "drop down closed");
291 }), 500);
292
293 return d;
294 },
295 tearDown: function(){
296 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
297 w.closeDropDown();
298 }
299 },
300 {
301 name: "corrected invalid input",
302 timeout: 10000,
303 setUp: function(){
304 // clear the field
305 w = dijit.byId('q2');
306 w.set('value', null, false);
307 },
308 runTest: function(){
309 var d = new doh.Deferred();
310
311 // focus field... drop down shouldn't open yet
312 w.focus();
313
314 // do partial input
315 doh.robot.typeKeys('12a', 500, 600);
316 doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
317
318 doh.robot.sequence(d.getTestErrback(function(){
319 // partial input shouldn't be flagged as an error, because probably
320 // the user just hasn't finished typing yet
321 doh.f(w.isValid(), 'fully invalid');
322 doh.t(w._isValidSubset(), 'subset valid');
323 doh.is("Error", w.state, 'error shown');
324
325 // typing caused drop down to open
326 var popup = dijit.byId('q2_popup');
327 doh.t(popup && isVisible(popup), "popup visible");
328
329 // drop down list should be filtered to times starting with 12:,
330 // and they should appear in chronological order
331 var children = dojo.query(".dijitTimePickerItem", popup.domNode);
332 doh.is(8, children.length, "# of items in drop down");
333 }), 1000);
334
335 // tab away to close drop down
336 doh.robot.keyPress(dojo.keys.TAB, 500, {});
337
338 doh.robot.sequence(d.getTestCallback(function(){
339 doh.f(w._opened, "drop down closed");
340 }), 500);
341
342 return d;
343 },
344 tearDown: function(){
345 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
346 w.closeDropDown();
347 console.log("closed drop down for " + w.id)
348 }
349 }
350 ]);
351
352 var handler, q5;
353 doh.register("mouse", [
354 {
355 name: "select",
356 timeout: 6000,
357 runTest: function(){
358 var d = new doh.Deferred(),
359 popup,
360 toClick;
361 w = dijit.byId('q1');
362
363 handler = w.connect(w, 'openDropDown', d.getTestErrback(function(){
364 console.log("drop down opened");
365 w.disconnect(handler);
366 popup = dijit.byId('q1_popup');
367 var wasVisible = popup && isVisible(popup);
368 toClick = dojo.query(".dijitTimePickerItemInner:contains(6:45)", popup.domNode);
369
370 handler = w.connect(w, 'closeDropDown', d.getTestCallback(function(){
371 console.log("drop down closed");
372 doh.t(wasVisible, "popup visible");
373 doh.is(2, toClick.length, "found 6:45am and 6:45pm in drop down");
374 popup = dijit.byId('q1_popup');
375 doh.t(!popup || isHidden(popup), "popup hidden");
376 var val = dojo.date.stamp.toISOString(w.get('value'), {selector: "time"});
377 doh.is("T18:45:00", val, "should be 6:45PM");
378 }));
379
380 // click 6:45pm, thus selecting it and closing drop down
381 doh.robot.mouseMoveAt(function(){return toClick[1]; }, 500, 1);
382 doh.robot.mouseClick({left:true}, 500);
383 }));
384
385 // click down arrow, opening drop down
386 doh.robot.mouseMoveAt(w._buttonNode, 500, 1);
387 doh.robot.mouseClick({left:true}, 500);
388
389 return d;
390 },
391 tearDown: function(){
392 w.disconnect(handler);
393 w.closeDropDown();
394 }
395 }
396 ]);
397
398 var q20;
399 doh.register("disabled", [
400 {
401 name: "disable",
402 timeout: 6000,
403 runTest: function(){
404 var d = new doh.Deferred();
405 q20 = dijit.byId('q20');
406
407 q20.set('disabled',true);
408 // click down arrow, but disabled so won't open drop down
409 doh.robot.mouseMoveAt(q20._buttonNode, 500, 1);
410 doh.robot.mouseClick({left:true}, 500);
411 doh.robot.typeKeys('1', 500, 200);
412
413 doh.robot.sequence(d.getTestCallback(function(){
414 var popup = dijit.byId('q20_popup');
415 doh.t(!popup || isHidden(popup), "popup hidden");
416 var val = dojo.date.stamp.toISOString(q20.get('value'), {selector: "time"});
417 doh.is("T17:45:00", val, "should be 5:45PM");
418 }), 1000);
419 return d;
420 },
421 tearDown: function(){
422 q20.set('disabled',false);
423 q20.closeDropDown();
424 }
425 },
426 {
427 name: "readOnly",
428 timeout: 6000,
429 runTest: function(){
430 var d = new doh.Deferred();
431 q20 = dijit.byId('q20');
432
433 q20.set('readOnly',true);
434 // click down arrow, but readonly so won't open drop down
435 doh.robot.mouseMoveAt(q20._buttonNode, 500, 1);
436 doh.robot.mouseClick({left:true}, 500);
437 doh.robot.typeKeys('1', 500, 200);
438
439 doh.robot.sequence(d.getTestCallback(function(){
440 var popup = dijit.byId('q20_popup');
441 doh.t(!popup || isHidden(popup), "popup hidden");
442 var val = dojo.date.stamp.toISOString(q20.get('value'), {selector: "time"});
443 doh.is("T17:45:00", val, "should be 5:45PM");
444 }), 1000);
445 return d;
446 },
447 tearDown: function(){
448 q20.set('readOnly',false);
449 q20.closeDropDown();
450 }
451 }
452 ]);
453
454 var q21;
455 doh.register("Regression tests for 18201", [
456 {
457 name: "set Date value",
458 timeout: 1000,
459 runTest: function(){
460 var q21 = dijit.byId("q21"),
461 testDate = new Date();
462
463 q21.set('value', testDate);
464 var value = q21.get('value');
465 doh.assertTrue(value != null, "Unable to set Date value");
466 }
467 },
468 {
469 name: "compare Date value",
470 timeout: 1000,
471 runTest: function(){
472 var q21 = dijit.byId("q21"),
473 testDate = new Date();
474
475 q21.set('value', testDate);
476 var widgetDate = q21.get('value');
477 doh.assertEqual(0, q21.compare(testDate, widgetDate), "Invalid date comparison")
478 }
479 }
480 ]);
481
482 doh.register("limited drop down range", {
483 name: "9 to 5",
484 timeout: 10000,
485 runTest: function(){
486 var d = new doh.Deferred();
487
488 w = dijit.byId('q22');
489
490 // open drop down
491 w.focus();
492 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
493 doh.robot.sequence(d.getTestCallback(function(){
494 var popup = dijit.byId('q22_popup');
495 doh.t(isVisible(popup), "popup visible");
496 doh.is(9, popup.containerNode.children.length, "# of entries in drop down")
497 }), 500);
498
499 return d;
500 },
501 tearDown: function(){
502 // Even if test failed, make sure drop down is closed so it doesn't interfere w/next test
503 w.closeDropDown();
504 }
505 });
506
507 doh.run();
508 });
509 </script>
510 </head>
511 </html>