]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("grid-rowedit", function() {\r |
2 | function createSuite(buffered) {\r | |
3 | describe(buffered ? "with buffered rendering" : "without buffered rendering", function() {\r | |
4 | var ENTER = 13,\r | |
5 | ESC = 27;\r | |
6 | \r | |
7 | var grid, view, store, plugin, colRef, GridEventModel = Ext.define(null, {\r | |
8 | extend: 'Ext.data.Model',\r | |
9 | fields: [\r | |
10 | 'field1',\r | |
11 | 'field2',\r | |
12 | 'field3',\r | |
13 | 'field4',\r | |
14 | 'field5',\r | |
15 | 'field6',\r | |
16 | 'field7',\r | |
17 | 'field8',\r | |
18 | 'field9',\r | |
19 | 'field10'\r | |
20 | ]\r | |
21 | });\r | |
22 | \r | |
23 | function triggerCellMouseEvent(type, rowIdx, cellIdx, button, x, y) {\r | |
24 | var target = findCell(rowIdx, cellIdx);\r | |
25 | \r | |
26 | jasmine.fireMouseEvent(target, type, x, y, button);\r | |
27 | }\r | |
28 | \r | |
29 | function triggerCellKeyEvent(type, rowIdx, cellIdx, key) {\r | |
30 | var target = findCell(rowIdx, cellIdx);\r | |
31 | jasmine.fireKeyEvent(target, type, key);\r | |
32 | }\r | |
33 | \r | |
34 | function triggerEditorKey(key) {\r | |
35 | var target = plugin.getEditor().items.first().inputEl.dom;\r | |
36 | jasmine.fireKeyEvent(target, 'keydown', key);\r | |
37 | jasmine.fireKeyEvent(target, 'keyup', key);\r | |
38 | jasmine.fireKeyEvent(target, 'keypress', key);\r | |
39 | }\r | |
40 | \r | |
41 | function getRec(index) {\r | |
42 | return store.getAt(index);\r | |
43 | }\r | |
44 | \r | |
45 | function findCell(rowIdx, cellIdx) {\r | |
46 | return grid.getView().getCellInclusive({\r | |
47 | row: rowIdx,\r | |
48 | column: cellIdx\r | |
49 | }, true);\r | |
50 | }\r | |
51 | \r | |
52 | function startEdit(rec) {\r | |
53 | if (!rec || !rec.isModel) {\r | |
54 | rec = store.getAt(rec || 0);\r | |
55 | }\r | |
56 | plugin.startEdit(rec);\r | |
57 | }\r | |
58 | \r | |
59 | // Prevent validity from running on a delay\r | |
60 | function clearFormDelay() {\r | |
61 | plugin.getEditor().getForm().taskDelay = 0;\r | |
62 | }\r | |
63 | \r | |
64 | // locked param as true means that columns 1 and 2 are locked\r | |
65 | function makeGrid(columns, pluginCfg, locked, gridCfg) {\r | |
66 | var data = [],\r | |
67 | defaultCols = [],\r | |
68 | hasCols,\r | |
69 | i,\r | |
70 | colConfig;\r | |
71 | \r | |
72 | if (!columns) {\r | |
73 | hasCols = true;\r | |
74 | colRef = []; \r | |
75 | for (i = 1; i <= 5; ++i) {\r | |
76 | colConfig = {\r | |
77 | text: 'F' + i,\r | |
78 | dataIndex: 'field' + i,\r | |
79 | field: {\r | |
80 | xtype: 'textfield',\r | |
81 | id: 'field' + i,\r | |
82 | allowBlank: i !== 1\r | |
83 | }\r | |
84 | };\r | |
85 | \r | |
86 | // Columns 1 and 2 are locked if the locked config is true\r | |
87 | if (locked && i < 3) {\r | |
88 | colConfig.locked = true;\r | |
89 | }\r | |
90 | defaultCols.push(new Ext.grid.column.Column(colConfig));\r | |
91 | colRef[i - 1] = defaultCols[i - 1];\r | |
92 | }\r | |
93 | }\r | |
94 | \r | |
95 | for (i = 1; i <= 10; ++i) {\r | |
96 | data.push({\r | |
97 | field1: i + '.' + 1,\r | |
98 | field2: i + '.' + 2,\r | |
99 | field3: i + '.' + 3,\r | |
100 | field4: i + '.' + 4,\r | |
101 | field5: i + '.' + 5,\r | |
102 | field6: i + '.' + 6,\r | |
103 | field7: i + '.' + 7,\r | |
104 | field8: i + '.' + 8,\r | |
105 | field9: i + '.' + 9,\r | |
106 | field10: i + '.' + 10\r | |
107 | });\r | |
108 | }\r | |
109 | \r | |
110 | store = new Ext.data.Store({\r | |
111 | model: GridEventModel,\r | |
112 | data: data\r | |
113 | });\r | |
114 | \r | |
115 | plugin = new Ext.grid.plugin.RowEditing(pluginCfg);\r | |
116 | \r | |
117 | grid = new Ext.grid.Panel(Ext.apply({\r | |
118 | columns: columns || defaultCols,\r | |
119 | store: store,\r | |
120 | selType: 'cellmodel',\r | |
121 | plugins: [plugin],\r | |
122 | width: 1000,\r | |
123 | height: 500,\r | |
124 | bufferedRenderer: buffered,\r | |
125 | viewConfig: {\r | |
126 | mouseOverOutBuffer: 0\r | |
127 | },\r | |
128 | renderTo: Ext.getBody()\r | |
129 | }, gridCfg));\r | |
130 | \r | |
131 | if (!hasCols) {\r | |
132 | colRef = grid.getColumnManager().getColumns();\r | |
133 | }\r | |
134 | view = grid.getView();\r | |
135 | }\r | |
136 | \r | |
137 | afterEach(function(){\r | |
138 | Ext.destroy(grid, store);\r | |
139 | plugin = grid = store = view = null;\r | |
140 | Ext.data.Model.schema.clear();\r | |
141 | });\r | |
142 | \r | |
143 | describe("resolveListenerScope", function() {\r | |
144 | it("should resolve the scope to the grid", function() {\r | |
145 | var fooScope = {\r | |
146 | someFn: function() {}\r | |
147 | };\r | |
148 | \r | |
149 | spyOn(fooScope, 'someFn');\r | |
150 | \r | |
151 | makeGrid(null, {\r | |
152 | listeners: {\r | |
153 | 'beforeedit': 'someFn'\r | |
154 | }\r | |
155 | });\r | |
156 | grid.resolveSatelliteListenerScope = function() {\r | |
157 | return fooScope;\r | |
158 | };\r | |
159 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
160 | expect(fooScope.someFn).toHaveBeenCalled();\r | |
161 | });\r | |
162 | });\r | |
163 | \r | |
164 | describe("Editing in a locked grid", function() {\r | |
165 | beforeEach(function() {\r | |
166 | makeGrid(null, null, true);\r | |
167 | });\r | |
168 | \r | |
169 | it('should move an editor from one side to another when a column is locked during editing', function() {\r | |
170 | var ed;\r | |
171 | \r | |
172 | triggerCellMouseEvent('dblclick', 0, 2);\r | |
173 | ed = colRef[2].getEditor();\r | |
174 | expect(plugin.editing).toBe(true);\r | |
175 | \r | |
176 | // The editor of the 3rd column (first normal column) should be active\r | |
177 | expect(Ext.Element.getActiveElement() === ed.inputEl.dom).toBe(true);\r | |
178 | \r | |
179 | // The editor should be in the right container\r | |
180 | expect(ed.up('container') === plugin.editor.items.items[1]).toBe(true);\r | |
181 | \r | |
182 | // Locking the first normal column should not throw error.\r | |
183 | grid.lock(colRef[2]);\r | |
184 | expect(plugin.editing).toBe(true);\r | |
185 | \r | |
186 | // The editor should now be in the left container\r | |
187 | expect(ed.up('container') === plugin.editor.items.items[0]).toBe(true);\r | |
188 | });\r | |
189 | });\r | |
190 | \r | |
191 | describe("basic editing", function() {\r | |
192 | // https://sencha.jira.com/browse/EXTJS-18773\r | |
193 | it('should scroll a record that is outside the rendered block into view and edit it', function() {\r | |
194 | makeGrid();\r | |
195 | var data = [],\r | |
196 | i;\r | |
197 | \r | |
198 | for (i = 11; i <= 1000; ++i) {\r | |
199 | data.push({\r | |
200 | field1: i + '.' + 1,\r | |
201 | field2: i + '.' + 2,\r | |
202 | field3: i + '.' + 3,\r | |
203 | field4: i + '.' + 4,\r | |
204 | field5: i + '.' + 5,\r | |
205 | field6: i + '.' + 6,\r | |
206 | field7: i + '.' + 7,\r | |
207 | field8: i + '.' + 8,\r | |
208 | field9: i + '.' + 9,\r | |
209 | field10: i + '.' + 10\r | |
210 | });\r | |
211 | }\r | |
212 | store.add(data);\r | |
213 | startEdit(900);\r | |
214 | expect(plugin.editing).toBe(true);\r | |
215 | expect(plugin.getEditor().isVisible()).toBe(true);\r | |
216 | });\r | |
217 | \r | |
218 | it("should trigger the edit on cell interaction", function(){\r | |
219 | makeGrid();\r | |
220 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
221 | expect(plugin.editing).toBe(true);\r | |
222 | expect(plugin.getEditor().isVisible()).toBe(true);\r | |
223 | });\r | |
224 | \r | |
225 | it("should focus the field for the clicked cell", function() {\r | |
226 | makeGrid();\r | |
227 | triggerCellMouseEvent('dblclick', 0, 3);\r | |
228 | expect(plugin.editing).toBe(true);\r | |
229 | expect(plugin.getEditor().isVisible()).toBe(true);\r | |
230 | var toFocus = plugin.getEditor().items.getAt(3);\r | |
231 | jasmine.waitForFocus(toFocus);\r | |
232 | jasmine.expectFocused(toFocus);\r | |
233 | });\r | |
234 | \r | |
235 | it("should be able to be trigger by record", function(){\r | |
236 | makeGrid();\r | |
237 | var rec = store.first();\r | |
238 | startEdit(rec);\r | |
239 | expect(plugin.editing).toBe(true);\r | |
240 | expect(plugin.getEditor().getRecord() === rec).toBe(true);\r | |
241 | });\r | |
242 | \r | |
243 | it("should trigger the first time when clicking a cell without a defined editor", function() {\r | |
244 | Ext.destroy(grid, store);\r | |
245 | Ext.data.Model.schema.clear();\r | |
246 | makeGrid([{\r | |
247 | dataIndex: 'field1',\r | |
248 | editor: 'textfield'\r | |
249 | }, {\r | |
250 | dataIndex: 'field2'\r | |
251 | }]);\r | |
252 | triggerCellMouseEvent('dblclick', 0, 1);\r | |
253 | expect(plugin.editing).toBe(true);\r | |
254 | expect(plugin.getEditor().isVisible()).toBe(true);\r | |
255 | });\r | |
256 | \r | |
257 | it("should focus the first visible column if not passed", function(){\r | |
258 | makeGrid();\r | |
259 | var rec = store.first();\r | |
260 | startEdit(rec);\r | |
261 | \r | |
262 | var toFocus = plugin.getEditor().items.getAt(0);\r | |
263 | jasmine.waitForFocus(toFocus);\r | |
264 | jasmine.expectFocused(toFocus);\r | |
265 | });\r | |
266 | \r | |
267 | it("should focus the first column that isn't a displayfield", function() {\r | |
268 | makeGrid([{\r | |
269 | dataIndex: 'field1',\r | |
270 | field: 'displayfield'\r | |
271 | }, {\r | |
272 | dataIndex: 'field2',\r | |
273 | field: 'displayfield'\r | |
274 | }, {\r | |
275 | dataIndex: 'field3',\r | |
276 | field: 'displayfield'\r | |
277 | }, {\r | |
278 | dataIndex: 'field4',\r | |
279 | field: 'textfield'\r | |
280 | }]);\r | |
281 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
282 | var toFocus = plugin.getEditor().items.getAt(3);\r | |
283 | jasmine.waitForFocus(toFocus);\r | |
284 | jasmine.expectFocused(toFocus);\r | |
285 | });\r | |
286 | \r | |
287 | it("should focus the passed column", function () {\r | |
288 | makeGrid();\r | |
289 | var rec = store.first();\r | |
290 | plugin.startEdit(rec, colRef[2]);\r | |
291 | expect(plugin.editing).toBe(true);\r | |
292 | expect(plugin.getEditor().getRecord() === rec).toBe(true);\r | |
293 | \r | |
294 | var toFocus = plugin.getEditor().items.getAt(2);\r | |
295 | jasmine.waitForFocus(toFocus);\r | |
296 | jasmine.expectFocused(toFocus);\r | |
297 | });\r | |
298 | \r | |
299 | it("should scroll horizontally to display the field being edited", function() {\r | |
300 | makeGrid(null,null,null,{\r | |
301 | width: 300\r | |
302 | });\r | |
303 | var rec = store.first(),\r | |
304 | x, offset=0;\r | |
305 | \r | |
306 | // IE 8 has a 2px offset when the editor is visible\r | |
307 | if(Ext.isIE8) {\r | |
308 | offset = 2;\r | |
309 | }\r | |
310 | \r | |
311 | // this will scroll the grid all the way to the right\r | |
312 | view.scrollBy(300,0);\r | |
313 | waitsFor(function() {\r | |
314 | return view.getScrollX() >= 200;\r | |
315 | });\r | |
316 | \r | |
317 | runs(function(){\r | |
318 | x = view.getScrollX();\r | |
319 | plugin.startEdit(rec,colRef[4]);\r | |
320 | \r | |
321 | // expects the grid not to scroll when editing the last field\r | |
322 | expect(view.getScrollX()).toBe(x-offset);\r | |
323 | plugin.cancelEdit();\r | |
324 | // expects the grid not to scroll when cancelling the edit\r | |
325 | expect(view.getScrollX()).toBe(x);\r | |
326 | plugin.startEdit(rec,colRef[0]);\r | |
327 | // expects the grid to scroll left when editing the first field\r | |
328 | expect(view.getScrollX()).toBe(offset);\r | |
329 | });\r | |
330 | });\r | |
331 | \r | |
332 | it("should not be dirty when the field has values", function() {\r | |
333 | makeGrid();\r | |
334 | startEdit(store.first());\r | |
335 | expect(plugin.getEditor().isDirty()).toBe(false);\r | |
336 | });\r | |
337 | });\r | |
338 | \r | |
339 | describe("scrolling while editing", function() {\r | |
340 | beforeEach(function() {\r | |
341 | var data = [],\r | |
342 | bufferPlugin;\r | |
343 | \r | |
344 | makeGrid([{\r | |
345 | dataIndex: 'field1',\r | |
346 | field: 'displayfield'\r | |
347 | }, {\r | |
348 | dataIndex: 'field2',\r | |
349 | field: 'displayfield'\r | |
350 | }, {\r | |
351 | dataIndex: 'field3',\r | |
352 | field: 'displayfield'\r | |
353 | }, {\r | |
354 | dataIndex: 'field4',\r | |
355 | field: 'textfield'\r | |
356 | }],{\r | |
357 | clicksToMoveEditor: 1,\r | |
358 | autoCancel: false \r | |
359 | },null,{\r | |
360 | trailingBufferZone: 10,\r | |
361 | leadingBufferZone: 10\r | |
362 | });\r | |
363 | \r | |
364 | \r | |
365 | for (var i = 11; i <= 100; ++i) {\r | |
366 | data.push({\r | |
367 | field1: i + '.' + 1,\r | |
368 | field2: i + '.' + 2,\r | |
369 | field3: i + '.' + 3,\r | |
370 | field4: i + '.' + 4,\r | |
371 | field5: i + '.' + 5,\r | |
372 | field6: i + '.' + 6,\r | |
373 | field7: i + '.' + 7,\r | |
374 | field8: i + '.' + 8,\r | |
375 | field9: i + '.' + 9,\r | |
376 | field10: i + '.' + 10\r | |
377 | });\r | |
378 | }\r | |
379 | \r | |
380 | store.insert(10,data);\r | |
381 | \r | |
382 | });\r | |
383 | \r | |
384 | it('it should keep the editor active if scrolling out of view', function() {\r | |
385 | startEdit();\r | |
386 | \r | |
387 | runs(function(){\r | |
388 | setTimeout(function(){\r | |
389 | // this will scroll the grid view down\r | |
390 | // to a point where rows get de-rendered\r | |
391 | // if the grid has a bufferedRenderer plugin\r | |
392 | view.scrollBy(0,700);\r | |
393 | },50);\r | |
394 | \r | |
395 | })\r | |
396 | \r | |
397 | waitsFor(function () {\r | |
398 | // Wait until a record begin edit is cached\r | |
399 | // or verified if it is not a grid with bufferedRenderer\r | |
400 | return plugin.editor._cachedNode || !grid.bufferedRenderer;\r | |
401 | }, 'scroll to the bottom', 10000);\r | |
402 | \r | |
403 | runs(function(){\r | |
404 | // if this is a grid with bufferedRenderer\r | |
405 | // the record editor should be hidden at Y = -400;\r | |
406 | if (grid.bufferedRenderer) {\r | |
407 | expect(plugin.editor.getLocalY()).not.toBe(0);\r | |
408 | }\r | |
409 | setTimeout(function(){\r | |
410 | // scrolls the grid back to the top\r | |
411 | view.scrollBy(0,-700);\r | |
412 | },1000);\r | |
413 | });\r | |
414 | \r | |
415 | waitsFor(function(){\r | |
416 | return view.getScrollY() === 0;\r | |
417 | },10000);\r | |
418 | \r | |
419 | runs(function(){\r | |
420 | // the cached record should have been erased\r | |
421 | // or it should never existed if this is not a grid with bufferedRenderer\r | |
422 | // the editor also should not be hidden anymore\r | |
423 | // and the editor editing status should still be true.\r | |
424 | expect(plugin.editor._editedNode).toBeFalsy();\r | |
425 | expect(plugin.editor.getLocalY()).toBe(0);\r | |
426 | expect(plugin.editing).toBe(true);\r | |
427 | });\r | |
428 | \r | |
429 | });\r | |
430 | });\r | |
431 | \r | |
432 | // https://sencha.jira.com/browse/EXTJSIV-11364\r | |
433 | describe("destroying a grid before editing starts", function() {\r | |
434 | beforeEach(function(){\r | |
435 | makeGrid([{\r | |
436 | name: 'F0',\r | |
437 | dataIndex: 'field0',\r | |
438 | field: {\r | |
439 | xtype: 'combobox',\r | |
440 | id: 'field0',\r | |
441 | initComponent: function() {\r | |
442 | // The column will be removed at this point, and column.up will return undefined.\r | |
443 | this.store = this.column.up('tablepanel').store.collect(this.column.dataIndex, false, true);\r | |
444 | Ext.form.field.ComboBox.prototype.initComponent.apply(this, arguments);\r | |
445 | }\r | |
446 | }\r | |
447 | }]);\r | |
448 | });\r | |
449 | \r | |
450 | it("should not throw an error", function() {\r | |
451 | expect(function() {\r | |
452 | grid.destroy();\r | |
453 | }).not.toThrow();\r | |
454 | });\r | |
455 | });\r | |
456 | \r | |
457 | describe("setting widths", function() {\r | |
458 | function expectWidth(field, width) {\r | |
459 | width -= field._marginWidth;\r | |
460 | expect(field.getWidth()).toBe(width); \r | |
461 | }\r | |
462 | \r | |
463 | function expectWidths() {\r | |
464 | var items = plugin.getEditor().items;\r | |
465 | items.each(function(item, index) {\r | |
466 | expectWidth(item, colRef[index].getWidth());\r | |
467 | });\r | |
468 | }\r | |
469 | \r | |
470 | it("should set fixed column widths", function() {\r | |
471 | makeGrid([{\r | |
472 | dataIndex: 'field1',\r | |
473 | width: 100,\r | |
474 | field: 'textfield'\r | |
475 | }, {\r | |
476 | dataIndex: 'field2',\r | |
477 | width: 200,\r | |
478 | field: 'textfield'\r | |
479 | }]); \r | |
480 | startEdit();\r | |
481 | expectWidths();\r | |
482 | });\r | |
483 | \r | |
484 | it("should set flex widths", function() {\r | |
485 | makeGrid([{\r | |
486 | dataIndex: 'field1',\r | |
487 | flex: 1,\r | |
488 | field: 'textfield'\r | |
489 | }, {\r | |
490 | dataIndex: 'field2',\r | |
491 | flex: 1,\r | |
492 | field: 'textfield'\r | |
493 | }]); \r | |
494 | startEdit();\r | |
495 | expectWidths();\r | |
496 | });\r | |
497 | \r | |
498 | it("should set width with a mix of flex/configured", function() {\r | |
499 | makeGrid([{\r | |
500 | dataIndex: 'field1',\r | |
501 | flex: 1,\r | |
502 | field: 'textfield'\r | |
503 | }, {\r | |
504 | dataIndex: 'field2',\r | |
505 | width: 300,\r | |
506 | field: 'textfield'\r | |
507 | }, {\r | |
508 | dataIndex: 'field3',\r | |
509 | width: 400,\r | |
510 | field: 'textfield'\r | |
511 | }]); \r | |
512 | startEdit();\r | |
513 | expectWidths();\r | |
514 | });\r | |
515 | \r | |
516 | describe("reconfigure", function() {\r | |
517 | it("should set the widths if the editor has not been shown", function() {\r | |
518 | makeGrid();\r | |
519 | grid.reconfigure(null, [{\r | |
520 | dataIndex: 'field1',\r | |
521 | width: 200,\r | |
522 | field: 'textfield'\r | |
523 | }, {\r | |
524 | dataIndex: 'field2',\r | |
525 | width: 300,\r | |
526 | field: 'textfield'\r | |
527 | }]);\r | |
528 | colRef = grid.getColumnManager().getColumns();\r | |
529 | startEdit();\r | |
530 | expectWidths();\r | |
531 | });\r | |
532 | \r | |
533 | it("should set the widths after the editor has already been shown", function() {\r | |
534 | makeGrid();\r | |
535 | plugin.startEdit(store.first());\r | |
536 | plugin.cancelEdit();\r | |
537 | grid.reconfigure(null, [{\r | |
538 | dataIndex: 'field1',\r | |
539 | width: 200,\r | |
540 | field: 'textfield'\r | |
541 | }, {\r | |
542 | dataIndex: 'field2',\r | |
543 | width: 300,\r | |
544 | field: 'textfield'\r | |
545 | }]);\r | |
546 | colRef = grid.getColumnManager().getColumns();\r | |
547 | startEdit();\r | |
548 | expectWidths();\r | |
549 | });\r | |
550 | });\r | |
551 | });\r | |
552 | \r | |
553 | describe("events", function() {\r | |
554 | beforeEach(function() {\r | |
555 | makeGrid();\r | |
556 | });\r | |
557 | describe("beforeedit", function(){\r | |
558 | it("should fire the event", function() {\r | |
559 | var called = false;\r | |
560 | plugin.on('beforeedit', function(){\r | |
561 | called = true;\r | |
562 | });\r | |
563 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
564 | expect(called).toBe(true);\r | |
565 | });\r | |
566 | \r | |
567 | it("should fire the event with the plugin & an event context", function() {\r | |
568 | var p, context;\r | |
569 | plugin.on('beforeedit', function(a1, a2){\r | |
570 | p = a1;\r | |
571 | context = a2;\r | |
572 | });\r | |
573 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
574 | expect(p === plugin).toBe(true);\r | |
575 | expect(context.colIdx).toBe(0);\r | |
576 | expect(context.column === colRef[0]).toBe(true);\r | |
577 | expect(context.grid === grid).toBe(true);\r | |
578 | expect(context.record === getRec(0)).toBe(true);\r | |
579 | expect(context.row === view.getRow(view.all.first())).toBe(true);\r | |
580 | expect(context.rowIdx).toBe(0);\r | |
581 | expect(context.store === store).toBe(true);\r | |
582 | });\r | |
583 | \r | |
584 | it("should prevent editing if false is returned", function(){\r | |
585 | plugin.on('beforeedit', function(a1, a2){\r | |
586 | return false;\r | |
587 | });\r | |
588 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
589 | expect(plugin.editing).toBeFalsy();\r | |
590 | });\r | |
591 | \r | |
592 | it("should prevent editing if context.cancel is set", function(){\r | |
593 | plugin.on('beforeedit', function(p, context){\r | |
594 | context.cancel = true;\r | |
595 | });\r | |
596 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
597 | expect(plugin.editing).toBeFalsy();\r | |
598 | });\r | |
599 | }); \r | |
600 | \r | |
601 | describe("canceledit", function(){\r | |
602 | it("should fire the event when editing is cancelled", function(){\r | |
603 | var called = false;\r | |
604 | plugin.on('canceledit', function(p, context){\r | |
605 | called = true;\r | |
606 | });\r | |
607 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
608 | plugin.cancelEdit();\r | |
609 | expect(called).toBe(true);\r | |
610 | expect(plugin.editing).toBe(false);\r | |
611 | });\r | |
612 | \r | |
613 | it("should pass the plugin and the context", function(){\r | |
614 | var p, context;\r | |
615 | plugin.on('canceledit', function(a1, a2){\r | |
616 | p = a1;\r | |
617 | context = a2;\r | |
618 | });\r | |
619 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
620 | plugin.cancelEdit();\r | |
621 | expect(p === plugin).toBe(true);\r | |
622 | expect(context.colIdx).toBe(0);\r | |
623 | expect(context.column === colRef[0]).toBe(true);\r | |
624 | expect(context.grid === grid).toBe(true);\r | |
625 | expect(context.record === getRec(0)).toBe(true);\r | |
626 | expect(context.row === view.getRow(view.all.first())).toBe(true);\r | |
627 | expect(context.rowIdx).toBe(0);\r | |
628 | expect(context.store === store).toBe(true);\r | |
629 | });\r | |
630 | });\r | |
631 | \r | |
632 | describe("validateedit", function(){\r | |
633 | it("should fire the validateedit event before edit", function(){\r | |
634 | var calledFirst = false,\r | |
635 | called = false;\r | |
636 | \r | |
637 | plugin.on('validateedit', function(){\r | |
638 | calledFirst = !called;\r | |
639 | });\r | |
640 | plugin.on('edit', function(p, context){\r | |
641 | calledFirst = !called;\r | |
642 | });\r | |
643 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
644 | plugin.completeEdit();\r | |
645 | expect(calledFirst).toBe(true);\r | |
646 | }); \r | |
647 | \r | |
648 | it("should pass the plugin and the context", function(){\r | |
649 | var p, context;\r | |
650 | \r | |
651 | plugin.on('validateedit', function(a1, a2){\r | |
652 | p = a1;\r | |
653 | context = a2;\r | |
654 | });\r | |
655 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
656 | plugin.completeEdit();\r | |
657 | expect(p === plugin).toBe(true);\r | |
658 | expect(context.colIdx).toBe(0);\r | |
659 | expect(context.column === colRef[0]).toBe(true);\r | |
660 | expect(context.grid === grid).toBe(true);\r | |
661 | expect(context.record === getRec(0)).toBe(true);\r | |
662 | expect(context.row === view.getRow(view.all.first())).toBe(true);\r | |
663 | expect(context.rowIdx).toBe(0);\r | |
664 | expect(context.store === store).toBe(true);\r | |
665 | }); \r | |
666 | \r | |
667 | it("should veto the completeEdit if we return false", function(){\r | |
668 | var called = false;\r | |
669 | \r | |
670 | plugin.on('validateedit', function(){\r | |
671 | return false;\r | |
672 | });\r | |
673 | plugin.on('edit', function(p, context){\r | |
674 | called = true;\r | |
675 | });\r | |
676 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
677 | plugin.completeEdit();\r | |
678 | expect(plugin.editing).toBe(true);\r | |
679 | expect(called).toBe(false);\r | |
680 | });\r | |
681 | \r | |
682 | it("should veto the completeEdit if we set context.cancel", function(){\r | |
683 | var called = false;\r | |
684 | \r | |
685 | plugin.on('validateedit', function(p, context){\r | |
686 | context.cancel = true;\r | |
687 | });\r | |
688 | plugin.on('edit', function(p, context){\r | |
689 | called = true;\r | |
690 | });\r | |
691 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
692 | plugin.completeEdit();\r | |
693 | expect(plugin.editing).toBe(true);\r | |
694 | expect(called).toBe(false);\r | |
695 | });\r | |
696 | });\r | |
697 | \r | |
698 | describe("edit", function(){\r | |
699 | it("should fire the edit event", function(){\r | |
700 | var called = false;\r | |
701 | \r | |
702 | plugin.on('edit', function(p, context){\r | |
703 | called = true;\r | |
704 | });\r | |
705 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
706 | plugin.completeEdit();\r | |
707 | expect(plugin.editing).toBe(false);\r | |
708 | expect(called).toBe(true);\r | |
709 | }); \r | |
710 | \r | |
711 | it("should pass the plugin and the context", function(){\r | |
712 | var p, context;\r | |
713 | \r | |
714 | plugin.on('edit', function(a1, a2){\r | |
715 | p = a1;\r | |
716 | context = a2;\r | |
717 | });\r | |
718 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
719 | plugin.completeEdit();\r | |
720 | expect(p === plugin).toBe(true);\r | |
721 | expect(context.colIdx).toBe(0);\r | |
722 | expect(context.column === colRef[0]).toBe(true);\r | |
723 | expect(context.grid === grid).toBe(true);\r | |
724 | expect(context.record === getRec(0)).toBe(true);\r | |
725 | expect(context.row === view.getRow(view.all.first())).toBe(true);\r | |
726 | expect(context.rowIdx).toBe(0);\r | |
727 | expect(context.store === store).toBe(true);\r | |
728 | });\r | |
729 | \r | |
730 | it("should update the value in the model", function(){\r | |
731 | \r | |
732 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
733 | plugin.getEditor().items.first().setValue('foo');\r | |
734 | plugin.completeEdit();\r | |
735 | expect(getRec(0).get('field1')).toBe('foo');\r | |
736 | });\r | |
737 | });\r | |
738 | });\r | |
739 | \r | |
740 | describe("dynamic editors", function() {\r | |
741 | beforeEach(function() {\r | |
742 | // Suppress console warning about Trigger field being deprecated\r | |
743 | spyOn(Ext.log, 'warn');\r | |
744 | });\r | |
745 | \r | |
746 | it("should allow the editor to change dynamically", function(){\r | |
747 | var field = new Ext.form.field.Trigger();\r | |
748 | makeGrid();\r | |
749 | colRef[0].setEditor(field);\r | |
750 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
751 | expect(plugin.getEditor().items.first() === field).toBe(true);\r | |
752 | });\r | |
753 | \r | |
754 | it("should allow the editor to change in the beforeedit event", function() {\r | |
755 | var field = new Ext.form.field.Trigger();\r | |
756 | makeGrid();\r | |
757 | plugin.on('beforeedit', function(){\r | |
758 | colRef[0].setEditor(field);\r | |
759 | }); \r | |
760 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
761 | expect(plugin.getEditor().items.first() === field).toBe(true);\r | |
762 | });\r | |
763 | \r | |
764 | it("should correct the width when setting the editor during beforeedit after rendering", function() {\r | |
765 | var field = new Ext.form.field.Trigger();\r | |
766 | makeGrid([{\r | |
767 | width: 500,\r | |
768 | field: 'textfield'\r | |
769 | }]);\r | |
770 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
771 | plugin.cancelEdit();\r | |
772 | plugin.on('beforeedit', function() {\r | |
773 | colRef[0].setEditor(field);\r | |
774 | }); \r | |
775 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
776 | expect(plugin.getEditor().items.first().getWidth()).toBe(500);\r | |
777 | });\r | |
778 | \r | |
779 | it("should allow us to set an editor if one wasn't there before", function() {\r | |
780 | var field = new Ext.form.field.Text();\r | |
781 | makeGrid([{\r | |
782 | dataIndex: 'field1'\r | |
783 | }, {\r | |
784 | dataIndex: 'field2',\r | |
785 | field: 'textfield'\r | |
786 | }]); \r | |
787 | colRef = grid.getColumnManager().getColumns();\r | |
788 | colRef[0].setEditor(field);\r | |
789 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
790 | expect(plugin.getEditor().items.first() === field).toBe(true);\r | |
791 | });\r | |
792 | \r | |
793 | it("should allow us to clear out an editor", function() {\r | |
794 | makeGrid();\r | |
795 | colRef[0].setEditor(null);\r | |
796 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
797 | expect(plugin.getEditor().items.first().getXType()).toBe('displayfield');\r | |
798 | });\r | |
799 | \r | |
800 | it("should destroy the old field", function() {\r | |
801 | var field = new Ext.form.field.Text();\r | |
802 | \r | |
803 | makeGrid([{\r | |
804 | dataIndex: 'field1',\r | |
805 | field: field\r | |
806 | }]); \r | |
807 | colRef = grid.getColumnManager().getColumns();\r | |
808 | colRef[0].setEditor(new Ext.form.field.Text());\r | |
809 | expect(field.destroyed).toBe(true);\r | |
810 | });\r | |
811 | });\r | |
812 | \r | |
813 | describe("hidden columns", function() {\r | |
814 | beforeEach(function(){\r | |
815 | makeGrid([{\r | |
816 | dataIndex: 'field1',\r | |
817 | hidden: true,\r | |
818 | field: 'textfield'\r | |
819 | }, {\r | |
820 | dataIndex: 'field2',\r | |
821 | field: 'textfield'\r | |
822 | }, {\r | |
823 | dataIndex: 'field3',\r | |
824 | field: 'textfield'\r | |
825 | }, {\r | |
826 | dataIndex: 'field4',\r | |
827 | hidden: true,\r | |
828 | field: 'textfield'\r | |
829 | }, {\r | |
830 | dataIndex: 'field5',\r | |
831 | field: 'textfield'\r | |
832 | }, {\r | |
833 | dataIndex: 'field6',\r | |
834 | field: 'textfield'\r | |
835 | }, {\r | |
836 | dataIndex: 'field7',\r | |
837 | field: 'textfield'\r | |
838 | }]);\r | |
839 | colRef = grid.getColumnManager().getColumns();\r | |
840 | });\r | |
841 | \r | |
842 | it("should not show editors for hidden columns", function() {\r | |
843 | triggerCellMouseEvent('dblclick', 0, 1);\r | |
844 | expect(plugin.getEditor().items.getAt(0).isVisible()).toBe(false);\r | |
845 | expect(plugin.getEditor().items.getAt(3).isVisible()).toBe(false);\r | |
846 | });\r | |
847 | \r | |
848 | it("should focus the first visible field", function() {\r | |
849 | startEdit();\r | |
850 | var toFocus = plugin.getEditor().items.getAt(1);\r | |
851 | jasmine.waitForFocus(toFocus);\r | |
852 | jasmine.expectFocused(toFocus);\r | |
853 | });\r | |
854 | \r | |
855 | it("should show the editor when the column is shown", function() {\r | |
856 | startEdit();\r | |
857 | colRef[0].show();\r | |
858 | expect(plugin.getEditor().items.getAt(0).isVisible()).toBe(true);\r | |
859 | });\r | |
860 | \r | |
861 | it("should hide the editor when the column is hidden", function() {\r | |
862 | startEdit();\r | |
863 | colRef[6].show();\r | |
864 | expect(plugin.getEditor().items.getAt(6).isVisible()).toBe(true);\r | |
865 | });\r | |
866 | });\r | |
867 | \r | |
868 | describe("reconfigure", function() {\r | |
869 | var old;\r | |
870 | describe("original editor not rendered", function() {\r | |
871 | beforeEach(function() {\r | |
872 | makeGrid();\r | |
873 | old = [];\r | |
874 | Ext.Array.forEach(grid.getColumnManager().getColumns(), function(col) {\r | |
875 | old.push(col.getEditor()); \r | |
876 | });\r | |
877 | grid.reconfigure(null, [{\r | |
878 | dataIndex: 'field1',\r | |
879 | field: {\r | |
880 | id: 'newEd'\r | |
881 | }\r | |
882 | }, {\r | |
883 | dataIndex: 'field2'\r | |
884 | }]);\r | |
885 | colRef = grid.getColumnManager().getColumns();\r | |
886 | });\r | |
887 | \r | |
888 | it("should destroy old editors", function() {\r | |
889 | Ext.Array.forEach(old, function(item){\r | |
890 | expect(item.destroyed).toBe(true); \r | |
891 | });\r | |
892 | });\r | |
893 | \r | |
894 | it("should update columns with no editors", function() {\r | |
895 | triggerCellMouseEvent('dblclick', 0, 1);\r | |
896 | expect(plugin.getEditor().items.getAt(1).getXType()).toBe('displayfield');\r | |
897 | }); \r | |
898 | \r | |
899 | it("should use new editors", function() {\r | |
900 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
901 | expect(plugin.getEditor().items.first().getItemId()).toBe('newEd');\r | |
902 | });\r | |
903 | });\r | |
904 | \r | |
905 | describe("original rendered", function() {\r | |
906 | it("should cancel editing on reconfigure if visible", function() {\r | |
907 | makeGrid();\r | |
908 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
909 | grid.reconfigure(null, [{\r | |
910 | dataIndex: 'field1'\r | |
911 | }]);\r | |
912 | expect(plugin.editing).toBe(false);\r | |
913 | expect(plugin.getEditor().isVisible()).toBe(false);\r | |
914 | });\r | |
915 | });\r | |
916 | });\r | |
917 | \r | |
918 | describe("values/validity", function() {\r | |
919 | it("should set the values on each field", function() {\r | |
920 | makeGrid();\r | |
921 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
922 | var items = plugin.getEditor().items;\r | |
923 | \r | |
924 | expect(items.getAt(0).getValue()).toBe('1.1');\r | |
925 | expect(items.getAt(1).getValue()).toBe('1.2');\r | |
926 | expect(items.getAt(2).getValue()).toBe('1.3');\r | |
927 | expect(items.getAt(3).getValue()).toBe('1.4');\r | |
928 | expect(items.getAt(4).getValue()).toBe('1.5');\r | |
929 | });\r | |
930 | \r | |
931 | it("should set the correct value if the field name config is specified", function() {\r | |
932 | makeGrid([{\r | |
933 | dataIndex: 'field1',\r | |
934 | field: {\r | |
935 | xtype: 'textfield',\r | |
936 | name: 'field2'\r | |
937 | }\r | |
938 | }]); \r | |
939 | \r | |
940 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
941 | expect(plugin.getEditor().items.first().getValue()).toBe('1.2');\r | |
942 | });\r | |
943 | \r | |
944 | it("should not retain the value from previous edits if the model value is not defined", function() {\r | |
945 | makeGrid();\r | |
946 | startEdit(0);\r | |
947 | var field = plugin.getEditor().items.getAt(0);\r | |
948 | expect(field.getValue()).toBe('1.1');\r | |
949 | plugin.completeEdit();\r | |
950 | store.insert(0, {});\r | |
951 | startEdit(0);\r | |
952 | expect(field.getValue()).toBe('');\r | |
953 | });\r | |
954 | \r | |
955 | describe("buttons", function() {\r | |
956 | beforeEach(function() {\r | |
957 | makeGrid();\r | |
958 | });\r | |
959 | \r | |
960 | it("should disable the buttons when starting editing in an invalid state", function() {\r | |
961 | store.first().set('field1', '');\r | |
962 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
963 | expect(plugin.getEditor().down('#update').disabled).toBe(true);\r | |
964 | });\r | |
965 | \r | |
966 | it("should disable the buttons when a value changes the form to a invalid state", function() {\r | |
967 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
968 | clearFormDelay();\r | |
969 | plugin.getEditor().items.first().setValue('');\r | |
970 | expect(plugin.getEditor().down('#update').disabled).toBe(true);\r | |
971 | });\r | |
972 | \r | |
973 | it("should enable the buttons when a value changes the form to a valid state", function() {\r | |
974 | store.first().set('field1', '');\r | |
975 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
976 | clearFormDelay();\r | |
977 | plugin.getEditor().items.first().setValue('Foo');\r | |
978 | expect(plugin.getEditor().down('#update').disabled).toBe(false);\r | |
979 | });\r | |
980 | \r | |
981 | it("should update the state correctly after loading multiple records", function() {\r | |
982 | store.removeAll();\r | |
983 | store.insert(0, {});\r | |
984 | startEdit(0);\r | |
985 | clearFormDelay();\r | |
986 | plugin.getEditor().items.first().setValue('Foo');\r | |
987 | plugin.completeEdit();\r | |
988 | store.insert(0, {});\r | |
989 | startEdit(0);\r | |
990 | plugin.getEditor().items.first().setValue('Foo');\r | |
991 | expect(plugin.getEditor().down('#update').disabled).toBe(false);\r | |
992 | });\r | |
993 | });\r | |
994 | \r | |
995 | describe("tooltip", function() {\r | |
996 | beforeEach(function() {\r | |
997 | makeGrid();\r | |
998 | });\r | |
999 | \r | |
1000 | it("should show the tip when starting editing in an invalid state", function() {\r | |
1001 | store.first().set('field1', '');\r | |
1002 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1003 | expect(plugin.getEditor().tooltip.isVisible()).toBe(true);\r | |
1004 | });\r | |
1005 | \r | |
1006 | it("should show the tip when a value changes the form to a invalid state", function() {\r | |
1007 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1008 | clearFormDelay();\r | |
1009 | var editor = plugin.getEditor();\r | |
1010 | editor.items.first().setValue('');\r | |
1011 | expect(editor.tooltip.isVisible()).toBe(true);\r | |
1012 | });\r | |
1013 | \r | |
1014 | it("should hide the tip when a value changes the form to a valid state", function() {\r | |
1015 | store.first().set('field1', '');\r | |
1016 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1017 | clearFormDelay();\r | |
1018 | var editor = plugin.getEditor();\r | |
1019 | editor.items.first().setValue('Foo');\r | |
1020 | expect(editor.tooltip.isVisible()).toBe(false);\r | |
1021 | });\r | |
1022 | \r | |
1023 | describe("tip content", function() {\r | |
1024 | function expectErrors(errors) {\r | |
1025 | // Parse out the markup here\r | |
1026 | var editor = plugin.getEditor(),\r | |
1027 | tipErrors = editor.tooltip.getEl().query('.' + editor.errorCls),\r | |
1028 | len = tipErrors.length,\r | |
1029 | i, html, error;\r | |
1030 | \r | |
1031 | expect(len).toBe(errors.length);\r | |
1032 | \r | |
1033 | for (i = 0; i < len; ++i) {\r | |
1034 | html = tipErrors[i].innerHTML;\r | |
1035 | error = errors[i];\r | |
1036 | expect(html).toBe(error);\r | |
1037 | }\r | |
1038 | }\r | |
1039 | \r | |
1040 | it("should update the tip content with errors for each field", function() {\r | |
1041 | store.first().set('field2', '');\r | |
1042 | var editor = plugin.getEditor(),\r | |
1043 | f1 = editor.items.getAt(0),\r | |
1044 | f2 = editor.items.getAt(1),\r | |
1045 | f3 = editor.items.getAt(2);\r | |
1046 | \r | |
1047 | f1.minLength = 100;\r | |
1048 | f2.allowBlank = false;\r | |
1049 | f3.maxLength = 1;\r | |
1050 | \r | |
1051 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1052 | clearFormDelay();\r | |
1053 | expectErrors([\r | |
1054 | 'F1: ' + f1.getErrors()[0],\r | |
1055 | 'F2: ' + f2.getErrors()[0],\r | |
1056 | 'F3: ' + f3.getErrors()[0]\r | |
1057 | ]);\r | |
1058 | });\r | |
1059 | \r | |
1060 | it("should add a new field if it becomes invalid", function() {\r | |
1061 | var editor = plugin.getEditor(),\r | |
1062 | f1 = editor.items.getAt(0),\r | |
1063 | f2 = editor.items.getAt(1),\r | |
1064 | f3 = editor.items.getAt(2);\r | |
1065 | \r | |
1066 | f1.minLength = 100;\r | |
1067 | f2.allowBlank = false;\r | |
1068 | f3.maxLength = 1;\r | |
1069 | \r | |
1070 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1071 | clearFormDelay();\r | |
1072 | expectErrors([\r | |
1073 | 'F1: ' + f1.getErrors()[0],\r | |
1074 | 'F3: ' + f3.getErrors()[0]\r | |
1075 | ]);\r | |
1076 | f2.setValue('');\r | |
1077 | expectErrors([\r | |
1078 | 'F1: ' + f1.getErrors()[0],\r | |
1079 | 'F2: ' + f2.getErrors()[0],\r | |
1080 | 'F3: ' + f3.getErrors()[0]\r | |
1081 | ]);\r | |
1082 | });\r | |
1083 | \r | |
1084 | it("should remove a existing field if it becomes valid", function() {\r | |
1085 | store.first().set('field2', '');\r | |
1086 | var editor = plugin.getEditor(),\r | |
1087 | f1 = editor.items.getAt(0),\r | |
1088 | f2 = editor.items.getAt(1),\r | |
1089 | f3 = editor.items.getAt(2);\r | |
1090 | \r | |
1091 | f1.minLength = 100;\r | |
1092 | f2.allowBlank = false;\r | |
1093 | f3.maxLength = 1;\r | |
1094 | \r | |
1095 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1096 | clearFormDelay();\r | |
1097 | expectErrors([\r | |
1098 | 'F1: ' + f1.getErrors()[0],\r | |
1099 | 'F2: ' + f2.getErrors()[0],\r | |
1100 | 'F3: ' + f3.getErrors()[0]\r | |
1101 | ]);\r | |
1102 | f2.setValue('Foo');\r | |
1103 | expectErrors([\r | |
1104 | 'F1: ' + f1.getErrors()[0],\r | |
1105 | 'F3: ' + f3.getErrors()[0]\r | |
1106 | ]);\r | |
1107 | });\r | |
1108 | \r | |
1109 | it("should only render the first error from the field", function() {\r | |
1110 | var editor = plugin.getEditor(),\r | |
1111 | f1 = editor.items.getAt(0);\r | |
1112 | \r | |
1113 | f1.getErrors = function() {\r | |
1114 | return ['Foo', 'Bar'];\r | |
1115 | };\r | |
1116 | \r | |
1117 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1118 | clearFormDelay();\r | |
1119 | expectErrors(['F1: Foo']);\r | |
1120 | });\r | |
1121 | \r | |
1122 | it("should not prefix the error with the column name if the text is empty", function() {\r | |
1123 | var editor = plugin.getEditor(),\r | |
1124 | f1 = editor.items.getAt(0),\r | |
1125 | f2 = editor.items.getAt(1);\r | |
1126 | \r | |
1127 | f1.getErrors = function() {\r | |
1128 | return ['Foo'];\r | |
1129 | };\r | |
1130 | f2.getErrors = function() {\r | |
1131 | return ['Bar'];\r | |
1132 | };\r | |
1133 | colRef[0].text = '';\r | |
1134 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1135 | clearFormDelay();\r | |
1136 | expectErrors(['Foo', 'F2: Bar']);\r | |
1137 | });\r | |
1138 | });\r | |
1139 | });\r | |
1140 | });\r | |
1141 | \r | |
1142 | describe("field types", function() {\r | |
1143 | it("should set values with a fieldcontainer", function() {\r | |
1144 | makeGrid([{\r | |
1145 | dataIndex: 'field1',\r | |
1146 | field: {\r | |
1147 | xtype: 'fieldcontainer',\r | |
1148 | items: {\r | |
1149 | name: 'field1',\r | |
1150 | xtype: 'textfield'\r | |
1151 | }\r | |
1152 | }\r | |
1153 | }]);\r | |
1154 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1155 | expect(plugin.getEditor().items.first().items.first().getValue()).toBe('1.1');\r | |
1156 | }); \r | |
1157 | });\r | |
1158 | \r | |
1159 | describe("key events", function() {\r | |
1160 | it("should cancel editing on ESC", function() {\r | |
1161 | makeGrid();\r | |
1162 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1163 | triggerEditorKey(ESC);\r | |
1164 | expect(plugin.editing).toBe(false);\r | |
1165 | }); \r | |
1166 | \r | |
1167 | it("should complete on edit if the form is valid", function() {\r | |
1168 | makeGrid();\r | |
1169 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1170 | plugin.getEditor().items.first().setValue('Foo');\r | |
1171 | triggerEditorKey(ENTER);\r | |
1172 | expect(plugin.editing).toBe(false);\r | |
1173 | expect(store.first().get('field1')).toBe('Foo');\r | |
1174 | });\r | |
1175 | \r | |
1176 | it("should not finish editing if enter is pressed and the form is invalid", function() {\r | |
1177 | makeGrid();\r | |
1178 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1179 | // First doesn't allow blank\r | |
1180 | plugin.getEditor().items.first().setValue('');\r | |
1181 | triggerEditorKey(ENTER);\r | |
1182 | expect(plugin.editing).toBe(true);\r | |
1183 | });\r | |
1184 | \r | |
1185 | it("should be able to cancel after pressing enter and the form is invalid", function() {\r | |
1186 | makeGrid();\r | |
1187 | triggerCellMouseEvent('dblclick', 0, 0);\r | |
1188 | // First doesn't allow blank\r | |
1189 | plugin.getEditor().items.first().setValue('');\r | |
1190 | triggerEditorKey(ENTER);\r | |
1191 | triggerEditorKey(ESC);\r | |
1192 | expect(plugin.editing).toBe(false);\r | |
1193 | expect(store.first().get('field1')).toBe('1.1');\r | |
1194 | });\r | |
1195 | });\r | |
1196 | \r | |
1197 | describe("adding/removing/moving columns", function() {\r | |
1198 | function dragColumn(from, to, onRight) {\r | |
1199 | var fromBox = from.el.getBox(),\r | |
1200 | fromMx = fromBox.x + fromBox.width/2,\r | |
1201 | fromMy = fromBox.y + fromBox.height/2,\r | |
1202 | toBox = to.el.getBox(),\r | |
1203 | toMx = toBox.x,\r | |
1204 | toMy = toBox.y + toBox.height/2,\r | |
1205 | offset = onRight ? toBox.width - 6 : 5,\r | |
1206 | moveOffset = toMx + offset,\r | |
1207 | dragThresh = onRight ? Ext.dd.DragDropManager.clickPixelThresh + 1 : -Ext.dd.DragDropManager.clickPixelThresh - 1;\r | |
1208 | \r | |
1209 | // Mousedown on the header to drag\r | |
1210 | jasmine.fireMouseEvent(from.el.dom, 'mouseover', fromMx, fromMy);\r | |
1211 | jasmine.fireMouseEvent(from.titleEl.dom, 'mousedown', fromMx, fromMy);\r | |
1212 | \r | |
1213 | // The initial move which tiggers the start of the drag\r | |
1214 | jasmine.fireMouseEvent(from.el.dom, 'mousemove', fromMx + dragThresh, fromMy);\r | |
1215 | \r | |
1216 | // The move to left of the centre of the target element\r | |
1217 | jasmine.fireMouseEvent(to.el.dom, 'mousemove', moveOffset, toMy);\r | |
1218 | \r | |
1219 | // Drop to left of centre of target element\r | |
1220 | jasmine.fireMouseEvent(to.el.dom, 'mouseup', moveOffset, toMy);\r | |
1221 | }\r | |
1222 | \r | |
1223 | describe("modification while visible with the grid pending layouts", function() {\r | |
1224 | it("should update the layout appropriately", function() {\r | |
1225 | makeGrid();\r | |
1226 | startEdit();\r | |
1227 | \r | |
1228 | var editor = plugin.getEditor(),\r | |
1229 | count = editor.componentLayoutCounter;\r | |
1230 | \r | |
1231 | dragColumn(colRef[3], colRef[0], false);\r | |
1232 | expect(editor.componentLayoutCounter).toBe(count + 1);\r | |
1233 | });\r | |
1234 | });\r | |
1235 | \r | |
1236 | function createLockingSuite(beforeFirstShow) {\r | |
1237 | describe(beforeFirstShow ? "before first show" : "after first show", function() {\r | |
1238 | describe("basic operations", function() {\r | |
1239 | beforeEach(function() {\r | |
1240 | makeGrid();\r | |
1241 | });\r | |
1242 | \r | |
1243 | it("should add a new field", function() {\r | |
1244 | if (!beforeFirstShow) {\r | |
1245 | startEdit();\r | |
1246 | }\r | |
1247 | grid.headerCt.add({\r | |
1248 | dataIndex: 'field6',\r | |
1249 | field: {\r | |
1250 | xtype: 'textfield',\r | |
1251 | id: 'field6'\r | |
1252 | }\r | |
1253 | }); \r | |
1254 | if (beforeFirstShow) {\r | |
1255 | startEdit();\r | |
1256 | }\r | |
1257 | expect(plugin.getEditor().getComponent('field6').getValue()).toBe('1.6');\r | |
1258 | }); \r | |
1259 | \r | |
1260 | it("should remove an existing field & destroy it", function() {\r | |
1261 | if (!beforeFirstShow) {\r | |
1262 | startEdit();\r | |
1263 | }\r | |
1264 | grid.headerCt.remove(1);\r | |
1265 | if (beforeFirstShow) {\r | |
1266 | startEdit();\r | |
1267 | }\r | |
1268 | expect(plugin.getEditor().getComponent('field2')).toBeFalsy();\r | |
1269 | expect(Ext.getCmp('field2')).toBeFalsy(); \r | |
1270 | });\r | |
1271 | \r | |
1272 | it("should move the field in the editor", function() {\r | |
1273 | if (!beforeFirstShow) {\r | |
1274 | startEdit();\r | |
1275 | }\r | |
1276 | grid.headerCt.move(0, 5);\r | |
1277 | if (beforeFirstShow) {\r | |
1278 | startEdit();\r | |
1279 | }\r | |
1280 | expect(plugin.getEditor().items.last().getItemId()).toBe('field1'); \r | |
1281 | });\r | |
1282 | \r | |
1283 | it("should remove all fields", function() {\r | |
1284 | if (!beforeFirstShow) {\r | |
1285 | startEdit();\r | |
1286 | }\r | |
1287 | grid.headerCt.removeAll();\r | |
1288 | if (beforeFirstShow) {\r | |
1289 | startEdit();\r | |
1290 | }\r | |
1291 | expect(plugin.getEditor().items.getCount()).toBe(0);\r | |
1292 | });\r | |
1293 | });\r | |
1294 | \r | |
1295 | describe("moving with hidden columns", function() {\r | |
1296 | // The purpose here is to simulate user drag drops\r | |
1297 | function makeColumns(columns) {\r | |
1298 | var len = columns.length,\r | |
1299 | out = [],\r | |
1300 | i;\r | |
1301 | \r | |
1302 | for (i = 1; i <= len; ++i) {\r | |
1303 | out.push({\r | |
1304 | name: 'F' + i,\r | |
1305 | dataIndex: 'field' + i,\r | |
1306 | hidden: columns[i],\r | |
1307 | field: {\r | |
1308 | xtype: 'textfield',\r | |
1309 | id: 'field' + i\r | |
1310 | }\r | |
1311 | });\r | |
1312 | }\r | |
1313 | return out;\r | |
1314 | }\r | |
1315 | \r | |
1316 | it("should insert after the first hidden column", function() {\r | |
1317 | makeGrid(makeColumns([true, false, false, false, false]));\r | |
1318 | if (!beforeFirstShow) {\r | |
1319 | startEdit();\r | |
1320 | }\r | |
1321 | // insert before the first visible column\r | |
1322 | grid.headerCt.move(4, 1);\r | |
1323 | if (beforeFirstShow) {\r | |
1324 | startEdit();\r | |
1325 | }\r | |
1326 | expect(plugin.getEditor().items.getAt(1).getItemId()).toBe('field5'); \r | |
1327 | });\r | |
1328 | \r | |
1329 | it("should insert before the last hidden column", function() {\r | |
1330 | makeGrid(makeColumns([false, false, false, false, true]));\r | |
1331 | if (!beforeFirstShow) {\r | |
1332 | startEdit();\r | |
1333 | }\r | |
1334 | // insert after the last visible column\r | |
1335 | grid.headerCt.move(0, 3);\r | |
1336 | if (beforeFirstShow) {\r | |
1337 | startEdit();\r | |
1338 | }\r | |
1339 | expect(plugin.getEditor().items.getAt(3).getItemId()).toBe('field1'); \r | |
1340 | });\r | |
1341 | \r | |
1342 | it("should position properly with hidden columns in the middle", function() {\r | |
1343 | makeGrid(makeColumns([false, false, true, false, true, true, false]));\r | |
1344 | if (!beforeFirstShow) {\r | |
1345 | startEdit();\r | |
1346 | }\r | |
1347 | grid.headerCt.move(0, 3);\r | |
1348 | grid.headerCt.insert(1, colRef[6]);\r | |
1349 | if (beforeFirstShow) {\r | |
1350 | startEdit();\r | |
1351 | }\r | |
1352 | expect(plugin.getEditor().items.getAt(1).getItemId()).toBe('field7'); \r | |
1353 | expect(plugin.getEditor().items.getAt(4).getItemId()).toBe('field1'); \r | |
1354 | });\r | |
1355 | });\r | |
1356 | \r | |
1357 | describe("moving grouped columns", function() {\r | |
1358 | beforeEach(function() {\r | |
1359 | makeGrid([{\r | |
1360 | text: 'Locked',\r | |
1361 | dataIndex: 'field10',\r | |
1362 | locked: true\r | |
1363 | }, {\r | |
1364 | columns: [{\r | |
1365 | dataIndex: 'field1',\r | |
1366 | field: {id: 'field1'}\r | |
1367 | }, {\r | |
1368 | dataIndex: 'field2',\r | |
1369 | field: {id: 'field2'}\r | |
1370 | }, {\r | |
1371 | dataIndex: 'field3',\r | |
1372 | field: {id: 'field3'}\r | |
1373 | }]\r | |
1374 | }, {\r | |
1375 | columns: [{\r | |
1376 | dataIndex: 'field4',\r | |
1377 | field: {id: 'field4'}\r | |
1378 | }, {\r | |
1379 | dataIndex: 'field5',\r | |
1380 | field: {id: 'field5'}\r | |
1381 | }, {\r | |
1382 | dataIndex: 'field6',\r | |
1383 | field: {id: 'field6'}\r | |
1384 | }]\r | |
1385 | }, {\r | |
1386 | columns: [{\r | |
1387 | dataIndex: 'field7',\r | |
1388 | field: {id: 'field7'}\r | |
1389 | }, {\r | |
1390 | dataIndex: 'field8',\r | |
1391 | field: {id: 'field8'}\r | |
1392 | }, {\r | |
1393 | dataIndex: 'field9',\r | |
1394 | field: {id: 'field9'}\r | |
1395 | }]\r | |
1396 | }]);\r | |
1397 | });\r | |
1398 | \r | |
1399 | function expectOrder(order) {\r | |
1400 | // Extract the items collection of the normal (unlocked) side of the editor.\r | |
1401 | var items = plugin.getEditor().items.items[1].items,\r | |
1402 | len = order.length,\r | |
1403 | i;\r | |
1404 | \r | |
1405 | for (i = 0; i < len; ++i) {\r | |
1406 | expect(items.getAt(i).getItemId()).toBe(order[i]);\r | |
1407 | }\r | |
1408 | }\r | |
1409 | \r | |
1410 | it("should move all leaf columns to the left", function() {\r | |
1411 | if (!beforeFirstShow) {\r | |
1412 | startEdit();\r | |
1413 | }\r | |
1414 | grid.normalGrid.headerCt.move(1, 0);\r | |
1415 | if (beforeFirstShow) {\r | |
1416 | startEdit();\r | |
1417 | }\r | |
1418 | expectOrder(['field4', 'field5', 'field6', 'field1', 'field2', 'field3', 'field7', 'field8', 'field9']);\r | |
1419 | });\r | |
1420 | \r | |
1421 | it("should move all leaf columns to the right", function() {\r | |
1422 | if (!beforeFirstShow) {\r | |
1423 | startEdit();\r | |
1424 | }\r | |
1425 | grid.normalGrid.headerCt.move(1, 2);\r | |
1426 | if (beforeFirstShow) {\r | |
1427 | startEdit();\r | |
1428 | }\r | |
1429 | expectOrder(['field1', 'field2', 'field3', 'field7', 'field8', 'field9', 'field4', 'field5', 'field6']);\r | |
1430 | });\r | |
1431 | });\r | |
1432 | });\r | |
1433 | }\r | |
1434 | createLockingSuite(true);\r | |
1435 | createLockingSuite(false);\r | |
1436 | });\r | |
1437 | });\r | |
1438 | }\r | |
1439 | createSuite(false);\r | |
1440 | createSuite(true);\r | |
1441 | }); |