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: "onChange set value", |
---|
169 | timeout: 2000, |
---|
170 | runTest: function(){ |
---|
171 | var d = new doh.Deferred(); |
---|
172 | var inlineBox = registry.byId("editable"); |
---|
173 | inlineBox.set("value", "programmatic value"); |
---|
174 | robot.sequence(d.getTestCallback(function(){ |
---|
175 | doh.is("programmatic value", inlineBox._onChangeValue, "programmatic set causes onChange"); |
---|
176 | }), 500); |
---|
177 | return d; |
---|
178 | } |
---|
179 | }, |
---|
180 | { |
---|
181 | name: "onChange programmatic creation", |
---|
182 | timeout: 2000, |
---|
183 | runTest: function(){ |
---|
184 | var d = new doh.Deferred(); |
---|
185 | var inlineBox = registry.byId("programmatic"); |
---|
186 | inlineBox.edit(); |
---|
187 | inlineBox.wrapperWidget.editWidget.set('value', 'changed'); |
---|
188 | inlineBox.save(); |
---|
189 | robot.sequence(d.getTestCallback(function(){ |
---|
190 | doh.is("changed", inlineBox._onChangeValue, "editing causes onChange"); |
---|
191 | }), 500); |
---|
192 | return d; |
---|
193 | } |
---|
194 | }, |
---|
195 | { |
---|
196 | name: "Textarea test", |
---|
197 | timeout: 15000, |
---|
198 | runTest: function(){ |
---|
199 | var d = new doh.Deferred(); |
---|
200 | var inlineBox = registry.byId("textarea"); |
---|
201 | moveAndClick(inlineBox.domNode); |
---|
202 | robot.typeKeys("line 1", 1000, 1200); |
---|
203 | robot.keyPress(keys.ENTER, 500, {}); |
---|
204 | robot.typeKeys("line 2", 500, 1200); |
---|
205 | moveAndClick("predefined"); |
---|
206 | robot.sequence(d.getTestCallback(function(){ |
---|
207 | doh.is('line 1\\nline 2', inlineBox.get("value").replace(/\n/g, "\\n"), "textarea programmatic value was " + inlineBox.get("value").replace(/\n/g, "\\n")); |
---|
208 | doh.is('line 1<br>line 2', inlineBox.domNode.innerHTML.toLowerCase(), "textarea rendered value was " + inlineBox.domNode.innerHTML); |
---|
209 | }), 1000); |
---|
210 | return d; |
---|
211 | } |
---|
212 | } |
---|
213 | ]); |
---|
214 | |
---|
215 | // Testing that the initial display value of the InlineEditBox gets sent to the editor. |
---|
216 | // For example, in this markup: |
---|
217 | // <span dojoType="dijit.InlineEditBox" ...>01/05/2007</span> |
---|
218 | // When the editor is clicked the calendar should open to that date. |
---|
219 | array.forEach([ |
---|
220 | { widget: "CurrencyTextBox", id: "dollar", textValue: "$2,000", widgetValue: 2000 }, |
---|
221 | { widget: "NumberTextBox", id: "quantity", textValue: "3", widgetValue: 3 }, |
---|
222 | { widget: "ComboBox", id: "item", textValue: "refrigerators", widgetValue: "refrigerators" }, |
---|
223 | { widget: "DateTextBox", id: "purchase", textValue: "01/05/2007", widgetValue: datelocale.parse("01/05/2007", {datePattern: 'MM/dd/yyyy', selector:'date'}) }, |
---|
224 | { widget: "FilteringSelect", id: "state", textValue: "Pennsylvania", widgetValue: "PA" }, |
---|
225 | { widget: "Select", id: "country", textValue: "United States of America", widgetValue: "US" } |
---|
226 | ], function(test){ |
---|
227 | doh.register("preDefinedValue " + test.widget, { |
---|
228 | timeout: 8000, |
---|
229 | name: test.id, |
---|
230 | runTest: function(){ |
---|
231 | var d = new doh.Deferred(); |
---|
232 | var inlineBox = registry.byId(test.id); |
---|
233 | var handler = aspect.after(inlineBox, 'edit', function(){ |
---|
234 | handler.remove(); |
---|
235 | var editWidget = inlineBox.wrapperWidget.editWidget; |
---|
236 | handler = aspect.after(editWidget, '_onFocus', function(){ |
---|
237 | handler.remove(); |
---|
238 | robot.sequence(function(){ |
---|
239 | var |
---|
240 | textValue = test.textValue, |
---|
241 | value = inlineBox.get("value"), |
---|
242 | visible = helpers.isVisible(editWidget), |
---|
243 | expected = test.widgetValue, |
---|
244 | actual = editWidget.get("value"), |
---|
245 | showHandler = aspect.after(inlineBox, 'save', d.getTestCallback(function(){ |
---|
246 | cancelHandler.remove(); |
---|
247 | showHandler.remove(); |
---|
248 | doh.t(false, "Save was clicked"); |
---|
249 | }), true), |
---|
250 | cancelHandler = aspect.after(inlineBox, 'onCancel', function(){ |
---|
251 | cancelHandler.remove(); |
---|
252 | showHandler.remove(); |
---|
253 | robot.sequence(d.getTestCallback(function(){ |
---|
254 | doh.is(textValue, value, "inline text value"); |
---|
255 | doh.t(visible, "editor widget should be visible"); |
---|
256 | doh.is(typeof expected, typeof actual, "editor value typeof"); |
---|
257 | doh.is(expected.toString(), actual.toString(), "editor widget value"); |
---|
258 | doh.t(helpers.isHidden(inlineBox.wrapperWidget), "editor widget should be hidden"); |
---|
259 | }), 500); |
---|
260 | }, true), |
---|
261 | buttons = query(".dijitButton", inlineBox.domNode.parentNode); |
---|
262 | moveAndClick(buttons[buttons.length-2]); // Save should be disabled so nothing happens |
---|
263 | moveAndClick(buttons[buttons.length-1]); |
---|
264 | }, 1500); |
---|
265 | }, true); |
---|
266 | }, true); |
---|
267 | moveAndClick(inlineBox.domNode); |
---|
268 | return d; |
---|
269 | } |
---|
270 | }) |
---|
271 | }); |
---|
272 | |
---|
273 | doh.register("renderAsHtml", [ |
---|
274 | |
---|
275 | // "plain text" mode, < > & have no special meaning |
---|
276 | { |
---|
277 | name: "false", |
---|
278 | timeout: 10000, |
---|
279 | runTest: function(){ |
---|
280 | var d = new doh.Deferred(); |
---|
281 | |
---|
282 | // confirm initial displayed value |
---|
283 | var inlineBox = registry.byId("renderAsHtml_false"); |
---|
284 | doh.is("<B>not bold</B>&lt;input&gt;", lang.trim(inlineBox.domNode.innerHTML), |
---|
285 | "confirm initial value (with special chars) wasn't modified"); |
---|
286 | doh.is("<B>not bold</B><input>", inlineBox.get("value"), |
---|
287 | "confirm initial get('value')"); |
---|
288 | |
---|
289 | // launch editor, and make sure that special characters aren't mangled |
---|
290 | moveAndClick(inlineBox.domNode); |
---|
291 | robot.sequence(d.getTestErrback(function(){ |
---|
292 | var editor = inlineBox.wrapperWidget.editWidget; |
---|
293 | doh.is("<B>not bold</B><input>", editor.get("value"), "initial editor value"); |
---|
294 | }), 1000); |
---|
295 | |
---|
296 | // edit value and save |
---|
297 | robot.keyPress(keys.RIGHT_ARROW, 1000, {}); |
---|
298 | robot.typeKeys("end", 2000, 1000); |
---|
299 | robot.keyPress(keys.ENTER, 500, {}); |
---|
300 | |
---|
301 | // check that display value didn't mangle special characters |
---|
302 | robot.sequence(d.getTestCallback(function(){ |
---|
303 | doh.is("<B>not bold</B>&lt;input&gt;end", lang.trim(inlineBox.domNode.innerHTML), |
---|
304 | "displayed value after edit"); |
---|
305 | doh.is("<B>not bold</B><input>end", inlineBox.get("value"), |
---|
306 | "get('value') after edit"); |
---|
307 | }), 1000); |
---|
308 | |
---|
309 | return d; |
---|
310 | } |
---|
311 | }, |
---|
312 | |
---|
313 | // HTML mode, display mode has rich text, which is passed to editor |
---|
314 | { |
---|
315 | name: "true", |
---|
316 | timeout: 10000, |
---|
317 | runTest: function(){ |
---|
318 | var d = new doh.Deferred(); |
---|
319 | |
---|
320 | // confirm initial displayed value |
---|
321 | var inlineBox = registry.byId("renderAsHtml_true"); |
---|
322 | doh.is("<b>not bold</b><b>bold</b>&lt;input&gt;", |
---|
323 | lang.trim(inlineBox.domNode.innerHTML).toLowerCase(), |
---|
324 | "confirm initial value (with special chars) wasn't modified"); |
---|
325 | doh.is("<b>not bold</b><b>bold</b>&lt;input&gt;", |
---|
326 | inlineBox.get("value").toLowerCase(), |
---|
327 | "confirm initial get('value')"); |
---|
328 | |
---|
329 | // launch editor, and make sure that value was passed to editor as HTML |
---|
330 | moveAndClick(inlineBox.domNode); |
---|
331 | robot.sequence(d.getTestErrback(function(){ |
---|
332 | var editor = inlineBox.wrapperWidget.editWidget; |
---|
333 | doh.is("<b>not bold</b><b>bold</b>&lt;input&gt;", |
---|
334 | editor.get("value").toLowerCase(), |
---|
335 | "initial editor value"); |
---|
336 | }), 1000); |
---|
337 | |
---|
338 | // edit value and save |
---|
339 | robot.keyPress(keys.RIGHT_ARROW, 1000, {}); |
---|
340 | robot.typeKeys("end", 2000, 1000); |
---|
341 | robot.keyPress(keys.ENTER, 500, {}); |
---|
342 | |
---|
343 | // check that display value didn't mangle special characters |
---|
344 | robot.sequence(d.getTestCallback(function(){ |
---|
345 | doh.is("<b>not bold</b><b>bold</b>&lt;input&gt;end", |
---|
346 | lang.trim(inlineBox.domNode.innerHTML).toLowerCase(), |
---|
347 | "displayed value after edit"); |
---|
348 | doh.is("<b>not bold</b><b>bold</b>&lt;input&gt;end", |
---|
349 | inlineBox.get("value").toLowerCase(), |
---|
350 | "get('value') after edit"); |
---|
351 | }), 1000); |
---|
352 | |
---|
353 | return d; |
---|
354 | } |
---|
355 | } |
---|
356 | ]); |
---|
357 | |
---|
358 | doh.register("focus tests", [ |
---|
359 | { |
---|
360 | name: "RTE", |
---|
361 | timeout: 7000, |
---|
362 | runTest: function(){ |
---|
363 | var d = new doh.Deferred(); |
---|
364 | var inlineBox = registry.byId("inlineRTE"); |
---|
365 | var handler = aspect.after(inlineBox, 'edit', function(){ |
---|
366 | handler.remove(); |
---|
367 | handler = aspect.after(inlineBox, 'save', function(){ |
---|
368 | handler.remove(); |
---|
369 | setTimeout(d.getTestCallback(function(){ |
---|
370 | doh.t(helpers.isHidden(inlineBox.wrapperWidget), "editor widget should be visible"); |
---|
371 | doh.t(inlineBox.get("value").indexOf('!start!') >= 0, "value changed"); |
---|
372 | }), 1000); |
---|
373 | }); |
---|
374 | robot.typeKeys("!start!", 1, 1400); |
---|
375 | var buttons = query(".saveButton", inlineBox.domNode.parentNode); |
---|
376 | moveAndClick(buttons[buttons.length-1]); |
---|
377 | }); |
---|
378 | moveAndClick(inlineBox.domNode); |
---|
379 | return d; |
---|
380 | } |
---|
381 | } |
---|
382 | ]); |
---|
383 | |
---|
384 | doh.register("positioning", [ |
---|
385 | { |
---|
386 | name: "offscreen", |
---|
387 | timeout: 4000, |
---|
388 | runTest: function(){ |
---|
389 | var d = new doh.Deferred(); |
---|
390 | var inlineBox = registry.byId("areaEditable"); |
---|
391 | inlineBox.edit(); |
---|
392 | moveAndClick("disableAreaEditable"); |
---|
393 | robot.sequence(d.getTestCallback(function(){ |
---|
394 | doh.t(inlineBox.get("disabled"), "disabled"); |
---|
395 | inlineBox.set('disabled', false); |
---|
396 | inlineBox.cancel(); |
---|
397 | }), 1000); |
---|
398 | return d; |
---|
399 | } |
---|
400 | } |
---|
401 | ]); |
---|
402 | |
---|
403 | doh.run(); |
---|
404 | }); |
---|
405 | </script> |
---|
406 | </head> |
---|
407 | </html> |
---|