]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.Editor", function() {\r |
2 | \r | |
3 | var editor, field, target;\r | |
4 | \r | |
5 | function makeEditor(cfg) {\r | |
6 | editor = new Ext.Editor(cfg);\r | |
7 | field = editor.field;\r | |
8 | }\r | |
9 | \r | |
10 | function makeTarget(cfg) {\r | |
11 | target = Ext.getBody().createChild(Ext.apply({\r | |
12 | tag: 'span',\r | |
13 | html: 'Sample Text'\r | |
14 | }, cfg));\r | |
15 | }\r | |
16 | \r | |
17 | afterEach(function() {\r | |
18 | Ext.destroy(editor, target);\r | |
19 | target = field = editor = null;\r | |
20 | });\r | |
21 | \r | |
22 | function startEditWithTarget(value) {\r | |
23 | makeTarget();\r | |
24 | if (arguments.length) {\r | |
25 | editor.startEdit(target, value);\r | |
26 | } else {\r | |
27 | editor.startEdit(target);\r | |
28 | }\r | |
29 | }\r | |
30 | \r | |
31 | function fireKeyOnField(key) {\r | |
32 | jasmine.fireKeyEvent(field.inputEl, 'keydown', key);\r | |
33 | }\r | |
34 | \r | |
35 | describe("field creation", function() {\r | |
36 | it("should create a text field by default", function() {\r | |
37 | makeEditor();\r | |
38 | expect(field.$className).toBe('Ext.form.field.Text');\r | |
39 | });\r | |
40 | \r | |
41 | it("should accept a string xtype", function() {\r | |
42 | makeEditor({\r | |
43 | field: 'datefield'\r | |
44 | });\r | |
45 | expect(field.$className).toBe('Ext.form.field.Date');\r | |
46 | });\r | |
47 | \r | |
48 | it("should accept a config without xtype and default to a text field", function() {\r | |
49 | makeEditor({\r | |
50 | field: {\r | |
51 | maxLength: 10\r | |
52 | }\r | |
53 | });\r | |
54 | expect(field.$className).toBe('Ext.form.field.Text');\r | |
55 | expect(field.maxLength).toBe(10);\r | |
56 | });\r | |
57 | \r | |
58 | it("should accept an object config including xtype", function() {\r | |
59 | makeEditor({\r | |
60 | field: {\r | |
61 | xtype: 'numberfield',\r | |
62 | maxValue: 20\r | |
63 | }\r | |
64 | });\r | |
65 | expect(field.$className).toBe('Ext.form.field.Number');\r | |
66 | expect(field.maxValue).toBe(20);\r | |
67 | });\r | |
68 | });\r | |
69 | \r | |
70 | describe("getValue/setValue", function() {\r | |
71 | it("should get the value from the underlying field", function() {\r | |
72 | makeEditor();\r | |
73 | startEditWithTarget();\r | |
74 | editor.field.setValue('asdf');\r | |
75 | expect(editor.getValue()).toBe('asdf');\r | |
76 | });\r | |
77 | \r | |
78 | it("should set the value on the underlying field", function() {\r | |
79 | makeEditor();\r | |
80 | startEditWithTarget();\r | |
81 | editor.setValue('foo');\r | |
82 | expect(editor.getValue()).toBe('foo');\r | |
83 | });\r | |
84 | });\r | |
85 | \r | |
86 | describe("startEdit", function() {\r | |
87 | describe("basic functionality", function() {\r | |
88 | it("should show the editor", function() {\r | |
89 | makeEditor();\r | |
90 | startEditWithTarget();\r | |
91 | expect(editor.isVisible()).toBe(true);\r | |
92 | });\r | |
93 | \r | |
94 | it("should set the editing property to true", function() {\r | |
95 | makeEditor();\r | |
96 | startEditWithTarget();\r | |
97 | expect(editor.editing).toBe(true);\r | |
98 | });\r | |
99 | \r | |
100 | // Only Webkit focusing is reliable in the test runner\r | |
101 | (Ext.isWebKit ? it : xit)("should focus the field", function() {\r | |
102 | makeEditor();\r | |
103 | startEditWithTarget();\r | |
104 | waitsFor(function() {\r | |
105 | return field.hasFocus;\r | |
106 | }, "Field never focused");\r | |
107 | runs(function() {\r | |
108 | expect(field.hasFocus).toBe(true);\r | |
109 | });\r | |
110 | });\r | |
111 | \r | |
112 | it("should complete an existing edit when starting", function() {\r | |
113 | makeEditor({\r | |
114 | updateEl: true\r | |
115 | });\r | |
116 | startEditWithTarget();\r | |
117 | editor.setValue('Foo');\r | |
118 | editor.startEdit(target);\r | |
119 | expect(target.getHtml()).toBe('Foo');\r | |
120 | });\r | |
121 | });\r | |
122 | \r | |
123 | describe("positioning", function() {\r | |
124 | it("should align to c-c as the default", function() {\r | |
125 | makeEditor();\r | |
126 | startEditWithTarget();\r | |
127 | expect(editor.getXY()).toEqual([0, 0]);\r | |
128 | });\r | |
129 | \r | |
130 | it("should use another alignment", function() {\r | |
131 | // Top left of the field aligns to the bottom right of the target\r | |
132 | makeEditor({\r | |
133 | alignment: 'tl-br'\r | |
134 | });\r | |
135 | startEditWithTarget();\r | |
136 | var size = target.getSize();\r | |
137 | expect(editor.getXY()).toEqual([size.width, size.height]);\r | |
138 | });\r | |
139 | \r | |
140 | it("should use offsets", function() {\r | |
141 | makeEditor({\r | |
142 | alignment: 'tl-tl',\r | |
143 | offsets: [20, 30]\r | |
144 | });\r | |
145 | startEditWithTarget();\r | |
146 | expect(editor.getXY()).toEqual([20, 30]);\r | |
147 | });\r | |
148 | \r | |
149 | it("should use a combination of alignment & offsets", function() {\r | |
150 | // Top left of the field aligns to the bottom right of the target\r | |
151 | makeEditor({\r | |
152 | alignment: 'tl-br',\r | |
153 | offsets: [20, 30]\r | |
154 | });\r | |
155 | startEditWithTarget();\r | |
156 | var size = target.getSize();\r | |
157 | expect(editor.getXY()).toEqual([size.width + 20, size.height + 30]);\r | |
158 | });\r | |
159 | });\r | |
160 | \r | |
161 | describe("boundEl", function() {\r | |
162 | it("should accept an Ext.dom.Element", function() {\r | |
163 | makeEditor();\r | |
164 | makeTarget();\r | |
165 | editor.startEdit(target);\r | |
166 | expect(field.getValue()).toBe('Sample Text');\r | |
167 | });\r | |
168 | \r | |
169 | it("should accept an HtmlElement", function() {\r | |
170 | makeEditor();\r | |
171 | makeTarget();\r | |
172 | editor.startEdit(target.dom);\r | |
173 | expect(field.getValue()).toBe('Sample Text');\r | |
174 | });\r | |
175 | \r | |
176 | it("should accept an id", function() {\r | |
177 | makeEditor();\r | |
178 | makeTarget();\r | |
179 | editor.startEdit(target.id);\r | |
180 | expect(field.getValue()).toBe('Sample Text');\r | |
181 | });\r | |
182 | });\r | |
183 | \r | |
184 | describe("value", function() {\r | |
185 | it("should take the value from the element by default", function() {\r | |
186 | makeEditor();\r | |
187 | startEditWithTarget();\r | |
188 | expect(field.getValue()).toBe('Sample Text');\r | |
189 | });\r | |
190 | \r | |
191 | it("should use the passed value", function() {\r | |
192 | makeEditor();\r | |
193 | startEditWithTarget('Foo');\r | |
194 | expect(field.getValue()).toBe('Foo');\r | |
195 | });\r | |
196 | \r | |
197 | it("should retain the type of the passed value", function() {\r | |
198 | var d = new Date();\r | |
199 | makeEditor({\r | |
200 | field: 'datefield'\r | |
201 | });\r | |
202 | spyOn(field, 'setValue');\r | |
203 | startEditWithTarget(d);\r | |
204 | expect(field.setValue).toHaveBeenCalledWith(d);\r | |
205 | });\r | |
206 | });\r | |
207 | \r | |
208 | describe("the field", function() {\r | |
209 | it("should not fire the change event", function() {\r | |
210 | makeEditor();\r | |
211 | var spy = jasmine.createSpy();\r | |
212 | field.on('change', spy);\r | |
213 | startEditWithTarget();\r | |
214 | expect(spy).not.toHaveBeenCalled();\r | |
215 | });\r | |
216 | \r | |
217 | it("should not be dirty", function() {\r | |
218 | makeEditor();\r | |
219 | startEditWithTarget();\r | |
220 | expect(field.isDirty()).toBe(false);\r | |
221 | });\r | |
222 | });\r | |
223 | \r | |
224 | describe("hideEl", function() {\r | |
225 | it("should hide the el with hideEl: true", function() {\r | |
226 | makeEditor({\r | |
227 | hideEl: true\r | |
228 | });\r | |
229 | startEditWithTarget();\r | |
230 | expect(target.isVisible()).toBe(false);\r | |
231 | });\r | |
232 | \r | |
233 | it("should not hide the el with hideEl: false", function() {\r | |
234 | makeEditor({\r | |
235 | hideEl: false\r | |
236 | });\r | |
237 | startEditWithTarget();\r | |
238 | expect(target.isVisible()).toBe(true);\r | |
239 | });\r | |
240 | });\r | |
241 | \r | |
242 | describe("events", function() {\r | |
243 | var spy;\r | |
244 | \r | |
245 | beforeEach(function() {\r | |
246 | spy = jasmine.createSpy();\r | |
247 | });\r | |
248 | \r | |
249 | afterEach(function() {\r | |
250 | spy = null;\r | |
251 | });\r | |
252 | \r | |
253 | it("should fire beforestartedit and pass the editor, boundEl & value", function() {\r | |
254 | makeEditor();\r | |
255 | editor.on('beforestartedit', spy);\r | |
256 | startEditWithTarget();\r | |
257 | expect(spy).toHaveBeenCalled();\r | |
258 | var args = spy.mostRecentCall.args;\r | |
259 | expect(args[0]).toBe(editor);\r | |
260 | expect(args[1]).toBe(target);\r | |
261 | expect(args[2]).toBe('Sample Text');\r | |
262 | });\r | |
263 | \r | |
264 | it("should fire startedit and pass the editor, boundEl & value", function() {\r | |
265 | makeEditor();\r | |
266 | editor.on('startedit', spy);\r | |
267 | startEditWithTarget();\r | |
268 | expect(spy).toHaveBeenCalled();\r | |
269 | var args = spy.mostRecentCall.args;\r | |
270 | expect(args[0]).toBe(editor);\r | |
271 | expect(args[1]).toBe(target);\r | |
272 | expect(args[2]).toBe('Sample Text');\r | |
273 | });\r | |
274 | \r | |
275 | it("should not show or set to editing if it returns false", function() {\r | |
276 | var editSpy = jasmine.createSpy();\r | |
277 | makeEditor();\r | |
278 | makeTarget();\r | |
279 | editor.on('beforestartedit', spy.andReturn(false));\r | |
280 | editor.on('startedit', editSpy);\r | |
281 | editor.startEdit(target);\r | |
282 | expect(editor.isVisible()).toBe(false);\r | |
283 | expect(editor.editing).toBe(false);\r | |
284 | expect(editSpy).not.toHaveBeenCalled();\r | |
285 | });\r | |
286 | });\r | |
287 | });\r | |
288 | \r | |
289 | describe("completeEdit", function() {\r | |
290 | it("should not cause an exception if not editing", function() {\r | |
291 | makeEditor();\r | |
292 | expect(function() {\r | |
293 | editor.completeEdit();\r | |
294 | }).not.toThrow();\r | |
295 | });\r | |
296 | \r | |
297 | it("should hide the editor and set editing to false", function() {\r | |
298 | makeEditor();\r | |
299 | startEditWithTarget();\r | |
300 | editor.completeEdit();\r | |
301 | expect(editor.isVisible()).toBe(false);\r | |
302 | expect(editor.editing).toBe(false);\r | |
303 | })\r | |
304 | \r | |
305 | describe("validity", function() {\r | |
306 | describe("with revertInvalid: false", function() {\r | |
307 | it("should not complete the edit if the field is not valid", function() {\r | |
308 | makeEditor({\r | |
309 | revertInvalid: false,\r | |
310 | field: {\r | |
311 | allowBlank: false\r | |
312 | }\r | |
313 | });\r | |
314 | startEditWithTarget('');\r | |
315 | editor.completeEdit();\r | |
316 | expect(editor.editing).toBe(true);\r | |
317 | expect(editor.isVisible()).toBe(true);\r | |
318 | expect(editor.getValue()).toBe('');\r | |
319 | });\r | |
320 | });\r | |
321 | \r | |
322 | describe("with revertInvalid: true", function() {\r | |
323 | it("should cancel the edit if the field is not valid", function() {\r | |
324 | makeEditor({\r | |
325 | revertInvalid: true,\r | |
326 | field: {\r | |
327 | allowBlank: false\r | |
328 | }\r | |
329 | });\r | |
330 | startEditWithTarget();\r | |
331 | field.setValue('');\r | |
332 | editor.completeEdit();\r | |
333 | expect(editor.getValue()).toBe('Sample Text');\r | |
334 | expect(editor.editing).toBe(false);\r | |
335 | expect(editor.isVisible()).toBe(false);\r | |
336 | });\r | |
337 | });\r | |
338 | });\r | |
339 | \r | |
340 | describe("hideEl", function() {\r | |
341 | it("should not show the boundEl if complete is vetoed with revertInvalid: false", function() {\r | |
342 | makeEditor({\r | |
343 | revertInvalid: false,\r | |
344 | field: {\r | |
345 | allowBlank: false\r | |
346 | }\r | |
347 | });\r | |
348 | startEditWithTarget('');\r | |
349 | editor.completeEdit();\r | |
350 | expect(target.isVisible()).toBe(false);\r | |
351 | });\r | |
352 | \r | |
353 | it("should show the boundEl if complete is vetoed with revertInvalid: true", function() {\r | |
354 | makeEditor({\r | |
355 | revertInvalid: true,\r | |
356 | field: {\r | |
357 | allowBlank: false\r | |
358 | }\r | |
359 | });\r | |
360 | startEditWithTarget('');\r | |
361 | editor.completeEdit();\r | |
362 | expect(target.isVisible()).toBe(true); \r | |
363 | });\r | |
364 | \r | |
365 | it("should show the boundEl if complete is successful", function() {\r | |
366 | makeEditor({\r | |
367 | revertInvalid: true,\r | |
368 | field: {\r | |
369 | allowBlank: false\r | |
370 | }\r | |
371 | });\r | |
372 | startEditWithTarget('Foo');\r | |
373 | editor.completeEdit();\r | |
374 | expect(target.isVisible()).toBe(true); \r | |
375 | });\r | |
376 | });\r | |
377 | \r | |
378 | describe("remainVisible", function() {\r | |
379 | it("should leave the editor visible with remainVisible", function() {\r | |
380 | makeEditor();\r | |
381 | startEditWithTarget();\r | |
382 | editor.completeEdit(true);\r | |
383 | expect(editor.isVisible()).toBe(true);\r | |
384 | expect(editor.editing).toBe(false);\r | |
385 | });\r | |
386 | \r | |
387 | it("should leave the editor visible with remainVisible when the edit is cancelled for being invalid", function() {\r | |
388 | makeEditor({\r | |
389 | revertInvalid: true,\r | |
390 | field: {\r | |
391 | allowBlank: true\r | |
392 | }\r | |
393 | });\r | |
394 | startEditWithTarget('');\r | |
395 | editor.completeEdit(true);\r | |
396 | expect(editor.isVisible()).toBe(true);\r | |
397 | expect(editor.editing).toBe(false);\r | |
398 | });\r | |
399 | });\r | |
400 | \r | |
401 | describe("updateEl", function() {\r | |
402 | it("should set the html if the boundEl with updateEl: true", function() {\r | |
403 | makeEditor({\r | |
404 | updateEl: true\r | |
405 | });\r | |
406 | startEditWithTarget('Foo');\r | |
407 | editor.completeEdit();\r | |
408 | expect(target.getHtml()).toBe('Foo');\r | |
409 | });\r | |
410 | \r | |
411 | it("should not set the html if the boundEl with updateEl: false", function() {\r | |
412 | makeEditor({\r | |
413 | updateEl: false\r | |
414 | });\r | |
415 | startEditWithTarget('Foo');\r | |
416 | editor.completeEdit();\r | |
417 | expect(target.getHtml()).toBe('Sample Text');\r | |
418 | });\r | |
419 | });\r | |
420 | \r | |
421 | // FF randomly errors out on focus test in the test runner\r | |
422 | (Ext.isGecko ? xdescribe : describe)("allowBlur", function() {\r | |
423 | it("should not complete on blur with allowBlur: false", function() {\r | |
424 | makeEditor({\r | |
425 | allowBlur: false\r | |
426 | });\r | |
427 | startEditWithTarget();\r | |
428 | spyOn(editor, 'completeEdit').andCallThrough();\r | |
429 | waitsFor(function() {\r | |
430 | return field.hasFocus;\r | |
431 | }, "Field never focused");\r | |
432 | runs(function() {\r | |
433 | // Programmatic blur fails on IEs. Focus then remove an input field\r | |
434 | Ext.getBody().createChild({tag: 'input', type: 'text'}).focus().remove();\r | |
435 | });\r | |
436 | waitsFor(function() {\r | |
437 | return !field.hasFocus;\r | |
438 | }, "Field never blurred");\r | |
439 | runs(function() {\r | |
440 | expect(editor.completeEdit).not.toHaveBeenCalled();\r | |
441 | });\r | |
442 | });\r | |
443 | \r | |
444 | it("should complete on blur with allowBlur: true", function() {\r | |
445 | makeEditor({\r | |
446 | allowBlur: true\r | |
447 | });\r | |
448 | startEditWithTarget();\r | |
449 | spyOn(editor, 'completeEdit').andCallThrough();\r | |
450 | waitsFor(function() {\r | |
451 | return field.hasFocus;\r | |
452 | }, "Field never focused");\r | |
453 | runs(function() {\r | |
454 | // Programmatic blur fails on IEs. Focus then remove an input field\r | |
455 | Ext.getBody().createChild({tag: 'input', type: 'text'}).focus().remove();\r | |
456 | });\r | |
457 | waitsFor(function() {\r | |
458 | return !field.hasFocus;\r | |
459 | }, "Field never blurred");\r | |
460 | runs(function() {\r | |
461 | expect(editor.completeEdit).toHaveBeenCalled();\r | |
462 | });\r | |
463 | });\r | |
464 | });\r | |
465 | \r | |
466 | // FF randomly errors out on focus test in the test runner\r | |
467 | (Ext.isGecko ? xdescribe : describe)("completeOnEnter", function() {\r | |
468 | it("should not complete on enter with completeOnEnter: false", function() {\r | |
469 | makeEditor({\r | |
470 | completeOnEnter: false\r | |
471 | });\r | |
472 | editor.specialKeyDelay = 0;\r | |
473 | startEditWithTarget();\r | |
474 | spyOn(editor, 'completeEdit').andCallThrough();\r | |
475 | waitsFor(function() {\r | |
476 | return field.hasFocus;\r | |
477 | }, "Field never focused");\r | |
478 | runs(function() {\r | |
479 | fireKeyOnField(Ext.event.Event.ENTER);\r | |
480 | expect(editor.completeEdit).not.toHaveBeenCalled();\r | |
481 | });\r | |
482 | });\r | |
483 | \r | |
484 | it("should complete on enter with completeOnEnter: true", function() {\r | |
485 | makeEditor({\r | |
486 | completeOnEnter: true\r | |
487 | });\r | |
488 | editor.specialKeyDelay = 0;\r | |
489 | startEditWithTarget();\r | |
490 | spyOn(editor, 'completeEdit').andCallThrough();\r | |
491 | waitsFor(function() {\r | |
492 | return field.hasFocus;\r | |
493 | }, "Field never focused");\r | |
494 | runs(function() {\r | |
495 | fireKeyOnField(Ext.event.Event.ENTER);\r | |
496 | expect(editor.completeEdit).toHaveBeenCalled();\r | |
497 | });\r | |
498 | });\r | |
499 | });\r | |
500 | \r | |
501 | describe("events", function() {\r | |
502 | var spy;\r | |
503 | \r | |
504 | beforeEach(function() {\r | |
505 | spy = jasmine.createSpy();\r | |
506 | });\r | |
507 | \r | |
508 | afterEach(function() {\r | |
509 | spy = null;\r | |
510 | });\r | |
511 | \r | |
512 | it("should fire beforecomplete & pass the editor, value & start value", function() {\r | |
513 | makeEditor();\r | |
514 | editor.on('beforecomplete', spy);\r | |
515 | startEditWithTarget();\r | |
516 | field.setValue('ASDF');\r | |
517 | editor.completeEdit();\r | |
518 | expect(spy).toHaveBeenCalled();\r | |
519 | var args = spy.mostRecentCall.args;\r | |
520 | expect(args[0]).toBe(editor);\r | |
521 | expect(args[1]).toBe('ASDF');\r | |
522 | expect(args[2]).toBe('Sample Text');\r | |
523 | });\r | |
524 | \r | |
525 | it("should fire the complete event & pass the editor, value & start value", function() {\r | |
526 | makeEditor();\r | |
527 | editor.on('complete', spy);\r | |
528 | startEditWithTarget();\r | |
529 | field.setValue('ASDF');\r | |
530 | editor.completeEdit();\r | |
531 | expect(spy).toHaveBeenCalled();\r | |
532 | var args = spy.mostRecentCall.args;\r | |
533 | expect(args[0]).toBe(editor);\r | |
534 | expect(args[1]).toBe('ASDF');\r | |
535 | expect(args[2]).toBe('Sample Text');\r | |
536 | });\r | |
537 | \r | |
538 | it("should not fire beforecomplete/complete if not editing", function() {\r | |
539 | makeEditor();\r | |
540 | editor.on('beforecomplete', spy);\r | |
541 | editor.on('complete', spy);\r | |
542 | editor.completeEdit();\r | |
543 | expect(spy).not.toHaveBeenCalled();\r | |
544 | });\r | |
545 | \r | |
546 | describe("vetoing beforecomplete", function() {\r | |
547 | it("should not fire complete", function() {\r | |
548 | var completeSpy = jasmine.createSpy();\r | |
549 | makeEditor();\r | |
550 | editor.on('beforecomplete', spy.andReturn(false));\r | |
551 | editor.on('complete', completeSpy);\r | |
552 | startEditWithTarget('Value');\r | |
553 | editor.completeEdit();\r | |
554 | expect(completeSpy).not.toHaveBeenCalled();\r | |
555 | });\r | |
556 | \r | |
557 | it("should not update the boundEl", function() {\r | |
558 | makeEditor();\r | |
559 | editor.on('beforecomplete', spy.andReturn(false));\r | |
560 | startEditWithTarget('Value');\r | |
561 | editor.completeEdit();\r | |
562 | expect(target.getHtml()).toBe('Sample Text');\r | |
563 | });\r | |
564 | });\r | |
565 | \r | |
566 | describe("invalid values", function() {\r | |
567 | it("should not fire beforecomplete/complete if the value is invalid with revertInvalid: false", function() {\r | |
568 | makeEditor({\r | |
569 | revertInvalid: false,\r | |
570 | field: {\r | |
571 | allowBlank: false\r | |
572 | }\r | |
573 | });\r | |
574 | editor.on('beforecomplete', spy);\r | |
575 | editor.on('complete', spy);\r | |
576 | startEditWithTarget('');\r | |
577 | editor.completeEdit();\r | |
578 | expect(spy).not.toHaveBeenCalled();\r | |
579 | });\r | |
580 | \r | |
581 | it("should not fire beforecomplete/complete if the value is invalid with revertInvalid: true", function() {\r | |
582 | makeEditor({\r | |
583 | revertInvalid: true,\r | |
584 | field: {\r | |
585 | allowBlank: false\r | |
586 | }\r | |
587 | });\r | |
588 | editor.on('beforecomplete', spy);\r | |
589 | editor.on('complete', spy);\r | |
590 | startEditWithTarget('');\r | |
591 | editor.completeEdit();\r | |
592 | expect(spy).not.toHaveBeenCalled();\r | |
593 | });\r | |
594 | });\r | |
595 | \r | |
596 | describe("ignoreNoChange", function() {\r | |
597 | it("should not fire beforecomplete/complete if the value did not change with ignoreNoChange: true", function() {\r | |
598 | makeEditor({\r | |
599 | ignoreNoChange: true\r | |
600 | });\r | |
601 | editor.on('beforecomplete', spy);\r | |
602 | editor.on('complete', spy);\r | |
603 | startEditWithTarget();\r | |
604 | editor.completeEdit();\r | |
605 | expect(spy).not.toHaveBeenCalled();\r | |
606 | });\r | |
607 | \r | |
608 | it("should fire beforecomplete/complete if the value did not change with ignoreNoChange: true", function() {\r | |
609 | var completeSpy = jasmine.createSpy();\r | |
610 | makeEditor({\r | |
611 | ignoreNoChange: false\r | |
612 | });\r | |
613 | editor.on('beforecomplete', spy);\r | |
614 | editor.on('complete', completeSpy);\r | |
615 | startEditWithTarget();\r | |
616 | editor.completeEdit();\r | |
617 | expect(spy).toHaveBeenCalled();\r | |
618 | expect(completeSpy).toHaveBeenCalled();\r | |
619 | });\r | |
620 | });\r | |
621 | });\r | |
622 | });\r | |
623 | \r | |
624 | describe("cancelEdit", function() {\r | |
625 | it("should not cause an error when not editing", function() {\r | |
626 | makeEditor();\r | |
627 | expect(function() {\r | |
628 | editor.cancelEdit();\r | |
629 | }).not.toThrow();\r | |
630 | });\r | |
631 | \r | |
632 | it("should hide the editor & set editing to false", function() {\r | |
633 | makeEditor();\r | |
634 | startEditWithTarget();\r | |
635 | editor.cancelEdit();\r | |
636 | expect(editor.isVisible()).toBe(false);\r | |
637 | expect(editor.editing).toBe(false);\r | |
638 | });\r | |
639 | \r | |
640 | it("should set the original value on the field and not fire the change event", function() {\r | |
641 | makeEditor();\r | |
642 | startEditWithTarget();\r | |
643 | editor.setValue('Foo');\r | |
644 | var spy = jasmine.createSpy();\r | |
645 | field.on('change', spy);\r | |
646 | editor.cancelEdit();\r | |
647 | expect(editor.getValue()).toBe('Sample Text');\r | |
648 | expect(spy).not.toHaveBeenCalled();\r | |
649 | });\r | |
650 | \r | |
651 | describe("with updateEl", function() {\r | |
652 | it("should not update the boundEl", function() {\r | |
653 | makeEditor();\r | |
654 | startEditWithTarget();\r | |
655 | editor.setValue('Foo')\r | |
656 | editor.cancelEdit();\r | |
657 | expect(target.getHtml()).toBe('Sample Text');\r | |
658 | });\r | |
659 | });\r | |
660 | \r | |
661 | // FF randomly errors out on focus test in the test runner\r | |
662 | (Ext.isGecko ? xdescribe : describe)("cancelOnEsc", function() {\r | |
663 | it("should not cancel on esc key with cancelOnEsc: false", function() {\r | |
664 | makeEditor({\r | |
665 | cancelOnEsc: false\r | |
666 | });\r | |
667 | editor.specialKeyDelay = 0;\r | |
668 | startEditWithTarget();\r | |
669 | spyOn(editor, 'cancelEdit').andCallThrough();\r | |
670 | waitsFor(function() {\r | |
671 | return field.hasFocus;\r | |
672 | }, "Field never focused");\r | |
673 | runs(function() {\r | |
674 | fireKeyOnField(Ext.event.Event.ESC);\r | |
675 | expect(editor.cancelEdit).not.toHaveBeenCalled();\r | |
676 | });\r | |
677 | });\r | |
678 | \r | |
679 | it("should cancel on esc key with cancelOnEsc: true", function() {\r | |
680 | makeEditor({\r | |
681 | cancelOnEsc: true\r | |
682 | });\r | |
683 | editor.specialKeyDelay = 0;\r | |
684 | startEditWithTarget();\r | |
685 | spyOn(editor, 'cancelEdit').andCallThrough();\r | |
686 | waitsFor(function() {\r | |
687 | return field.hasFocus;\r | |
688 | }, "Field never focused");\r | |
689 | runs(function() {\r | |
690 | fireKeyOnField(Ext.event.Event.ESC);\r | |
691 | expect(editor.cancelEdit).toHaveBeenCalled();\r | |
692 | });\r | |
693 | });\r | |
694 | });\r | |
695 | \r | |
696 | describe("hideEl", function() {\r | |
697 | it("should show the boundEl", function() {\r | |
698 | makeEditor();\r | |
699 | startEditWithTarget();\r | |
700 | editor.cancelEdit();\r | |
701 | expect(target.isVisible()).toBe(true);\r | |
702 | });\r | |
703 | });\r | |
704 | \r | |
705 | describe("remainVisible", function() {\r | |
706 | it("should leave the editor visible with remainVisible", function() {\r | |
707 | makeEditor();\r | |
708 | startEditWithTarget();\r | |
709 | editor.cancelEdit(true);\r | |
710 | expect(editor.isVisible()).toBe(true);\r | |
711 | });\r | |
712 | });\r | |
713 | \r | |
714 | describe("events", function() {\r | |
715 | it("should fire canceledit and pass the editor, current value & start value", function() {\r | |
716 | var spy = jasmine.createSpy();\r | |
717 | makeEditor();\r | |
718 | startEditWithTarget();\r | |
719 | editor.setValue('foo');\r | |
720 | editor.on('canceledit', spy);\r | |
721 | editor.cancelEdit();\r | |
722 | expect(spy).toHaveBeenCalled();\r | |
723 | var args = spy.mostRecentCall.args;\r | |
724 | expect(args[0]).toBe(editor);\r | |
725 | expect(args[1]).toBe('foo');\r | |
726 | expect(args[2]).toBe('Sample Text');\r | |
727 | });\r | |
728 | \r | |
729 | it("should not fire canceledit if not editing", function() {\r | |
730 | var spy = jasmine.createSpy();\r | |
731 | makeEditor();\r | |
732 | editor.on('canceledit', spy);\r | |
733 | editor.cancelEdit();\r | |
734 | expect(spy).not.toHaveBeenCalled();\r | |
735 | });\r | |
736 | });\r | |
737 | });\r | |
738 | }); |