Debian Codegraph @

dijit/tests/robot/InlineEditBox.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>robot InlineEditBox Test</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"
13 data-dojo-config="isDebug: true"></script>
14
15 <script type="text/javascript">
16 require([
17 "doh/runner", "dojo/robotx",
18 "dojo/_base/array", "dojo/aspect", "dojo/date/locale", "dojo/keys", "dojo/_base/lang", "dojo/query",
19 "dijit/tests/helpers", "dojo/domReady!"
20 ], function(doh, robot, array, aspect, datelocale, keys, lang, query, helpers){
21 robot.initRobot('../test_InlineEditBox.html');
22
23 function moveAndClick(node){
24 robot.mouseMoveAt(node, 500, 1);
25 robot.mouseClick({left: true}, 500);
26 }
27
28 doh.register(function setup(){
29 // get pointer to registry in the iframe
30 registry = robot.window.require("dijit/registry");
31 });
32
33 doh.register("dijit.InlineEditBox autosave tests", [
34 {
35 name: "CurrencyTextBox invalid value: blur",
36 timeout: 10000,
37 runTest: function(){
38 var d = new doh.Deferred();
39 var inlineBox = registry.byId("dollar_as");
40 moveAndClick(inlineBox.domNode);
41 robot.typeKeys("dollar", 1000, 1200); // invalid
42 moveAndClick("predefined");
43 robot.sequence(d.getTestCallback(function(){
44 var currencyTextBox = inlineBox.wrapperWidget.editWidget;
45 doh.is('dollar', currencyTextBox.get("displayedValue"), "displayedValue");
46 doh.f(currencyTextBox.isValid(), "!isValid");
47 inlineBox.cancel(false);
48 doh.is('', inlineBox.get("value"), "value");
49 }), 1000);
50 return d;
51 }
52 },
53 {
54 name: "CurrencyTextBox invalid value: ENTER",
55 timeout: 10000,
56 runTest: function(){
57 var d = new doh.Deferred();
58 var inlineBox = registry.byId("dollar_as");
59 var displayedValue, isValid;
60 moveAndClick(inlineBox.domNode);
61 robot.typeKeys("dollar", 1000, 1200); // invalid
62 robot.keyPress(keys.ENTER, 500, {});
63 robot.sequence(function(){
64 var currencyTextBox = inlineBox.wrapperWidget.editWidget;
65 displayedValue = currencyTextBox.get("displayedValue");
66 isValid = currencyTextBox.isValid();
67 }, 1000);
68 robot.keyPress(keys.ESCAPE, 500, {});
69 robot.sequence(d.getTestCallback(function(){
70 doh.is('dollar', displayedValue, "displayedValue");
71 doh.f(isValid, "!isValid");
72 doh.is('', inlineBox.get("value"), "value");
73 }), 1000);
74 return d;
75 }
76 },
77 {
78 name: "CurrencyTextBox valid value: blur",
79 timeout: 10000,
80 runTest: function(){
81 var d = new doh.Deferred();
82 var inlineBox = registry.byId("dollar_as");
83 moveAndClick(inlineBox.domNode);
84 robot.typeKeys("123", 1000, 600);
85 moveAndClick("predefined");
86 robot.sequence(d.getTestCallback(function(){
87 doh.is("$123.00", inlineBox.get("value"), "value");
88 }), 1000);
89 return d;
90 }
91 },
92 {
93 name: "CurrencyTextBox valid value: ENTER",
94 timeout: 10000,
95 runTest: function(){
96 var d = new doh.Deferred();
97 var inlineBox = registry.byId("dollar_as");
98 moveAndClick(inlineBox.domNode);
99 robot.typeKeys("234", 1000, 600);
100 robot.keyPress(keys.ENTER, 500, {});
101 robot.sequence(d.getTestCallback(function(){
102 doh.is('$234.00', inlineBox.get("value"), "value");
103 }), 1000);
104 return d;
105 }
106 },
107 {
108 name: "CurrencyTextBox valid value: ESCAPE",
109 timeout: 10000,
110 runTest: function(){
111 var d = new doh.Deferred();
112 var inlineBox = registry.byId("dollar_as");
113 moveAndClick(inlineBox.domNode);
114 robot.typeKeys("345", 1000, 600);
115 robot.keyPress(keys.ESCAPE, 500, {});
116 robot.sequence(d.getTestCallback(function(){
117 doh.is("$234.00", inlineBox.get("value"), "value");
118 }), 1000);
119 return d;
120 }
121 },
122 {
123 name: "CurrencyTextBox valid value: TAB",
124 timeout: 10000,
125 runTest: function(){
126 var d = new doh.Deferred();
127 var inlineBox = registry.byId("dollar_as");
128 moveAndClick(inlineBox.domNode);
129 robot.typeKeys("456", 1000, 600);
130 robot.keyPress(keys.TAB, 500, {});
131 robot.sequence(d.getTestCallback(function(){
132 doh.is('$456.00', inlineBox.get("value"), "value");
133 }), 1000);
134 return d;
135 }
136 },
137 {
138 name: "Focus test",
139 timeout: 15000,
140 runTest: function(){
141 var d = new doh.Deferred();
142 var inlineBox = registry.byId("editable");
143 var initialOnChange = inlineBox._onChangeValue;
144 inlineBox.set("value", "");
145 inlineBox.edit();
146 robot.typeKeys("editable", 1000, 1600);
147 robot.keyPress(keys.TAB, 500, {});
148 robot.keyPress(keys.TAB, 1500, {}); // wait more than 1 second to TAB
149 robot.keyPress(keys.ENTER, 500, {});
150 robot.typeKeys("567", 500, 600);
151 robot.keyPress(keys.ENTER, 500, {});
152 robot.keyPress(keys.TAB, 500, {shift:true}); // do this fast
153 robot.keyPress(keys.TAB, 500, {shift:true}); // do this fast
154 robot.keyPress(keys.ENTER, 500, {}); // quickly back to editable
155 robot.keyPress(keys.RIGHT_ARROW, 500, {});
156 robot.typeKeys(" again", 1000, 1200);
157 robot.keyPress(keys.TAB, 500, {});
158 robot.sequence(d.getTestCallback(function(){
159 doh.is(undefined, initialOnChange, "no onChange value");
160 doh.is('$567.00', registry.byId("dollar_as").get("value"), "value");
161 doh.is('editable again', inlineBox.get("value"), "value");
162 doh.is('editable again', inlineBox._onChangeValue, "onChange value");
163 }), 1000);
164 return d;
165 }
166 },
167 {
168 name: "Textarea test",
169 timeout: 15000,
170 runTest: function(){
171 var d = new doh.Deferred();
172 var inlineBox = registry.byId("textarea");
173 moveAndClick(inlineBox.domNode);
174 robot.typeKeys("line 1", 1000, 1200);
175 robot.keyPress(keys.ENTER, 500, {});
176 robot.typeKeys("line 2", 500, 1200);
177 moveAndClick("predefined");
178 robot.sequence(d.getTestCallback(function(){
179 doh.is('line 1\\nline 2', inlineBox.get("value").replace(/\n/g, "\\n"), "textarea programmatic value was " + inlineBox.get("value").replace(/\n/g, "\\n"));
180 doh.is('line 1<br>line 2', inlineBox.domNode.innerHTML.toLowerCase(), "textarea rendered value was " + inlineBox.domNode.innerHTML);
181 }), 1000);
182 return d;
183 }
184 }
185 ]);
186
187 // Testing that the initial display value of the InlineEditBox gets sent to the editor.
188 // For example, in this markup:
189 // <span dojoType="dijit.InlineEditBox" ...>01/05/2007</span>
190 // When the editor is clicked the calendar should open to that date.
191 array.forEach([
192 { widget: "CurrencyTextBox", id: "dollar", textValue: "$2,000", widgetValue: 2000 },
193 { widget: "NumberTextBox", id: "quantity", textValue: "3", widgetValue: 3 },
194 { widget: "ComboBox", id: "item", textValue: "refrigerators", widgetValue: "refrigerators" },
195 { widget: "DateTextBox", id: "purchase", textValue: "01/05/2007", widgetValue: datelocale.parse("01/05/2007", {datePattern: 'MM/dd/yyyy', selector:'date'}) },
196 { widget: "FilteringSelect", id: "state", textValue: "Pennsylvania", widgetValue: "PA" },
197 { widget: "Select", id: "country", textValue: "United States of America", widgetValue: "US" }
198 ], function(test){
199 doh.register("preDefinedValue " + test.widget, {
200 timeout: 8000,
201 name: test.id,
202 runTest: function(){
203 var d = new doh.Deferred();
204 var inlineBox = registry.byId(test.id);
205 var handler = aspect.after(inlineBox, 'edit', function(){
206 handler.remove();
207 var editWidget = inlineBox.wrapperWidget.editWidget;
208 handler = aspect.after(editWidget, '_onFocus', function(){
209 handler.remove();
210 robot.sequence(function(){
211 var
212 textValue = test.textValue,
213 value = inlineBox.get("value"),
214 visible = helpers.isVisible(editWidget),
215 expected = test.widgetValue,
216 actual = editWidget.get("value"),
217 showHandler = aspect.after(inlineBox, 'save', d.getTestCallback(function(){
218 cancelHandler.remove();
219 showHandler.remove();
220 doh.t(false, "Save was clicked");
221 }), true),
222 cancelHandler = aspect.after(inlineBox, 'onCancel', function(){
223 cancelHandler.remove();
224 showHandler.remove();
225 robot.sequence(d.getTestCallback(function(){
226 doh.is(textValue, value, "inline text value");
227 doh.t(visible, "editor widget should be visible");
228 doh.is(typeof expected, typeof actual, "editor value typeof");
229 doh.is(expected.toString(), actual.toString(), "editor widget value");
230 doh.t(helpers.isHidden(inlineBox.wrapperWidget), "editor widget should be hidden");
231 }), 500);
232 }, true),
233 buttons = query(".dijitButton", inlineBox.domNode.parentNode);
234 moveAndClick(buttons[buttons.length-2]); // Save should be disabled so nothing happens
235 moveAndClick(buttons[buttons.length-1]);
236 }, 1500);
237 }, true);
238 }, true);
239 moveAndClick(inlineBox.domNode);
240 return d;
241 }
242 })
243 });
244
245 doh.register("renderAsHtml", [
246
247 // "plain text" mode, < > & have no special meaning
248 {
249 name: "false",
250 timeout: 10000,
251 runTest: function(){
252 var d = new doh.Deferred();
253
254 // confirm initial displayed value
255 var inlineBox = registry.byId("renderAsHtml_false");
256 doh.is("&lt;B&gt;not bold&lt;/B&gt;&amp;lt;input&amp;gt;", lang.trim(inlineBox.domNode.innerHTML),
257 "confirm initial value (with special chars) wasn't modified");
258 doh.is("<B>not bold</B>&lt;input&gt;", inlineBox.get("value"),
259 "confirm initial get('value')");
260
261 // launch editor, and make sure that special characters aren't mangled
262 moveAndClick(inlineBox.domNode);
263 robot.sequence(d.getTestErrback(function(){
264 var editor = inlineBox.wrapperWidget.editWidget;
265 doh.is("<B>not bold</B>&lt;input&gt;", editor.get("value"), "initial editor value");
266 }), 1000);
267
268 // edit value and save
269 robot.keyPress(keys.RIGHT_ARROW, 1000, {});
270 robot.typeKeys("end", 2000, 1000);
271 robot.keyPress(keys.ENTER, 500, {});
272
273 // check that display value didn't mangle special characters
274 robot.sequence(d.getTestCallback(function(){
275 doh.is("&lt;B&gt;not bold&lt;/B&gt;&amp;lt;input&amp;gt;end", lang.trim(inlineBox.domNode.innerHTML),
276 "displayed value after edit");
277 doh.is("<B>not bold</B>&lt;input&gt;end", inlineBox.get("value"),
278 "get('value') after edit");
279 }), 1000);
280
281 return d;
282 }
283 },
284
285 // HTML mode, display mode has rich text, which is passed to editor
286 {
287 name: "true",
288 timeout: 10000,
289 runTest: function(){
290 var d = new doh.Deferred();
291
292 // confirm initial displayed value
293 var inlineBox = registry.byId("renderAsHtml_true");
294 doh.is("&lt;b&gt;not bold&lt;/b&gt;<b>bold</b>&amp;lt;input&amp;gt;",
295 lang.trim(inlineBox.domNode.innerHTML).toLowerCase(),
296 "confirm initial value (with special chars) wasn't modified");
297 doh.is("&lt;b&gt;not bold&lt;/b&gt;<b>bold</b>&amp;lt;input&amp;gt;",
298 inlineBox.get("value").toLowerCase(),
299 "confirm initial get('value')");
300
301 // launch editor, and make sure that value was passed to editor as HTML
302 moveAndClick(inlineBox.domNode);
303 robot.sequence(d.getTestErrback(function(){
304 var editor = inlineBox.wrapperWidget.editWidget;
305 doh.is("&lt;b&gt;not bold&lt;/b&gt;<b>bold</b>&amp;lt;input&amp;gt;",
306 editor.get("value").toLowerCase(),
307 "initial editor value");
308 }), 1000);
309
310 // edit value and save
311 robot.keyPress(keys.RIGHT_ARROW, 1000, {});
312 robot.typeKeys("end", 2000, 1000);
313 robot.keyPress(keys.ENTER, 500, {});
314
315 // check that display value didn't mangle special characters
316 robot.sequence(d.getTestCallback(function(){
317 doh.is("&lt;b&gt;not bold&lt;/b&gt;<b>bold</b>&amp;lt;input&amp;gt;end",
318 lang.trim(inlineBox.domNode.innerHTML).toLowerCase(),
319 "displayed value after edit");
320 doh.is("&lt;b&gt;not bold&lt;/b&gt;<b>bold</b>&amp;lt;input&amp;gt;end",
321 inlineBox.get("value").toLowerCase(),
322 "get('value') after edit");
323 }), 1000);
324
325 return d;
326 }
327 }
328 ]);
329
330 doh.register("focus tests", [
331 {
332 name: "RTE",
333 timeout: 7000,
334 runTest: function(){
335 var d = new doh.Deferred();
336 var inlineBox = registry.byId("inlineRTE");
337 var handler = aspect.after(inlineBox, 'edit', function(){
338 handler.remove();
339 handler = aspect.after(inlineBox, 'save', function(){
340 handler.remove();
341 setTimeout(d.getTestCallback(function(){
342 doh.t(helpers.isHidden(inlineBox.wrapperWidget), "editor widget should be visible");
343 doh.t(inlineBox.get("value").indexOf('!start!') >= 0, "value changed");
344 }), 1000);
345 });
346 robot.typeKeys("!start!", 1, 1400);
347 var buttons = query(".saveButton", inlineBox.domNode.parentNode);
348 moveAndClick(buttons[buttons.length-1]);
349 });
350 moveAndClick(inlineBox.domNode);
351 return d;
352 }
353 }
354 ]);
355
356 doh.register("positioning", [
357 {
358 name: "offscreen",
359 timeout: 4000,
360 runTest: function(){
361 var d = new doh.Deferred();
362 var inlineBox = registry.byId("areaEditable");
363 inlineBox.edit();
364 moveAndClick("disableAreaEditable");
365 robot.sequence(d.getTestCallback(function(){
366 doh.t(inlineBox.get("disabled"), "disabled");
367 inlineBox.set('disabled', false);
368 inlineBox.cancel();
369 }), 1000);
370 return d;
371 }
372 }
373 ]);
374
375 doh.register("programmatic", [
376 {
377 name: "create",
378 timeout: 4000,
379 runTest: function(){
380 // Actually, it was already created by test_InlineEditBox
381 numWidgetsBeforeProgCreate = registry.length;
382 robot.window.programmaticCreate();
383 doh.t(!!robot.window.programmatic);
384 }
385 },
386 {
387 name: "set()",
388 timeout: 2000,
389 runTest: function(){
390 var d = new doh.Deferred();
391 var inlineBox = registry.byId("editable");
392 inlineBox.set("value", "programmatic value");
393 robot.sequence(d.getTestCallback(function(){
394 doh.is("programmatic value", inlineBox._onChangeValue, "programmatic set causes onChange");
395 }), 500);
396 return d;
397 }
398 },
399 {
400 name: "edit",
401 timeout: 2000,
402 runTest: function(){
403 var d = new doh.Deferred();
404 var inlineBox = robot.window.programmatic;
405 inlineBox.edit();
406 inlineBox.wrapperWidget.editWidget.set('value', 'changed');
407 inlineBox.save();
408 robot.sequence(d.getTestCallback(function(){
409 doh.is("changed", inlineBox._onChangeValue, "editing causes onChange");
410 }), 500);
411 return d;
412 }
413 },
414 {
415 name: "destroy",
416 timeout: 4000,
417 runTest: function(){
418 robot.window.programmatic.destroy();
419 var numWidgetsAfterDestroy = registry.length;
420 doh.is(numWidgetsBeforeProgCreate, numWidgetsAfterDestroy,
421 "no orphaned widgets");
422 }
423 }
424 ]);
425
426 doh.run();
427 });
428 </script>
429 </head>
430 </html>