]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/grid/grid-columns.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / grid / grid-columns.js
CommitLineData
6527f429
DM
1describe("grid-columns", function() {\r
2 function createSuite(buffered) {\r
3 describe(buffered ? "with buffered rendering" : "without buffered rendering", function() {\r
4 var defaultColNum = 4,\r
5 totalWidth = 1000,\r
6 grid, view, colRef, store, column;\r
7 \r
8 function makeGrid(numCols, gridCfg, hiddenFn, lockedFn){\r
9 var cols, col, i;\r
10 \r
11 gridCfg = gridCfg || {};\r
12 \r
13 colRef = [];\r
14 if (!numCols || typeof numCols === 'number') {\r
15 cols = [];\r
16 numCols = numCols || defaultColNum; \r
17 \r
18 \r
19 for (i = 0; i < numCols; ++i) {\r
20 col = {\r
21 itemId: 'col' + i,\r
22 text: 'Col' + i,\r
23 dataIndex: 'field' + i\r
24 };\r
25 \r
26 if (hiddenFn && hiddenFn(i)) {\r
27 col.hidden = true;\r
28 }\r
29 \r
30 if (lockedFn && lockedFn(i)) {\r
31 col.locked = true;\r
32 }\r
33 col = new Ext.grid.column.Column(col);\r
34 cols.push(col);\r
35 }\r
36 } else {\r
37 cols = numCols;\r
38 }\r
39\r
40 store = new Ext.data.Store({\r
41 model: spec.TestModel,\r
42 data: [{\r
43 field0: 'val1',\r
44 field1: 'val2',\r
45 field2: 'val3',\r
46 field3: 'val4',\r
47 field4: 'val5'\r
48 }]\r
49 });\r
50\r
51 grid = new Ext.grid.Panel(Ext.apply({\r
52 renderTo: Ext.getBody(),\r
53 columns: cols,\r
54 width: totalWidth,\r
55 height: 500,\r
56 border: false,\r
57 store: store,\r
58 bufferedRenderer: buffered,\r
59 viewConfig: {\r
60 mouseOverOutBuffer: 0\r
61 }\r
62 }, gridCfg));\r
63\r
64 view = grid.view;\r
65 colRef = grid.getColumnManager().getColumns();\r
66 }\r
67\r
68 function getCell(rowIdx, colIdx) {\r
69 return grid.getView().getCellInclusive({\r
70 row: rowIdx,\r
71 column: colIdx\r
72 });\r
73 }\r
74\r
75 function getCellText(rowIdx, colIdx) {\r
76 return getCellInner(rowIdx, colIdx).innerHTML;\r
77 }\r
78\r
79 function getCellInner(rowIdx, colIdx) {\r
80 var cell = getCell(rowIdx, colIdx);\r
81 return Ext.fly(cell).down(grid.getView().innerSelector).dom;\r
82 }\r
83\r
84 function hasCls(el, cls) {\r
85 return Ext.fly(el).hasCls(cls);\r
86 }\r
87\r
88 function clickHeader(col) {\r
89 // Offset so we're not on the edges to trigger a drag\r
90 jasmine.fireMouseEvent(col.titleEl, 'click', 10);\r
91 }\r
92\r
93 function setup() {\r
94 Ext.define('spec.TestModel', {\r
95 extend: 'Ext.data.Model',\r
96 fields: ['field0', 'field1', 'field2', 'field3', 'field4']\r
97 });\r
98 }\r
99\r
100 function tearDown() {\r
101 Ext.destroy(grid, store, column);\r
102 grid = view = store = colRef = column = null;\r
103 Ext.undefine('spec.TestModel');\r
104 Ext.data.Model.schema.clear();\r
105 }\r
106\r
107 beforeEach(setup);\r
108\r
109 afterEach(tearDown);\r
110\r
111 describe('as containers', function () {\r
112 var leafCls = 'x-leaf-column-header',\r
113 col;\r
114\r
115 afterEach(function () {\r
116 col = null;\r
117 });\r
118\r
119 describe('group headers', function () {\r
120 beforeEach(function () {\r
121 makeGrid([{\r
122 itemId: 'main1',\r
123 columns: [{\r
124 itemId: 'child1'\r
125 }, {\r
126 itemId: 'child2'\r
127 }, {\r
128 itemId: 'child3'\r
129 }]\r
130 }]);\r
131\r
132 col = grid.down('#main1');\r
133 });\r
134\r
135 it('should be stamped as a container', function () {\r
136 expect(col.isContainer).toBe(true);\r
137 });\r
138\r
139 it('should not give the titleEl the leaf column class', function () {\r
140 expect(col.titleEl.hasCls(leafCls)).toBe(false);\r
141 });\r
142 });\r
143\r
144 describe('contains child items', function () {\r
145 beforeEach(function () {\r
146 makeGrid([{\r
147 text: 'Foo',\r
148 dataIndex: 'field0',\r
149 items: [{\r
150 xtype: 'textfield',\r
151 itemId: 'foo'\r
152 }]\r
153 }]);\r
154\r
155 col = grid.visibleColumnManager.getHeaderByDataIndex('field0');\r
156 });\r
157\r
158 it('should be stamped as a container', function () {\r
159 expect(col.isContainer).toBe(true);\r
160 });\r
161\r
162 it('should not give the titleEl the leaf column class', function () {\r
163 expect(col.titleEl.hasCls(leafCls)).toBe(false);\r
164 });\r
165\r
166 describe('focusing', function () {\r
167 // See EXTJS-15757.\r
168 it('should not throw when focusing', function () {\r
169 expect(function () {\r
170 grid.down('#foo').onFocus();\r
171 }).not.toThrow();\r
172 });\r
173\r
174 it('should return the items collection', function () {\r
175 var col = grid.visibleColumnManager.getHeaderByDataIndex('field0');\r
176 expect(col.getFocusables()).toBe(col.items.items);\r
177 });\r
178 });\r
179 });\r
180 });\r
181\r
182 describe("cell sizing", function() {\r
183 it("should size the cells to match fixed header sizes", function() {\r
184 makeGrid([{\r
185 width: 200\r
186 }, {\r
187 width: 500\r
188 }]);\r
189 expect(getCell(0, 0).getWidth()).toBe(200);\r
190 expect(getCell(0, 1).getWidth()).toBe(500);\r
191 });\r
192\r
193 it("should size the cells to match flex header sizes", function() {\r
194 makeGrid([{\r
195 flex: 8\r
196 }, {\r
197 flex: 2\r
198 }]);\r
199 expect(getCell(0, 0).getWidth()).toBe(800);\r
200 expect(getCell(0, 1).getWidth()).toBe(200);\r
201 });\r
202\r
203 it("should size the cells to match an the text size in the header", function() {\r
204 makeGrid([{\r
205 width: null,\r
206 text: '<div style="width: 25px;"></div>'\r
207 }, {\r
208 width: null,\r
209 text: '<div style="width: 75px;"></div>'\r
210 }]);\r
211\r
212 expect(getCell(0, 0).getWidth()).toBe(colRef[0].titleEl.getWidth() + colRef[0].el.getBorderWidth('lr'));\r
213 expect(getCell(0, 1).getWidth()).toBe(colRef[1].titleEl.getWidth() + colRef[1].el.getBorderWidth('lr'));\r
214 });\r
215 });\r
216\r
217 describe("initializing", function() {\r
218 describe("normal", function() {\r
219 it("should accept a column array", function() {\r
220 makeGrid([{\r
221 text: 'Foo',\r
222 dataIndex: 'field0'\r
223 }]);\r
224 expect(grid.getColumnManager().getHeaderAtIndex(0).text).toBe('Foo');\r
225 });\r
226\r
227 it("should accept a header config", function() {\r
228 makeGrid({\r
229 margin: 5,\r
230 items: [{\r
231 text: 'Foo',\r
232 dataIndex: 'field0'\r
233 }]\r
234 });\r
235 expect(grid.getColumnManager().getHeaderAtIndex(0).text).toBe('Foo');\r
236 expect(grid.headerCt.margin).toBe(5);\r
237 });\r
238 });\r
239\r
240 describe("locking", function() {\r
241 it("should accept a column array, enabling locking if a column is configured with locked: true", function() {\r
242 makeGrid([{\r
243 text: 'Foo',\r
244 dataIndex: 'field0',\r
245 locked: true\r
246 }, {\r
247 text: 'Bar',\r
248 dataIndex: 'field1'\r
249 }]);\r
250 expect(grid.lockable).toBe(true);\r
251 });\r
252\r
253 it("should accept a header config, enabling locking if any column is configured with locked: true", function() {\r
254 makeGrid({\r
255 items: [{\r
256 text: 'Foo',\r
257 dataIndex: 'field0',\r
258 locked: true\r
259 }, {\r
260 text: 'Bar',\r
261 dataIndex: 'field1'\r
262 }]\r
263 });\r
264 expect(grid.lockable).toBe(true);\r
265\r
266 // Top level grid should return columns from both sides\r
267 expect(grid.getVisibleColumns().length).toBe(2);\r
268 expect(grid.getColumns().length).toBe(2);\r
269 });\r
270 });\r
271 });\r
272\r
273 describe("column manager", function() {\r
274 // Get all columns from the grid ref\r
275 function ga() {\r
276 return grid.getColumnManager().getColumns();\r
277 }\r
278\r
279 // Get all manager\r
280 function gam() {\r
281 return grid.getColumnManager();\r
282 }\r
283\r
284 // Get all visible columns from the grid ref\r
285 function gv() {\r
286 return grid.getVisibleColumnManager().getColumns();\r
287 }\r
288\r
289 // Get visible manager\r
290 function gvm() {\r
291 return grid.getVisibleColumnManager();\r
292 }\r
293\r
294 it("should provide a getColumnManager method", function(){\r
295 makeGrid();\r
296 expect(gam().$className).toBe('Ext.grid.ColumnManager');\r
297 });\r
298\r
299 it("should provide a getVisibleColumnManager method", function(){\r
300 makeGrid();\r
301 expect(gvm().$className).toBe('Ext.grid.ColumnManager');\r
302 });\r
303\r
304 describe("simple grid", function(){\r
305 beforeEach(function(){\r
306 makeGrid();\r
307 });\r
308\r
309 it("should return all leaf columns", function() {\r
310 expect(gv().length).toBe(defaultColNum);\r
311 });\r
312\r
313 it("should have the correct column order", function(){\r
314 var cols = gv(),\r
315 i = 0,\r
316 len = cols.length;\r
317\r
318 for (; i < len; ++i) {\r
319 expect(cols[i]).toBe(colRef[i]);\r
320 }\r
321 });\r
322\r
323 it("should update the order when moving columns", function(){\r
324 grid.headerCt.move(3, 1);\r
325 var cols = gv();\r
326 expect(cols[0]).toBe(colRef[0]);\r
327 expect(cols[1]).toBe(colRef[3]);\r
328 expect(cols[2]).toBe(colRef[1]);\r
329 expect(cols[3]).toBe(colRef[2]);\r
330 });\r
331\r
332 it("should update the columns when removing a column", function(){\r
333 grid.headerCt.remove(1);\r
334 var cols = gv();\r
335 expect(cols[0]).toBe(colRef[0]);\r
336 expect(cols[1]).toBe(colRef[2]);\r
337 expect(cols[2]).toBe(colRef[3]);\r
338 });\r
339 \r
340 it("should update the columns when adding a column", function(){\r
341 grid.headerCt.add({\r
342 text: 'Col4'\r
343 });\r
344 expect(gv()[4].text).toBe('Col4');\r
345 });\r
346 \r
347 describe("functions", function() {\r
348 describe("getHeaderIndex", function() {\r
349 it("should return the correct index for the header", function() {\r
350 expect(gam().getHeaderIndex(colRef[3])).toBe(3);\r
351 });\r
352 \r
353 it("should return -1 if the column doesn't exist", function(){\r
354 column = new Ext.grid.column.Column();\r
355 \r
356 expect(gam().getHeaderIndex(column)).toBe(-1);\r
357 });\r
358 }); \r
359 \r
360 describe("getHeaderAtIndex", function(){\r
361 it("should return the column reference", function(){\r
362 expect(gam().getHeaderAtIndex(2)).toBe(colRef[2]); \r
363 });\r
364 \r
365 it("should return null if the index is out of bounds", function(){\r
366 expect(gam().getHeaderAtIndex(10)).toBeNull(); \r
367 }); \r
368 });\r
369 \r
370 describe("getHeaderById", function(){\r
371 it("should return the column reference by id", function(){\r
372 expect(gam().getHeaderById('col1')).toBe(colRef[1]);\r
373 });\r
374 \r
375 it("should return null if the id doesn't exist", function() {\r
376 expect(gam().getHeaderById('foo')).toBeNull(); \r
377 });\r
378 });\r
379 \r
380 it("should return the first item", function(){\r
381 expect(gam().getFirst()).toBe(colRef[0]);\r
382 });\r
383 \r
384 it("should return the last item", function(){\r
385 expect(gam().getLast()).toBe(colRef[3]);\r
386 });\r
387 \r
388 describe("getNextSibling", function(){\r
389 it("should return the next sibling", function(){\r
390 expect(gam().getNextSibling(colRef[1])).toBe(colRef[2]); \r
391 });\r
392 \r
393 it("should return the null if the next sibling doesn't exist", function(){\r
394 expect(gam().getNextSibling(colRef[3])).toBeNull(); \r
395 }); \r
396 });\r
397 \r
398 describe("getPreviousSibling", function(){\r
399 it("should return the previous sibling", function(){\r
400 expect(gam().getPreviousSibling(colRef[2])).toBe(colRef[1]); \r
401 });\r
402 \r
403 it("should return the null if the previous sibling doesn't exist", function(){\r
404 expect(gam().getPreviousSibling(colRef[0])).toBeNull(); \r
405 }); \r
406 });\r
407 });\r
408 });\r
409 \r
410 describe('getHeaderIndex', function () {\r
411 var index, headerCtItems;\r
412\r
413 beforeEach(function () {\r
414 makeGrid([{\r
415 text: 'Name',\r
416 width: 100,\r
417 dataIndex: 'name',\r
418 hidden: true\r
419 },{\r
420 text: 'Email',\r
421 width: 100,\r
422 dataIndex: 'email'\r
423 }, {\r
424 text: 'Stock Price',\r
425 columns: [{\r
426 text: 'Price',\r
427 width: 75,\r
428 dataIndex: 'price'\r
429 }, {\r
430 text: 'Phone',\r
431 width: 80,\r
432 dataIndex: 'phone',\r
433 hidden: true\r
434 }, {\r
435 text: '% Change',\r
436 width: 40,\r
437 dataIndex: 'pctChange'\r
438 }]\r
439 }, {\r
440 text: 'Foo',\r
441 columns: [{\r
442 text: 'Foo Price',\r
443 width: 75,\r
444 dataIndex: 'price',\r
445 hidden: true\r
446 }, {\r
447 text: 'Foo Phone',\r
448 width: 80,\r
449 dataIndex: 'phone'\r
450 }, {\r
451 text: 'Foo % Change',\r
452 width: 40,\r
453 dataIndex: 'pctChange'\r
454 }]\r
455 }]);\r
456\r
457 headerCtItems = grid.headerCt.items;\r
458 });\r
459\r
460 afterEach(function () {\r
461 index = headerCtItems = null;\r
462 });\r
463\r
464 describe('all columns', function () {\r
465 describe('when argument is a column', function () {\r
466 it('should return a valid index', function () {\r
467 index = gam().getHeaderIndex(headerCtItems.items[0]);\r
468\r
469 expect(index).not.toBe(-1);\r
470 expect(index).toBe(0);\r
471 });\r
472\r
473 it('should return the header regardless of visibility', function () {\r
474 var header;\r
475\r
476 header = headerCtItems.items[0];\r
477 index = gam().getHeaderIndex(header);\r
478\r
479 expect(header.hidden).toBe(true);\r
480 expect(index).toBe(0);\r
481 });\r
482\r
483 it('should return the index of the header in its owner stack - rootHeader', function () {\r
484 index = gam().getHeaderIndex(headerCtItems.items[3].items.items[0]);\r
485\r
486 expect(index).toBe(5);\r
487 });\r
488\r
489 it('should return the index of the header in its owner stack - groupHeader', function () {\r
490 // Note that this spec is using the same header as the previous spec to demonstrate the difference.\r
491 var groupHeader = headerCtItems.items[3];\r
492\r
493 index = groupHeader.columnManager.getHeaderIndex(groupHeader.items.items[0]);\r
494\r
495 expect(index).toBe(0);\r
496 });\r
497 });\r
498\r
499 describe('when argument is a group header', function () {\r
500 it('should return a valid index', function () {\r
501 index = gam().getHeaderIndex(headerCtItems.items[2]);\r
502\r
503 expect(index).not.toBe(-1);\r
504 expect(index).toBe(2);\r
505 });\r
506\r
507 it('should return an index of the first leaf of group header', function () {\r
508 var colMgrHeader;\r
509\r
510 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
511 index = gam().getHeaderIndex(headerCtItems.items[2]);\r
512 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
513 colMgrHeader = gam().getHeaderAtIndex(index);\r
514\r
515 // Remember, this is the index of the root header's visible col mgr.\r
516 expect(index).toBe(2);\r
517 expect(colMgrHeader.hidden).toBe(false);\r
518 expect(colMgrHeader.dataIndex).toBe('price');\r
519 });\r
520\r
521 it("should be a reference to the first leaf header in the grouped header's columnn manager", function () {\r
522 var groupedHeader, colMgrHeader, groupHeaderFirstHeader;\r
523\r
524 groupedHeader = headerCtItems.items[2];\r
525 groupHeaderFirstHeader = groupedHeader.columnManager.getHeaderAtIndex(0);\r
526\r
527 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
528 index = gam().getHeaderIndex(groupedHeader);\r
529 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
530 colMgrHeader = gam().getHeaderAtIndex(index);\r
531\r
532 expect(colMgrHeader).toBe(groupHeaderFirstHeader);\r
533 expect(colMgrHeader.hidden).toBe(groupHeaderFirstHeader.hidden);\r
534 expect(colMgrHeader.dataIndex).toBe(groupHeaderFirstHeader.dataIndex);\r
535 });\r
536\r
537 it('should return first sub-header regardless of visibility', function () {\r
538 var groupedHeader, colMgrHeader, groupHeaderFirstHeader;\r
539\r
540 groupedHeader = headerCtItems.items[3];\r
541 groupHeaderFirstHeader = groupedHeader.columnManager.getHeaderAtIndex(0);\r
542\r
543 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
544 index = gam().getHeaderIndex(groupedHeader);\r
545 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
546 colMgrHeader = gam().getHeaderAtIndex(index);\r
547\r
548 expect(colMgrHeader).toBe(groupHeaderFirstHeader);\r
549 expect(colMgrHeader.hidden).toBe(true);\r
550 expect(colMgrHeader.text).toBe('Foo Price');\r
551 });\r
552 });\r
553 });\r
554\r
555 describe('visible only', function () {\r
556 describe('when argument is a column', function () {\r
557 it('should return the correct index for the header', function() {\r
558 expect(gvm().getHeaderIndex(headerCtItems.items[1])).toBe(0);\r
559 });\r
560\r
561 it("should return -1 if the column doesn't exist", function() {\r
562 column = new Ext.grid.column.Column();\r
563 \r
564 expect(gvm().getHeaderIndex(column)).toBe(-1);\r
565 });\r
566\r
567 it('should not return a hidden sub-header', function () {\r
568 var header;\r
569\r
570 header = headerCtItems.items[0];\r
571 index = gvm().getHeaderIndex(header);\r
572\r
573 expect(header.hidden).toBe(true);\r
574 expect(index).toBe(-1);\r
575 });\r
576\r
577 it('should return a valid index', function () {\r
578 index = gvm().getHeaderIndex(headerCtItems.items[1]);\r
579\r
580 expect(index).not.toBe(-1);\r
581 // Will filter out the first hidden column in the stack.\r
582 expect(index).toBe(0);\r
583 });\r
584\r
585 it('should return the index of the header in its owner stack - rootHeader', function () {\r
586 index = gvm().getHeaderIndex(headerCtItems.items[3].items.items[2]);\r
587\r
588 expect(index).toBe(4);\r
589 });\r
590\r
591 it('should return the index of the header in its owner stack - groupHeader', function () {\r
592 // Note that this spec is using the same header as the previous spec to demonstrate the difference.\r
593 var groupHeader = headerCtItems.items[3];\r
594\r
595 index = groupHeader.visibleColumnManager.getHeaderIndex(groupHeader.items.items[2]);\r
596\r
597 expect(index).toBe(1);\r
598 });\r
599 });\r
600\r
601 describe('when argument is a group header', function () {\r
602 it('should return a valid index', function () {\r
603 index = gvm().getHeaderIndex(headerCtItems.items[2]);\r
604\r
605 expect(index).not.toBe(-1);\r
606 // Will filter out the second hidden column in the stack.\r
607 expect(index).toBe(1);\r
608 });\r
609\r
610 it('should return an index of the first leaf of group header', function () {\r
611 var colMgrHeader;\r
612\r
613 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
614 index = gvm().getHeaderIndex(headerCtItems.items[2]);\r
615 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
616 colMgrHeader = gvm().getHeaderAtIndex(index);\r
617\r
618 // Remember, this is the index of the root header's visible col mgr.\r
619 expect(index).toBe(1);\r
620 expect(colMgrHeader.hidden).toBe(false);\r
621 expect(colMgrHeader.dataIndex).toBe('price');\r
622 });\r
623\r
624 it("should be a reference to the first leaf header in the grouped header's columnn manager", function () {\r
625 var groupedHeader, colMgrHeader, groupHeaderFirstHeader;\r
626\r
627 groupedHeader = headerCtItems.items[2];\r
628 groupHeaderFirstHeader = headerCtItems.items[2].visibleColumnManager.getHeaderAtIndex(0);\r
629\r
630 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
631 index = gvm().getHeaderIndex(groupedHeader);\r
632 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
633 colMgrHeader = gvm().getHeaderAtIndex(index);\r
634\r
635 expect(colMgrHeader).toBe(groupHeaderFirstHeader);\r
636 expect(colMgrHeader.hidden).toBe(groupHeaderFirstHeader.hidden);\r
637 expect(colMgrHeader.dataIndex).toBe(groupHeaderFirstHeader.dataIndex);\r
638 });\r
639\r
640 it('should not return a hidden sub-header', function () {\r
641 var groupedHeader, colMgrHeader, groupHeaderFirstHeader;\r
642\r
643 groupedHeader = headerCtItems.items[3];\r
644 groupHeaderFirstHeader = groupedHeader.visibleColumnManager.getHeaderAtIndex(0);\r
645\r
646 // First, get the index from the column mgr. It will retrieve it from the group header's column mgr.\r
647 index = gvm().getHeaderIndex(groupedHeader);\r
648 // Next, get a reference to the actual header (top-level col mgr will have a ref to all sub-level headers).\r
649 colMgrHeader = gvm().getHeaderAtIndex(index);\r
650\r
651 expect(colMgrHeader).toBe(groupHeaderFirstHeader);\r
652 expect(colMgrHeader.hidden).toBe(false);\r
653 expect(colMgrHeader.text).toBe('Foo Phone');\r
654 });\r
655 });\r
656 });\r
657 });\r
658\r
659 describe('getHeaderAtIndex', function () {\r
660 var header, headerCtItems;\r
661\r
662 beforeEach(function () {\r
663 makeGrid([{\r
664 text: 'Name',\r
665 width: 100,\r
666 dataIndex: 'name',\r
667 hidden: true\r
668 },{\r
669 text: 'Email',\r
670 width: 100,\r
671 dataIndex: 'email'\r
672 }, {\r
673 text: 'Stock Price',\r
674 columns: [{\r
675 text: 'Price',\r
676 width: 75,\r
677 dataIndex: 'price'\r
678 }, {\r
679 text: 'Phone',\r
680 width: 80,\r
681 dataIndex: 'phone',\r
682 hidden: true\r
683 }, {\r
684 text: '% Change',\r
685 width: 40,\r
686 dataIndex: 'pctChange'\r
687 }]\r
688 }, {\r
689 text: 'Foo',\r
690 columns: [{\r
691 text: 'Foo Price',\r
692 width: 75,\r
693 dataIndex: 'price',\r
694 hidden: true\r
695 }, {\r
696 text: 'Foo Phone',\r
697 width: 80,\r
698 dataIndex: 'phone'\r
699 }, {\r
700 text: 'Foo % Change',\r
701 width: 40,\r
702 dataIndex: 'pctChange'\r
703 }]\r
704 }]);\r
705\r
706 headerCtItems = grid.headerCt.items;\r
707 });\r
708\r
709 afterEach(function () {\r
710 header = headerCtItems = null;\r
711 });\r
712\r
713 describe('all columns', function () {\r
714 it('should return a valid header', function () {\r
715 header = gam().getHeaderAtIndex(0);\r
716\r
717 expect(header).not.toBe(null);\r
718 expect(header.dataIndex).toBe('name');\r
719 });\r
720\r
721 it('should return the correct header from the index', function() {\r
722 expect(gam().getHeaderAtIndex(0).dataIndex).toBe('name');\r
723 });\r
724\r
725 it("should return null if the column doesn't exist", function() {\r
726 expect(gam().getHeaderAtIndex(50)).toBe(null);\r
727 });\r
728\r
729 it('should return the header regardless of visibility', function () {\r
730 var header2;\r
731\r
732 header = gam().getHeaderAtIndex(0);\r
733 header2 = gam().getHeaderAtIndex(1);\r
734\r
735 expect(header).not.toBe(null);\r
736 expect(header.hidden).toBe(true);\r
737\r
738 expect(header2).not.toBe(null);\r
739 expect(header2.hidden).toBe(false);\r
740 });\r
741\r
742 it('should return the header in its owner stack - rootHeader', function () {\r
743 header = gam().getHeaderAtIndex(0);\r
744\r
745 expect(header.text).toBe('Name');\r
746 });\r
747\r
748 it('should return the index of the header in its owner stack - groupHeader', function () {\r
749 // Note that this spec is using the index as the previous spec to demonstrate the difference.\r
750 header = headerCtItems.items[3].columnManager.getHeaderAtIndex(0);\r
751\r
752 expect(header.text).toBe('Foo Price');\r
753 });\r
754 });\r
755\r
756 describe('visible only', function () {\r
757 it('should return the correct header from the index', function() {\r
758 expect(gvm().getHeaderAtIndex(0).dataIndex).toBe('email');\r
759 });\r
760\r
761 it("should return null if the column doesn't exist", function() {\r
762 expect(gvm().getHeaderAtIndex(50)).toBe(null);\r
763 });\r
764\r
765 it('should not return a hidden sub-header', function () {\r
766 header = gvm().getHeaderAtIndex(2);\r
767\r
768 expect(header.hidden).toBe(false);\r
769 expect(header.dataIndex).toBe('pctChange');\r
770 });\r
771\r
772 it('should return a valid header', function () {\r
773 header = gvm().getHeaderAtIndex(0);\r
774\r
775 expect(header).not.toBe(null);\r
776 expect(header.dataIndex).toBe('email');\r
777 });\r
778\r
779 it('should return the header in its owner stack - rootHeader', function () {\r
780 header = gvm().getHeaderAtIndex(0);\r
781 expect(header.text).toBe('Email');\r
782 });\r
783\r
784 it('should return the index of the header in its owner stack - groupHeader', function () {\r
785 // Note that this spec is using the same header as the previous spec to demonstrate the difference.\r
786 var groupHeader = headerCtItems.items[3];\r
787\r
788 header = headerCtItems.items[3].visibleColumnManager.getHeaderAtIndex(0);\r
789\r
790 expect(header.text).toBe('Foo Phone');\r
791 });\r
792 });\r
793 });\r
794\r
795 describe('hidden columns', function() {\r
796 // Hidden at index 3/6\r
797 beforeEach(function(){\r
798 makeGrid(8, null, function(i){\r
799 return i > 0 && i % 3 === 0;\r
800 });\r
801 });\r
802\r
803 it("should return all columns when using getColumnManager", function(){\r
804 expect(ga().length).toBe(8);\r
805 });\r
806\r
807 it("should return only visible columns when using getVisibleColumnManager", function(){\r
808 expect(gv().length).toBe(6);\r
809 });\r
810\r
811 it("should update the collection when hiding a column", function(){\r
812 colRef[0].hide();\r
813 expect(gv().length).toBe(5);\r
814 });\r
815\r
816 it("should update the collection when showing a column", function(){\r
817 colRef[3].show();\r
818 expect(gv().length).toBe(7);\r
819 });\r
820\r
821 describe("getHeaderAtIndex", function(){\r
822 it("should return the column reference", function(){\r
823 expect(gvm().getHeaderAtIndex(3)).toBe(colRef[4]);\r
824 });\r
825\r
826 it("should return null if the index is out of bounds", function(){\r
827 expect(gvm().getHeaderAtIndex(7)).toBeNull();\r
828 });\r
829 });\r
830\r
831 describe("getHeaderById", function(){\r
832 it("should return the column reference by id", function(){\r
833 expect(gvm().getHeaderById('col1')).toBe(colRef[1]);\r
834 });\r
835\r
836 it("should return null if the id doesn't exist", function() {\r
837 expect(gvm().getHeaderById('col3')).toBeNull();\r
838 });\r
839 });\r
840\r
841 it("should return the first item", function(){\r
842 expect(gvm().getFirst()).toBe(colRef[0]);\r
843 });\r
844\r
845 it("should return the last item", function(){\r
846 expect(gvm().getLast()).toBe(colRef[7]);\r
847 });\r
848\r
849 describe("getNextSibling", function(){\r
850 it("should return the next sibling", function(){\r
851 expect(gvm().getNextSibling(colRef[2])).toBe(colRef[4]);\r
852 });\r
853\r
854 it("should return the null if the next sibling doesn't exist", function(){\r
855 expect(gvm().getNextSibling(colRef[3])).toBeNull();\r
856 });\r
857 });\r
858\r
859 describe("getPreviousSibling", function(){\r
860 it("should return the previous sibling", function(){\r
861 expect(gvm().getPreviousSibling(colRef[7])).toBe(colRef[5]);\r
862 });\r
863\r
864 it("should return the null if the previous sibling doesn't exist", function(){\r
865 expect(gvm().getPreviousSibling(colRef[6])).toBeNull();\r
866 });\r
867 });\r
868 });\r
869\r
870\r
871 describe("locking", function(){\r
872 // first 4 locked\r
873 beforeEach(function(){\r
874 makeGrid(10, null, null, function(i){\r
875 return i <= 3;\r
876 });\r
877 });\r
878\r
879 describe("global manager", function() {\r
880 it("should return both sets of columns", function(){\r
881 expect(ga().length).toBe(10);\r
882 });\r
883\r
884 it("should update the collection when adding to the locked side", function(){\r
885 grid.lockedGrid.headerCt.add({\r
886 text: 'Foo'\r
887 });\r
888 expect(ga().length).toBe(11);\r
889 });\r
890\r
891 it("should update the collection when adding to the unlocked side", function(){\r
892 grid.normalGrid.headerCt.add({\r
893 text: 'Foo'\r
894 });\r
895 expect(ga().length).toBe(11);\r
896 });\r
897\r
898 it("should update the collection when removing from the locked side", function(){\r
899 grid.lockedGrid.headerCt.remove(0);\r
900 expect(ga().length).toBe(9);\r
901 });\r
902\r
903 it("should update the collection when removing from the unlocked side", function(){\r
904 grid.normalGrid.headerCt.remove(0);\r
905 expect(ga().length).toBe(9);\r
906 });\r
907\r
908 it("should maintain the same size when locking an item", function(){\r
909 grid.lock(colRef[4]);\r
910 expect(ga().length).toBe(10);\r
911 });\r
912\r
913 it("should maintain the same size when unlocking an item", function(){\r
914 grid.unlock(colRef[0]);\r
915 expect(ga().length).toBe(10);\r
916 });\r
917 });\r
918\r
919 describe("locked side", function(){\r
920 var glm = function(){\r
921 return grid.lockedGrid.getColumnManager();\r
922 };\r
923 it("should only return the columns for this side", function(){\r
924 expect(glm().getColumns().length).toBe(4);\r
925 });\r
926\r
927 it("should update the collection when adding an item to this side", function(){\r
928 grid.lock(colRef[9]);\r
929 expect(glm().getColumns().length).toBe(5);\r
930 });\r
931\r
932 it("should update the collection when removing an item from this side", function(){\r
933 grid.unlock(colRef[0]);\r
934 expect(glm().getColumns().length).toBe(3);\r
935 });\r
936\r
937 describe("function", function(){\r
938 describe("getHeaderIndex", function() {\r
939 it("should return the correct index for the header", function() {\r
940 expect(glm().getHeaderIndex(colRef[2])).toBe(2);\r
941 });\r
942\r
943 it("should return -1 if the column doesn't exist", function(){\r
944 expect(glm().getHeaderIndex(colRef[5])).toBe(-1);\r
945 });\r
946 });\r
947\r
948 describe("getHeaderAtIndex", function(){\r
949 it("should return the column reference", function(){\r
950 expect(glm().getHeaderAtIndex(3)).toBe(colRef[3]);\r
951 });\r
952\r
953 it("should return null if the index is out of bounds", function(){\r
954 expect(glm().getHeaderAtIndex(6)).toBeNull();\r
955 });\r
956 });\r
957\r
958 describe("getHeaderById", function(){\r
959 it("should return the column reference by id", function(){\r
960 expect(glm().getHeaderById('col1')).toBe(colRef[1]);\r
961 });\r
962\r
963 it("should return null if the id doesn't exist", function() {\r
964 expect(glm().getHeaderById('col5')).toBeNull();\r
965 });\r
966 });\r
967 });\r
968 });\r
969\r
970 describe("unlocked side", function(){\r
971 var gum = function(){\r
972 return grid.normalGrid.getColumnManager();\r
973 };\r
974 it("should only return the columns for this side", function(){\r
975 expect(gum().getColumns().length).toBe(6);\r
976 });\r
977\r
978 it("should update the collection when adding an item to this side", function(){\r
979 grid.unlock(colRef[1]);\r
980 expect(gum().getColumns().length).toBe(7);\r
981 });\r
982\r
983 it("should update the collection when removing an item from this side", function(){\r
984 grid.lock(colRef[7]);\r
985 expect(gum().getColumns().length).toBe(5);\r
986 });\r
987\r
988 describe("function", function(){\r
989 var offset = 4;\r
990 describe("getHeaderIndex", function() {\r
991 it("should return the correct index for the header", function() {\r
992 expect(gum().getHeaderIndex(colRef[offset + 2])).toBe(2);\r
993 });\r
994\r
995 it("should return -1 if the column doesn't exist", function(){\r
996 expect(gum().getHeaderIndex(colRef[0])).toBe(-1);\r
997 });\r
998 });\r
999\r
1000 describe("getHeaderAtIndex", function(){\r
1001 it("should return the column reference", function(){\r
1002 expect(gum().getHeaderAtIndex(3)).toBe(colRef[3 + offset]);\r
1003 });\r
1004\r
1005 it("should return null if the index is out of bounds", function(){\r
1006 expect(gum().getHeaderAtIndex(6)).toBeNull();\r
1007 });\r
1008 });\r
1009\r
1010 describe("getHeaderById", function(){\r
1011 it("should return the column reference by id", function(){\r
1012 expect(gum().getHeaderById('col6')).toBe(colRef[6]);\r
1013 });\r
1014\r
1015 it("should return null if the id doesn't exist", function() {\r
1016 expect(gum().getHeaderById('col2')).toBeNull();\r
1017 });\r
1018 });\r
1019 });\r
1020 });\r
1021 });\r
1022 });\r
1023\r
1024 describe("sorting", function() {\r
1025 it("should sort by dataIndex when clicking on the header with sortable: true", function() {\r
1026 makeGrid([{\r
1027 dataIndex: 'field0',\r
1028 sortable: true\r
1029 }]);\r
1030 clickHeader(colRef[0]);\r
1031 var sorters = store.getSorters();\r
1032 expect(sorters.getCount()).toBe(1);\r
1033 expect(sorters.first().getProperty()).toBe('field0');\r
1034 expect(sorters.first().getDirection()).toBe('ASC');\r
1035 });\r
1036\r
1037 it("should invert the sort order when clicking on a sorted column", function() {\r
1038 makeGrid([{\r
1039 dataIndex: 'field0',\r
1040 sortable: true\r
1041 }]);\r
1042 clickHeader(colRef[0]);\r
1043 var sorters = store.getSorters();\r
1044 clickHeader(colRef[0]);\r
1045 expect(sorters.getCount()).toBe(1);\r
1046 expect(sorters.first().getProperty()).toBe('field0');\r
1047 expect(sorters.first().getDirection()).toBe('DESC');\r
1048 clickHeader(colRef[0]);\r
1049 expect(sorters.getCount()).toBe(1);\r
1050 expect(sorters.first().getProperty()).toBe('field0');\r
1051 expect(sorters.first().getDirection()).toBe('ASC');\r
1052 });\r
1053\r
1054 it("should not sort when configured with sortable false", function() {\r
1055 makeGrid([{\r
1056 dataIndex: 'field0',\r
1057 sortable: false\r
1058 }]);\r
1059 clickHeader(colRef[0]);\r
1060 expect(store.getSorters().getCount()).toBe(0);\r
1061 });\r
1062\r
1063 it("should not sort when the grid is configured with sortableColumns: false", function() {\r
1064 makeGrid([{\r
1065 dataIndex: 'field0'\r
1066 }], {\r
1067 sortableColumns: false\r
1068 });\r
1069 clickHeader(colRef[0]);\r
1070 expect(store.getSorters().getCount()).toBe(0);\r
1071 });\r
1072 });\r
1073\r
1074 describe("grouped columns", function() {\r
1075 var baseCols;\r
1076\r
1077 function createGrid(cols, stateful) {\r
1078 if (grid) {\r
1079 grid.destroy();\r
1080 grid = null;\r
1081 }\r
1082 \r
1083 makeGrid(cols, {\r
1084 renderTo: null,\r
1085 stateful: stateful,\r
1086 stateId: 'foo'\r
1087 });\r
1088 }\r
1089\r
1090 function getCol(id) {\r
1091 return grid.down('#' + id);\r
1092 }\r
1093\r
1094 describe('when stateful', function () {\r
1095 var col;\r
1096\r
1097 beforeEach(function () {\r
1098 new Ext.state.Provider();\r
1099\r
1100 makeGrid([{\r
1101 itemId: 'main1',\r
1102 columns: [{\r
1103 itemId: 'child1'\r
1104 }, {\r
1105 itemId: 'child2'\r
1106 }, {\r
1107 itemId: 'child3'\r
1108 }]\r
1109 }, {\r
1110 itemId: 'main2',\r
1111 columns: [{\r
1112 itemId: 'child4'\r
1113 }, {\r
1114 itemId: 'child5'\r
1115 }, {\r
1116 itemId: 'child6'\r
1117 }]\r
1118 }], {\r
1119 stateful: true,\r
1120 stateId: 'foo'\r
1121 });\r
1122 });\r
1123\r
1124 afterEach(function () {\r
1125 Ext.state.Manager.getProvider().clear();\r
1126 col = null;\r
1127 });\r
1128\r
1129 it('should work when toggling visibility on the groups', function () {\r
1130 // See EXTJS-11661.\r
1131 col = grid.down('#main2');\r
1132 col.hide();\r
1133 // Trigger the bug.\r
1134 grid.saveState();\r
1135 col.show();\r
1136\r
1137 // Now, select one of the col's children and query its hidden state.\r
1138 // Really, we can check anything here, b/c if the bug wasn't fixed then\r
1139 // a TypeError would be thrown in Ext.view.TableLayout#setColumnWidths.\r
1140 expect(grid.down('#child6').hidden).toBe(false);\r
1141 });\r
1142\r
1143 it('should not show a previously hidden subheader when the visibility of its group header is toggled', function () {\r
1144 var subheader = grid.down('#child4');\r
1145\r
1146 subheader.hide();\r
1147 col = grid.down('#main2');\r
1148 col.hide();\r
1149 col.show();\r
1150\r
1151 expect(subheader.hidden).toBe(true);\r
1152 });\r
1153 });\r
1154\r
1155 describe("column visibility", function() {\r
1156 var cells;\r
1157\r
1158 afterEach(function () {\r
1159 cells = null;\r
1160 });\r
1161\r
1162 describe("hiding/show during construction", function() {\r
1163 it("should be able to show a column during construction", function() {\r
1164 expect(function() {\r
1165 makeGrid([{\r
1166 dataIndex: 'field1',\r
1167 hidden: true,\r
1168 listeners: {\r
1169 added: function(c) {\r
1170 c.show();\r
1171 }\r
1172 }\r
1173 }]);\r
1174 }).not.toThrow();\r
1175 expect(grid.getVisibleColumnManager().getColumns()[0]).toBe(colRef[0]);\r
1176 });\r
1177\r
1178 it("should be able to hide a column during construction", function() {\r
1179 expect(function() {\r
1180 makeGrid([{\r
1181 dataIndex: 'field1',\r
1182 listeners: {\r
1183 added: function(c) {\r
1184 c.hide();\r
1185 }\r
1186 }\r
1187 }]);\r
1188 }).not.toThrow();\r
1189 expect(grid.getVisibleColumnManager().getColumns().length).toBe(0);\r
1190 });\r
1191 });\r
1192\r
1193 describe('when groupheader parent is hidden', function () {\r
1194 describe('hidden at config time', function () {\r
1195 beforeEach(function () {\r
1196 makeGrid([{\r
1197 itemId: 'main1'\r
1198 }, {\r
1199 itemId: 'main2',\r
1200 hidden: true,\r
1201 columns: [{\r
1202 itemId: 'child1'\r
1203 }, {\r
1204 itemId: 'child2'\r
1205 }]\r
1206 }]);\r
1207\r
1208 cells = grid.view.body.query('.x-grid-row td');\r
1209 });\r
1210\r
1211 it('should hide child columns at config time if the parent is hidden', function () {\r
1212 expect(grid.down('#child1').getInherited().hidden).toBe(true);\r
1213 expect(grid.down('#child2').getInherited().hidden).toBe(true);\r
1214 // Check the view.\r
1215 expect(cells.length).toBe(1);\r
1216 });\r
1217\r
1218 it('should not explicitly hide any child columns (they will be hierarchically hidden)', function () {\r
1219 expect(grid.down('#child1').hidden).toBe(false);\r
1220 expect(grid.down('#child2').hidden).toBe(false);\r
1221 // Check the view.\r
1222 expect(cells.length).toBe(1);\r
1223 });\r
1224 });\r
1225\r
1226 describe('hidden at run time', function () {\r
1227 beforeEach(function () {\r
1228 makeGrid([{\r
1229 itemId: 'main1'\r
1230 }, {\r
1231 itemId: 'main2',\r
1232 columns: [{\r
1233 itemId: 'child1'\r
1234 }, {\r
1235 itemId: 'child2'\r
1236 }]\r
1237 }]);\r
1238\r
1239 grid.down('#main2').hide();\r
1240 cells = grid.view.body.query('.x-grid-row td');\r
1241 });\r
1242\r
1243 it('should hide child columns at runtime if the parent is hidden', function () {\r
1244 expect(grid.down('#child1').getInherited().hidden).toBe(true);\r
1245 expect(grid.down('#child2').getInherited().hidden).toBe(true);\r
1246 // Check the view.\r
1247 expect(cells.length).toBe(1);\r
1248 });\r
1249\r
1250 it('should not explicitly hide any child columns (they will be hierarchically hidden)', function () {\r
1251 expect(grid.down('#child1').hidden).toBe(false);\r
1252 expect(grid.down('#child2').hidden).toBe(false);\r
1253 // Check the view.\r
1254 expect(cells.length).toBe(1);\r
1255 });\r
1256 });\r
1257 });\r
1258\r
1259 describe('when groupheader parent is shown', function () {\r
1260 describe('shown at config time', function () {\r
1261 beforeEach(function () {\r
1262 makeGrid([{\r
1263 itemId: 'main1'\r
1264 }, {\r
1265 itemId: 'main2',\r
1266 columns: [{\r
1267 itemId: 'child1'\r
1268 }, {\r
1269 itemId: 'child2'\r
1270 }]\r
1271 }]);\r
1272\r
1273 cells = grid.view.body.query('.x-grid-row td');\r
1274 });\r
1275\r
1276 it('should not hide child columns at config time if the parent is shown', function () {\r
1277 expect(grid.down('#child1').getInherited().hidden).not.toBeDefined();\r
1278 expect(grid.down('#child2').getInherited().hidden).not.toBeDefined();\r
1279 // Check the view.\r
1280 expect(cells.length).toBe(3);\r
1281 });\r
1282\r
1283 it('should not explicitly hide any child columns (they will be hierarchically shown)', function () {\r
1284 expect(grid.down('#child1').hidden).toBe(false);\r
1285 expect(grid.down('#child2').hidden).toBe(false);\r
1286 // Check the view.\r
1287 expect(cells.length).toBe(3);\r
1288 });\r
1289 });\r
1290\r
1291 describe('shown at run time', function () {\r
1292 beforeEach(function () {\r
1293 makeGrid([{\r
1294 itemId: 'main1'\r
1295 }, {\r
1296 itemId: 'main2',\r
1297 hidden: true,\r
1298 columns: [{\r
1299 itemId: 'child1'\r
1300 }, {\r
1301 itemId: 'child2'\r
1302 }]\r
1303 }]);\r
1304\r
1305 grid.down('#main2').show();\r
1306 cells = grid.view.body.query('.x-grid-row td');\r
1307 });\r
1308\r
1309 it('should show child columns at runtime if the parent is shown', function () {\r
1310 expect(grid.down('#child1').getInherited().hidden).not.toBeDefined();\r
1311 expect(grid.down('#child2').getInherited().hidden).not.toBeDefined();\r
1312 // Check the view.\r
1313 expect(cells.length).toBe(3);\r
1314 });\r
1315\r
1316 it('should not explicitly hide any child columns (they will be hierarchically shown)', function () {\r
1317 expect(grid.down('#child1').hidden).toBe(false);\r
1318 expect(grid.down('#child2').hidden).toBe(false);\r
1319 // Check the view.\r
1320 expect(cells.length).toBe(3);\r
1321 });\r
1322 });\r
1323 });\r
1324\r
1325 describe("hiding/showing children", function() {\r
1326 beforeEach(function() {\r
1327 baseCols = [{\r
1328 itemId: 'col1',\r
1329 columns: [{\r
1330 itemId: 'col11'\r
1331 }, {\r
1332 itemId: 'col12'\r
1333 }, {\r
1334 itemId: 'col13'\r
1335 }]\r
1336 }, {\r
1337 itemId: 'col2',\r
1338 columns: [{\r
1339 itemId: 'col21'\r
1340 }, {\r
1341 itemId: 'col22'\r
1342 }, {\r
1343 itemId: 'col23'\r
1344 }]\r
1345 }];\r
1346 });\r
1347\r
1348 it('should not show a previously hidden subheader when the visibility of its group header is toggled', function () {\r
1349 var subheader, col;\r
1350\r
1351 makeGrid([{\r
1352 itemId: 'main1'\r
1353 }, {\r
1354 itemId: 'main2',\r
1355 columns: [{\r
1356 itemId: 'child1'\r
1357 }, {\r
1358 itemId: 'child2'\r
1359 }]\r
1360 }]);\r
1361\r
1362 subheader = grid.down('#child1');\r
1363\r
1364 subheader.hide();\r
1365 col = grid.down('#main2');\r
1366 col.hide();\r
1367 col.show();\r
1368\r
1369 expect(subheader.hidden).toBe(true);\r
1370 });\r
1371\r
1372 it('should allow any subheader to be reshown when all subheaders are currently hidden', function () {\r
1373 // There was a bug where a subheader could not be reshown when itself and all of its fellows were curently hidden.\r
1374 // See EXTJS-18515.\r
1375 var subheader;\r
1376\r
1377 makeGrid([{\r
1378 itemId: 'main1'\r
1379 }, {\r
1380 itemId: 'main2',\r
1381 columns: [{\r
1382 itemId: 'child1'\r
1383 }, {\r
1384 itemId: 'child2'\r
1385 }, {\r
1386 itemId: 'child3'\r
1387 }]\r
1388 }]);\r
1389\r
1390 grid.down('#child1').hide();\r
1391 grid.down('#child2').hide();\r
1392 subheader = grid.down('#child3');\r
1393\r
1394 // Toggling would reveal the bug.\r
1395 subheader.hide();\r
1396 expect(subheader.hidden).toBe(true);\r
1397 subheader.show();\r
1398\r
1399 expect(subheader.hidden).toBe(false);\r
1400 });\r
1401\r
1402 it('should show the last hidden subheader if all subheaders are currently hidden when the group is reshown', function () {\r
1403 var groupheader, subheader1, subheader2, subheader3;\r
1404\r
1405 makeGrid([{\r
1406 itemId: 'main1'\r
1407 }, {\r
1408 itemId: 'main2',\r
1409 columns: [{\r
1410 itemId: 'child1'\r
1411 }, {\r
1412 itemId: 'child2'\r
1413 }, {\r
1414 itemId: 'child3'\r
1415 }]\r
1416 }]);\r
1417\r
1418 groupheader = grid.down('#main2');\r
1419 subheader1 = grid.down('#child1').hide();\r
1420 subheader3 = grid.down('#child3').hide();\r
1421 subheader2 = grid.down('#child2')\r
1422 subheader2.hide();\r
1423\r
1424 expect(subheader2.hidden).toBe(true);\r
1425\r
1426 groupheader.show();\r
1427\r
1428 // The last hidden subheader should now be shown.\r
1429 expect(subheader2.hidden).toBe(false);\r
1430\r
1431 // Let's also demonstrate that the others are still hidden.\r
1432 expect(subheader1.hidden).toBe(true);\r
1433 expect(subheader3.hidden).toBe(true);\r
1434 });\r
1435\r
1436 describe("initial configuration", function() {\r
1437 it("should not hide the parent by default", function() {\r
1438 createGrid(baseCols);\r
1439 expect(getCol('col1').hidden).toBe(false);\r
1440 });\r
1441\r
1442 it("should not hide the parent if not all children are hidden", function() {\r
1443 baseCols[1].columns[2].hidden = baseCols[1].columns[0].hidden = true;\r
1444 createGrid(baseCols);\r
1445 expect(getCol('col2').hidden).toBe(false);\r
1446 });\r
1447\r
1448 it("should hide the parent if all children are hidden", function() {\r
1449 baseCols[1].columns[2].hidden = baseCols[1].columns[1].hidden = baseCols[1].columns[0].hidden = true;\r
1450 createGrid(baseCols);\r
1451 expect(getCol('col2').hidden).toBe(true);\r
1452 });\r
1453 });\r
1454\r
1455 describe("before render", function() {\r
1456 it("should hide the parent when hiding all children", function() {\r
1457 createGrid(baseCols);\r
1458 getCol('col21').hide();\r
1459 getCol('col22').hide();\r
1460 getCol('col23').hide();\r
1461 grid.render(Ext.getBody());\r
1462 expect(getCol('col2').hidden).toBe(true);\r
1463 });\r
1464\r
1465 it("should show the parent when showing a hidden child", function() {\r
1466 baseCols[1].columns[2].hidden = baseCols[1].columns[1].hidden = baseCols[1].columns[0].hidden = true;\r
1467 createGrid(baseCols);\r
1468 getCol('col22').show();\r
1469 grid.render(Ext.getBody());\r
1470 expect(getCol('col2').hidden).toBe(false);\r
1471 });\r
1472 });\r
1473\r
1474 describe("after render", function() {\r
1475 it("should hide the parent when hiding all children", function() {\r
1476 createGrid(baseCols);\r
1477 grid.render(Ext.getBody());\r
1478 getCol('col21').hide();\r
1479 getCol('col22').hide();\r
1480 getCol('col23').hide();\r
1481 expect(getCol('col2').hidden).toBe(true);\r
1482 });\r
1483\r
1484 it("should show the parent when showing a hidden child", function() {\r
1485 baseCols[1].columns[2].hidden = baseCols[1].columns[1].hidden = baseCols[1].columns[0].hidden = true;\r
1486 createGrid(baseCols);\r
1487 grid.render(Ext.getBody());\r
1488 getCol('col22').show();\r
1489 expect(getCol('col2').hidden).toBe(false);\r
1490 });\r
1491\r
1492 it("should only trigger a single layout when hiding the last leaf in a group", function() {\r
1493 baseCols[0].columns.splice(1, 2);\r
1494 createGrid(baseCols);\r
1495 grid.render(Ext.getBody());\r
1496 var count = grid.componentLayoutCounter;\r
1497 getCol('col11').hide();\r
1498 expect(grid.componentLayoutCounter).toBe(count + 1);\r
1499 });\r
1500\r
1501 it("should only trigger a single refresh when hiding the last leaf in a group", function() {\r
1502 baseCols[0].columns.splice(1, 2);\r
1503 createGrid(baseCols);\r
1504 grid.render(Ext.getBody());\r
1505 var view = grid.getView(),\r
1506 count = view.refreshCounter;\r
1507\r
1508 getCol('col11').hide();\r
1509 expect(view.refreshCounter).toBe(count + 1);\r
1510 });\r
1511 });\r
1512\r
1513 describe('nested stacked columns', function () {\r
1514 // Test stacked group headers where the only child is the next group header in the hierarchy.\r
1515 // The last (lowest in the stack) group header will contain multiple child items.\r
1516 // For example:\r
1517 //\r
1518 // +-----------------------------------+\r
1519 // | col1 |\r
1520 // |-----------------------------------|\r
1521 // | col2 |\r
1522 // other |-----------------------------------| other\r
1523 // headers | col3 | headers\r
1524 // |-----------------------------------|\r
1525 // | col4 |\r
1526 // |-----------------------------------|\r
1527 // | Field1 | Field2 | Field3 | Field4 |\r
1528 // |===================================|\r
1529 // | view |\r
1530 // +-----------------------------------+\r
1531 //\r
1532 function assertHiddenState(n, hiddenState) {\r
1533 while (n) {\r
1534 expect(getCol('col' + n).hidden).toBe(hiddenState);\r
1535 --n;\r
1536 }\r
1537 }\r
1538\r
1539 describe('on hide', function () {\r
1540 beforeEach(function() {\r
1541 baseCols = [{\r
1542 itemId: 'col1',\r
1543 columns: [{\r
1544 itemId: 'col2',\r
1545 columns: [{\r
1546 itemId: 'col3',\r
1547 columns: [{\r
1548 itemId: 'col4',\r
1549 columns: [{\r
1550 itemId: 'col41'\r
1551 }, {\r
1552 itemId: 'col42'\r
1553 }, {\r
1554 itemId: 'col43'\r
1555 }, {\r
1556 itemId: 'col44'\r
1557 }]\r
1558 }]\r
1559 }]\r
1560 }]\r
1561 }, {\r
1562 itemId: 'col5'\r
1563 }]\r
1564 });\r
1565\r
1566 it('should hide every group header above the target group header', function () {\r
1567 createGrid(baseCols);\r
1568 getCol('col4').hide();\r
1569 assertHiddenState(4, true);\r
1570 tearDown();\r
1571\r
1572 setup();\r
1573 createGrid(baseCols);\r
1574 getCol('col3').hide();\r
1575 assertHiddenState(3, true);\r
1576 tearDown();\r
1577\r
1578 setup();\r
1579 createGrid(baseCols);\r
1580 getCol('col2').hide();\r
1581 assertHiddenState(2, true);\r
1582 });\r
1583\r
1584 it('should reshow every group header above the target group header when toggled', function () {\r
1585 createGrid(baseCols);\r
1586 getCol('col4').hide();\r
1587 assertHiddenState(4, true);\r
1588 getCol('col4').show();\r
1589 assertHiddenState(4, false);\r
1590 tearDown();\r
1591\r
1592 setup();\r
1593 createGrid(baseCols);\r
1594 getCol('col3').hide();\r
1595 assertHiddenState(3, true);\r
1596 getCol('col3').show();\r
1597 assertHiddenState(3, false);\r
1598 tearDown();\r
1599\r
1600 setup();\r
1601 createGrid(baseCols);\r
1602 getCol('col2').hide();\r
1603 assertHiddenState(2, true);\r
1604 getCol('col2').show();\r
1605 assertHiddenState(2, false);\r
1606 });\r
1607\r
1608 describe('subheaders', function () {\r
1609 it('should hide all ancestor group headers when hiding all subheaders in lowest group header', function () {\r
1610 createGrid(baseCols);\r
1611 getCol('col41').hide();\r
1612 getCol('col42').hide();\r
1613 getCol('col43').hide();\r
1614 getCol('col44').hide();\r
1615 assertHiddenState(4, true);\r
1616 });\r
1617 });\r
1618 });\r
1619\r
1620 describe('on show', function () {\r
1621 beforeEach(function() {\r
1622 baseCols = [{\r
1623 itemId: 'col1',\r
1624 hidden: true,\r
1625 columns: [{\r
1626 itemId: 'col2',\r
1627 hidden: true,\r
1628 columns: [{\r
1629 itemId: 'col3',\r
1630 hidden: true,\r
1631 columns: [{\r
1632 itemId: 'col4',\r
1633 hidden: true,\r
1634 columns: [{\r
1635 itemId: 'col41'\r
1636 }, {\r
1637 itemId: 'col42'\r
1638 }, {\r
1639 itemId: 'col43'\r
1640 }, {\r
1641 itemId: 'col44'\r
1642 }]\r
1643 }]\r
1644 }]\r
1645 }]\r
1646 }, {\r
1647 itemId: 'col5'\r
1648 }]\r
1649 });\r
1650\r
1651 it('should show every group header above the target group header', function () {\r
1652 // Here we're showing that a header that is explicitly shown will have every header\r
1653 // above it shown as well.\r
1654 createGrid(baseCols);\r
1655 getCol('col4').show();\r
1656 assertHiddenState(4, false);\r
1657\r
1658 tearDown();\r
1659 setup();\r
1660 createGrid(baseCols);\r
1661 getCol('col3').show();\r
1662 assertHiddenState(3, false);\r
1663\r
1664 tearDown();\r
1665 setup();\r
1666 createGrid(baseCols);\r
1667 getCol('col2').show();\r
1668 assertHiddenState(2, false);\r
1669 });\r
1670\r
1671 it('should show every group header in the chain no matter which group header is checked', function () {\r
1672 // Here we're showing that a header that is explicitly shown will have every header\r
1673 // in the chain shown, no matter which group header was clicked.\r
1674 //\r
1675 // Group headers are special in that they are auto-hidden when their subheaders are all\r
1676 // hidden and auto-shown when the first subheader is reshown. They are the only headers\r
1677 // that should now be auto-shown or -hidden.\r
1678 //\r
1679 // It follows that since group headers are dictated by some automation depending upon the\r
1680 // state of their child items that all group headers should be shown if anyone in the\r
1681 // hierarchy is shown since these special group headers only contain one child, which is\r
1682 // the next group header in the stack.\r
1683 createGrid(baseCols);\r
1684 getCol('col4').show();\r
1685 assertHiddenState(4, false);\r
1686\r
1687 tearDown();\r
1688 setup();\r
1689 createGrid(baseCols);\r
1690 getCol('col3').show();\r
1691 assertHiddenState(4, false);\r
1692\r
1693 tearDown();\r
1694 setup();\r
1695 createGrid(baseCols);\r
1696 getCol('col2').show();\r
1697 assertHiddenState(4, false);\r
1698\r
1699 tearDown();\r
1700 setup();\r
1701 createGrid(baseCols);\r
1702 getCol('col1').show();\r
1703 assertHiddenState(4, false);\r
1704 });\r
1705\r
1706 it('should rehide every group header above the target group header when toggled', function () {\r
1707 createGrid(baseCols);\r
1708 getCol('col4').show();\r
1709 assertHiddenState(4, false);\r
1710 getCol('col4').hide();\r
1711 assertHiddenState(4, true);\r
1712\r
1713 tearDown();\r
1714 setup();\r
1715 createGrid(baseCols);\r
1716 getCol('col3').show();\r
1717 assertHiddenState(3, false);\r
1718 getCol('col3').hide();\r
1719 assertHiddenState(3, true);\r
1720\r
1721 tearDown();\r
1722 setup();\r
1723 createGrid(baseCols);\r
1724 getCol('col2').show();\r
1725 assertHiddenState(2, false);\r
1726 getCol('col2').hide();\r
1727 assertHiddenState(2, true);\r
1728 });\r
1729\r
1730 describe('subheaders', function () {\r
1731 it('should not show any ancestor group headers when hiding all subheaders in lowest group header', function () {\r
1732 createGrid(baseCols);\r
1733 getCol('col41').hide();\r
1734 getCol('col42').hide();\r
1735 getCol('col43').hide();\r
1736 getCol('col44').hide();\r
1737 assertHiddenState(4, true);\r
1738 });\r
1739\r
1740 it('should show all ancestor group headers when hiding all subheaders in lowest group header and then showing one', function () {\r
1741 createGrid(baseCols);\r
1742 getCol('col41').hide();\r
1743 getCol('col42').hide();\r
1744 getCol('col43').hide();\r
1745 getCol('col44').hide();\r
1746 assertHiddenState(4, true);\r
1747 getCol('col42').show();\r
1748 assertHiddenState(4, false);\r
1749 });\r
1750\r
1751 it('should remember which subheader was last checked and restore its state when its group header is rechecked', function () {\r
1752 var col, subheader, headerCt;\r
1753\r
1754 // Let's hide the 3rd menu item.\r
1755 makeGrid(baseCols);\r
1756 col = getCol('col4');\r
1757 subheader = getCol('col43');\r
1758 headerCt = grid.headerCt;\r
1759\r
1760 getCol('col41').hide();\r
1761 getCol('col42').hide();\r
1762 getCol('col44').hide();\r
1763 subheader.hide();\r
1764\r
1765 expect(col.hidden).toBe(true);\r
1766 // Get the menu item.\r
1767 headerCt.getMenuItemForHeader(headerCt.menu, col).setChecked(true);\r
1768 expect(subheader.hidden).toBe(false);\r
1769\r
1770 // Now let's hide the 2nd menu item.\r
1771 tearDown();\r
1772 setup();\r
1773 makeGrid(baseCols);\r
1774 col = getCol('col4');\r
1775 subheader = getCol('col42');\r
1776 headerCt = grid.headerCt;\r
1777\r
1778 getCol('col41').hide();\r
1779 getCol('col43').hide();\r
1780 getCol('col44').hide();\r
1781 subheader.hide();\r
1782\r
1783 expect(col.hidden).toBe(true);\r
1784 // Get the menu item.\r
1785 headerCt.getMenuItemForHeader(headerCt.menu, col).setChecked(true);\r
1786 expect(subheader.hidden).toBe(false);\r
1787 });\r
1788\r
1789 it('should only show visible subheaders when all group headers are shown', function () {\r
1790 var col;\r
1791\r
1792 createGrid(baseCols);\r
1793 col = getCol('col4');\r
1794\r
1795 // All subheaders are visible.\r
1796 col.show();\r
1797 expect(col.visibleColumnManager.getColumns().length).toBe(4);\r
1798\r
1799 // Hide the group header and hide two subheaders.\r
1800 col.hide();\r
1801 getCol('col42').hide();\r
1802 getCol('col43').hide();\r
1803\r
1804 // Only two subheaders should now be visible.\r
1805 col.show();\r
1806 expect(col.visibleColumnManager.getColumns().length).toBe(2);\r
1807 });\r
1808 });\r
1809 });\r
1810 });\r
1811 });\r
1812\r
1813 describe("adding/removing children", function() {\r
1814 beforeEach(function() {\r
1815 baseCols = [{\r
1816 itemId: 'col1',\r
1817 columns: [{\r
1818 itemId: 'col11'\r
1819 }, {\r
1820 itemId: 'col12'\r
1821 }, {\r
1822 itemId: 'col13'\r
1823 }]\r
1824 }, {\r
1825 itemId: 'col2',\r
1826 columns: [{\r
1827 itemId: 'col21'\r
1828 }, {\r
1829 itemId: 'col22'\r
1830 }, {\r
1831 itemId: 'col23'\r
1832 }]\r
1833 }];\r
1834 });\r
1835\r
1836 describe("before render", function() {\r
1837 it("should hide the parent if removing the last hidden item", function() {\r
1838 baseCols[0].columns[0].hidden = baseCols[0].columns[1].hidden = true;\r
1839 createGrid(baseCols);\r
1840 getCol('col13').destroy();\r
1841 grid.render(Ext.getBody());\r
1842 expect(getCol('col1').hidden).toBe(true);\r
1843 });\r
1844\r
1845 it("should show the parent if adding a visible item and all items are hidden", function() {\r
1846 baseCols[0].columns[0].hidden = baseCols[0].columns[1].hidden = baseCols[0].columns[2].hidden = true;\r
1847 createGrid(baseCols);\r
1848 getCol('col1').add({\r
1849 itemId: 'col14'\r
1850 });\r
1851 grid.render(Ext.getBody());\r
1852 expect(getCol('col1').hidden).toBe(false);\r
1853 });\r
1854 });\r
1855\r
1856 describe("after render", function() {\r
1857 it("should hide the parent if removing the last hidden item", function() {\r
1858 baseCols[0].columns[0].hidden = baseCols[0].columns[1].hidden = true;\r
1859 createGrid(baseCols);\r
1860 grid.render(Ext.getBody());\r
1861 getCol('col13').destroy();\r
1862 expect(getCol('col1').hidden).toBe(true);\r
1863 });\r
1864\r
1865 it("should show the parent if adding a visible item and all items are hidden", function() {\r
1866 baseCols[0].columns[0].hidden = baseCols[0].columns[1].hidden = baseCols[0].columns[2].hidden = true;\r
1867 createGrid(baseCols);\r
1868 grid.render(Ext.getBody());\r
1869 getCol('col1').add({\r
1870 itemId: 'col14'\r
1871 });\r
1872 expect(getCol('col1').hidden).toBe(false);\r
1873 });\r
1874 });\r
1875 });\r
1876 });\r
1877\r
1878 describe("removing columns from group", function() {\r
1879 beforeEach(function() {\r
1880 baseCols = [{\r
1881 itemId: 'col1',\r
1882 columns: [{\r
1883 itemId: 'col11'\r
1884 }, {\r
1885 itemId: 'col12'\r
1886 }, {\r
1887 itemId: 'col13'\r
1888 }]\r
1889 }, {\r
1890 itemId: 'col2',\r
1891 columns: [{\r
1892 itemId: 'col21'\r
1893 }, {\r
1894 itemId: 'col22'\r
1895 }, {\r
1896 itemId: 'col23'\r
1897 }]\r
1898 }];\r
1899 \r
1900 createGrid(baseCols);\r
1901 });\r
1902 \r
1903 describe("before render", function() {\r
1904 it("should destroy the group header when removing all columns", function() {\r
1905 var headerCt = grid.headerCt,\r
1906 col2 = getCol('col2');\r
1907\r
1908 expect(headerCt.items.indexOf(col2)).toBe(1);\r
1909 getCol('col21').destroy();\r
1910 getCol('col22').destroy();\r
1911 getCol('col23').destroy();\r
1912 expect(col2.destroyed).toBe(true);\r
1913 expect(headerCt.items.indexOf(col2)).toBe(-1);\r
1914 });\r
1915 });\r
1916\r
1917 describe("after render", function() {\r
1918 it("should destroy the group header when removing all columns", function() {\r
1919 createGrid(baseCols);\r
1920 grid.render(Ext.getBody());\r
1921\r
1922 var headerCt = grid.headerCt,\r
1923 col2 = getCol('col2');\r
1924\r
1925 expect(headerCt.items.indexOf(col2)).toBe(1);\r
1926 getCol('col21').destroy();\r
1927 getCol('col22').destroy();\r
1928 getCol('col23').destroy();\r
1929 expect(col2.destroyed).toBe(true);\r
1930 expect(headerCt.items.indexOf(col2)).toBe(-1);\r
1931 });\r
1932 });\r
1933 });\r
1934 });\r
1935\r
1936 describe("column operations & the view", function() {\r
1937 describe('', function () {\r
1938 beforeEach(function() {\r
1939 makeGrid();\r
1940 });\r
1941\r
1942 it("should update the view when adding a new header", function() {\r
1943 grid.headerCt.insert(0, {\r
1944 dataIndex: 'field4'\r
1945 });\r
1946 expect(getCellText(0, 0)).toBe('val5');\r
1947 });\r
1948\r
1949 it("should update the view when moving an existing header", function() {\r
1950 grid.headerCt.insert(0, colRef[1]);\r
1951 expect(getCellText(0, 0)).toBe('val2');\r
1952 });\r
1953\r
1954 it("should update the view when removing a header", function() {\r
1955 grid.headerCt.remove(1);\r
1956 expect(getCellText(0, 1)).toBe('val3');\r
1957 });\r
1958\r
1959 it("should not refresh the view when doing a drag/drop move", function() {\r
1960 var called = false,\r
1961 header;\r
1962\r
1963 grid.getView().on('refresh', function() {\r
1964 called = true;\r
1965 });\r
1966\r
1967 // Simulate a DD here\r
1968 header = colRef[0];\r
1969 grid.headerCt.move(0, 3);\r
1970 expect(getCellText(0, 3)).toBe('val1');\r
1971 expect(called).toBe(false);\r
1972 });\r
1973 });\r
1974\r
1975 describe('toggling column visibility', function () {\r
1976 var refreshCounter;\r
1977\r
1978 beforeEach(function () {\r
1979 makeGrid();\r
1980 refreshCounter = view.refreshCounter;\r
1981 });\r
1982\r
1983 afterEach(function () {\r
1984 refreshCounter = null;\r
1985 });\r
1986\r
1987 describe('hiding', function () {\r
1988 it('should update the view', function () {\r
1989 colRef[0].hide();\r
1990\r
1991 expect(view.refreshCounter).toBe(refreshCounter + 1);\r
1992 });\r
1993 });\r
1994\r
1995 describe('showing', function () {\r
1996 it('should update the view', function () {\r
1997 colRef[0].hide();\r
1998 refreshCounter = view.refreshCounter;\r
1999 colRef[0].show();\r
2000\r
2001 expect(view.refreshCounter).toBe(refreshCounter + 1);\r
2002 });\r
2003 });\r
2004 });\r
2005 });\r
2006\r
2007 describe("locked/normal grid visibility", function() {\r
2008 function expectVisible(locked, normal) {\r
2009 expect(grid.lockedGrid.isVisible()).toBe(locked);\r
2010 expect(grid.normalGrid.isVisible()).toBe(normal);\r
2011 }\r
2012\r
2013 var failCount;\r
2014 beforeEach(function() {\r
2015 failCount = Ext.failedLayouts;\r
2016 });\r
2017\r
2018 afterEach(function() {\r
2019 expect(failCount).toBe(Ext.failedLayouts);\r
2020 failCount = null;\r
2021 });\r
2022\r
2023 describe("initial", function() {\r
2024 it("should have both sides visible", function() {\r
2025 makeGrid([{locked: true}, {}], {\r
2026 syncTaskDelay: 0\r
2027 });\r
2028 expectVisible(true, true);\r
2029 });\r
2030\r
2031 it("should have only the normal side visible if there are no locked columns", function() {\r
2032 makeGrid([{}, {}], {\r
2033 enableLocking: true,\r
2034 syncTaskDelay: 0\r
2035 });\r
2036 expectVisible(false, true);\r
2037 });\r
2038\r
2039 it("should have only the locked side visible if there are no normal columns", function() {\r
2040 makeGrid([{locked: true}, {locked: true}], {\r
2041 syncTaskDelay: 0\r
2042 });\r
2043 expectVisible(true, false);\r
2044 });\r
2045 });\r
2046\r
2047 describe("dynamic", function() {\r
2048 beforeEach(function() {\r
2049 makeGrid([{\r
2050 locked: true,\r
2051 itemId: 'col0'\r
2052 }, {\r
2053 locked: true,\r
2054 itemId: 'col1'\r
2055 }, {\r
2056 itemId: 'col2'\r
2057 }, {\r
2058 itemId: 'col3'\r
2059 }], {\r
2060 syncTaskDelay: 0\r
2061 });\r
2062 });\r
2063\r
2064 describe("normal side", function() {\r
2065 it("should not hide when removing a column but there are other normal columns", function() {\r
2066 grid.normalGrid.headerCt.remove('col2');\r
2067 expectVisible(true, true);\r
2068 });\r
2069\r
2070 it("should hide when removing the last normal column", function() {\r
2071 grid.normalGrid.headerCt.remove('col2');\r
2072 grid.normalGrid.headerCt.remove('col3');\r
2073 expectVisible(true, false);\r
2074 });\r
2075\r
2076 it("should not hide when hiding a column but there are other visible normal columns", function() {\r
2077 colRef[2].hide();\r
2078 expectVisible(true, true);\r
2079 });\r
2080\r
2081 it("should hide when hiding the last normal column", function() {\r
2082 colRef[2].hide();\r
2083 colRef[3].hide();\r
2084 expectVisible(true, false);\r
2085 });\r
2086 });\r
2087\r
2088 describe("locked side", function() {\r
2089 it("should not hide when removing a column but there are other locked columns", function() {\r
2090 grid.lockedGrid.headerCt.remove('col0');\r
2091 expectVisible(true, true);\r
2092 });\r
2093\r
2094 it("should hide when removing the last locked column", function() {\r
2095 grid.lockedGrid.headerCt.remove('col0');\r
2096 grid.lockedGrid.headerCt.remove('col1');\r
2097 expectVisible(false, true);\r
2098 });\r
2099\r
2100 it("should not hide when hiding a column but there are other visible locked columns", function() {\r
2101 colRef[0].hide();\r
2102 expectVisible(true, true);\r
2103 });\r
2104\r
2105 it("should hide when hiding the last locked column", function() {\r
2106 colRef[0].hide();\r
2107 colRef[1].hide();\r
2108 expectVisible(false, true);\r
2109 });\r
2110 });\r
2111 });\r
2112 });\r
2113\r
2114 describe("rendering", function() {\r
2115 beforeEach(function() {\r
2116 makeGrid();\r
2117 });\r
2118\r
2119 describe("first/last", function() {\r
2120 it("should stamp x-grid-cell-first on the first column cell", function() {\r
2121 var cls = grid.getView().firstCls;\r
2122 expect(hasCls(getCell(0, 0), cls)).toBe(true);\r
2123 expect(hasCls(getCell(0, 1), cls)).toBe(false);\r
2124 expect(hasCls(getCell(0, 2), cls)).toBe(false);\r
2125 expect(hasCls(getCell(0, 3), cls)).toBe(false);\r
2126 });\r
2127\r
2128 it("should stamp x-grid-cell-last on the last column cell", function() {\r
2129 var cls = grid.getView().lastCls;\r
2130 expect(hasCls(getCell(0, 0), cls)).toBe(false);\r
2131 expect(hasCls(getCell(0, 1), cls)).toBe(false);\r
2132 expect(hasCls(getCell(0, 2), cls)).toBe(false);\r
2133 expect(hasCls(getCell(0, 3), cls)).toBe(true);\r
2134 });\r
2135\r
2136 it("should update the first class when moving the first column", function() {\r
2137 grid.headerCt.insert(0, colRef[1]);\r
2138\r
2139 var cell = getCell(0, 0),\r
2140 view = grid.getView(),\r
2141 cls = view.firstCls;\r
2142\r
2143 expect(getCellText(0, 0)).toBe('val2');\r
2144 expect(hasCls(cell, cls)).toBe(true);\r
2145 expect(hasCls(getCell(0, 1), cls)).toBe(false);\r
2146 });\r
2147\r
2148 it("should update the last class when moving the last column", function() {\r
2149 // Suppress console warning about reusing existing id\r
2150 spyOn(Ext.log, 'warn');\r
2151\r
2152 grid.headerCt.add(colRef[1]);\r
2153\r
2154 var cell = getCell(0, 3),\r
2155 view = grid.getView(),\r
2156 cls = view.lastCls;\r
2157\r
2158 expect(getCellText(0, 3)).toBe('val2');\r
2159 expect(hasCls(cell, cls)).toBe(true);\r
2160 expect(hasCls(getCell(0, 2), cls)).toBe(false);\r
2161 });\r
2162 });\r
2163\r
2164 describe("id", function() {\r
2165 it("should stamp the id of the column in the cell", function() {\r
2166 expect(hasCls(getCell(0, 0), 'x-grid-cell-col0')).toBe(true);\r
2167 expect(hasCls(getCell(0, 1), 'x-grid-cell-col1')).toBe(true);\r
2168 expect(hasCls(getCell(0, 2), 'x-grid-cell-col2')).toBe(true);\r
2169 expect(hasCls(getCell(0, 3), 'x-grid-cell-col3')).toBe(true);\r
2170 });\r
2171 });\r
2172 });\r
2173\r
2174 describe("hiddenHeaders", function() {\r
2175 it("should lay out the hidden items so cells obtain correct width", function() {\r
2176 makeGrid([{\r
2177 width: 100\r
2178 }, {\r
2179 flex: 1\r
2180 }, {\r
2181 width: 200\r
2182 }], {\r
2183 hiddenHeaders: true\r
2184 });\r
2185\r
2186 expect(getCell(0, 0).getWidth()).toBe(100);\r
2187 expect(getCell(0, 1).getWidth()).toBe(totalWidth - 200 - 100);\r
2188 expect(getCell(0, 2).getWidth()).toBe(200);\r
2189 });\r
2190\r
2191 it("should lay out grouped column headers", function() {\r
2192 makeGrid([{\r
2193 width: 100\r
2194 }, {\r
2195 columns: [{\r
2196 width: 200\r
2197 }, {\r
2198 width: 400\r
2199 }, {\r
2200 width: 100\r
2201 }]\r
2202 }, {\r
2203 width: 200\r
2204 }], {\r
2205 hiddenHeaders: true\r
2206 });\r
2207 expect(getCell(0, 0).getWidth()).toBe(100);\r
2208 expect(getCell(0, 1).getWidth()).toBe(200);\r
2209 expect(getCell(0, 2).getWidth()).toBe(400);\r
2210 expect(getCell(0, 3).getWidth()).toBe(100);\r
2211 expect(getCell(0, 4).getWidth()).toBe(200);\r
2212 });\r
2213 });\r
2214\r
2215 describe("emptyCellText config", function () {\r
2216 function expectEmptyText(column, rowIdx, colIdx) {\r
2217 var cell = getCellInner(rowIdx, colIdx),\r
2218 el = document.createElement('div');\r
2219\r
2220 // We're doing this because ' ' !== '&#160;'. By letting the browser decode the entity, we\r
2221 // can then do a comparison.\r
2222 el.innerHTML = column.emptyCellText;\r
2223\r
2224 expect(cell.textContent || cell.innerText).toBe(el.textContent || el.innerText);\r
2225 }\r
2226\r
2227 describe("rendering", function() {\r
2228 beforeEach(function () {\r
2229 makeGrid([{\r
2230 width: 100\r
2231 }, {\r
2232 emptyCellText: 'derp',\r
2233 width: 200\r
2234 }]);\r
2235 });\r
2236\r
2237 it("should use the default html entity for when there is no emptyCellText given", function () {\r
2238 expectEmptyText(colRef[0], 0, 0);\r
2239 });\r
2240\r
2241 it("should use the value of emptyCellText when configured", function () {\r
2242 expectEmptyText(colRef[1], 0, 1);\r
2243 });\r
2244 });\r
2245\r
2246 describe("column update", function() {\r
2247 describe("full row update", function() {\r
2248 it("should use the empty text on update", function() {\r
2249 makeGrid([{\r
2250 width: 100,\r
2251 dataIndex: 'field0',\r
2252 renderer: function(v, meta, rec) {\r
2253 return v;\r
2254 }\r
2255 }]);\r
2256 // Renderer with >1 arg requires a full row redraw\r
2257 store.getAt(0).set('field0', '');\r
2258 expectEmptyText(colRef[0], 0, 0);\r
2259 });\r
2260 });\r
2261\r
2262 describe("cell update only", function() {\r
2263 describe("producesHTML: true", function() {\r
2264 it("should use the empty text on update", function() {\r
2265 makeGrid([{\r
2266 width: 100,\r
2267 producesHTML: true,\r
2268 dataIndex: 'field0'\r
2269 }]);\r
2270 store.getAt(0).set('field0', '');\r
2271 expectEmptyText(colRef[0], 0, 0);\r
2272 });\r
2273\r
2274 it("should use the empty text on update with a simple renderer", function() {\r
2275 makeGrid([{\r
2276 width: 100,\r
2277 producesHTML: true,\r
2278 dataIndex: 'field0',\r
2279 renderer: Ext.identityFn\r
2280 }]);\r
2281 store.getAt(0).set('field0', '');\r
2282 expectEmptyText(colRef[0], 0, 0);\r
2283 });\r
2284 });\r
2285\r
2286 describe("producesHTML: false", function() {\r
2287 it("should use the empty text on update", function() {\r
2288 makeGrid([{\r
2289 width: 100,\r
2290 producesHTML: false,\r
2291 dataIndex: 'field0'\r
2292 }]);\r
2293 store.getAt(0).set('field0', '');\r
2294 expectEmptyText(colRef[0], 0, 0);\r
2295 });\r
2296\r
2297 it("should use the empty text on update with a simple renderer", function() {\r
2298 makeGrid([{\r
2299 width: 100,\r
2300 producesHTML: false,\r
2301 dataIndex: 'field0',\r
2302 renderer: Ext.identityFn\r
2303 }]);\r
2304 store.getAt(0).set('field0', '');\r
2305 expectEmptyText(colRef[0], 0, 0);\r
2306 });\r
2307 });\r
2308 });\r
2309 });\r
2310 });\r
2311\r
2312 describe("non-column items in the header", function() {\r
2313 it("should show non-columns as children", function() {\r
2314 makeGrid([{\r
2315 width: 100,\r
2316 items: {\r
2317 xtype: 'textfield',\r
2318 itemId: 'foo'\r
2319 }\r
2320 }]);\r
2321 expect(grid.down('#foo').isVisible(true)).toBe(true);\r
2322 });\r
2323\r
2324 it("should have the hidden item as visible after showing an initially hidden column", function() {\r
2325 makeGrid([{\r
2326 width: 100,\r
2327 items: {\r
2328 xtype: 'textfield'\r
2329 }\r
2330 }, {\r
2331 width: 100,\r
2332 hidden: true,\r
2333 items: {\r
2334 xtype: 'textfield',\r
2335 itemId: 'foo'\r
2336 }\r
2337 }]);\r
2338 var field = grid.down('#foo');\r
2339 expect(field.isVisible(true)).toBe(false);\r
2340 field.ownerCt.show();\r
2341 expect(field.isVisible(true)).toBe(true);\r
2342 });\r
2343 });\r
2344\r
2345 describe("reconfiguring", function() {\r
2346 it("should destroy any old columns", function() {\r
2347 var o = {};\r
2348\r
2349 makeGrid(4);\r
2350 Ext.Array.forEach(colRef, function(col) {\r
2351 col.on('destroy', function(c) {\r
2352 o[col.getItemId()] = true;\r
2353 });\r
2354 });\r
2355 grid.reconfigure(null, []);\r
2356 expect(o).toEqual({\r
2357 col0: true,\r
2358 col1: true,\r
2359 col2: true,\r
2360 col3: true\r
2361 });\r
2362 });\r
2363\r
2364 describe("with locking", function() {\r
2365 it("should resize the locked part to match the grid size", function() {\r
2366 makeGrid(4, null, null, function(i) {\r
2367 return i === 0;\r
2368 });\r
2369\r
2370 var borderWidth = grid.lockedGrid.el.getBorderWidth('lr');\r
2371\r
2372 // Default column width\r
2373 expect(grid.lockedGrid.getWidth()).toBe(100 + borderWidth);\r
2374 grid.reconfigure(null, [{\r
2375 locked: true,\r
2376 width: 120\r
2377 }, {\r
2378 locked: true,\r
2379 width: 170\r
2380 }, {}, {}])\r
2381 expect(grid.lockedGrid.getWidth()).toBe(120 + 170 + borderWidth);\r
2382 });\r
2383 });\r
2384 });\r
2385 \r
2386 describe('column header borders', function() {\r
2387 it('should show header borders by default, and turn them off dynamically', function() {\r
2388 makeGrid();\r
2389 expect(colRef[0].el.getBorderWidth('r')).toBe(1);\r
2390 expect(colRef[1].el.getBorderWidth('r')).toBe(1);\r
2391 expect(colRef[2].el.getBorderWidth('r')).toBe(1);\r
2392 grid.setHeaderBorders(false);\r
2393 expect(colRef[0].el.getBorderWidth('r')).toBe(0);\r
2394 expect(colRef[1].el.getBorderWidth('r')).toBe(0);\r
2395 expect(colRef[2].el.getBorderWidth('r')).toBe(0);\r
2396 });\r
2397 it('should have no borders if configured false, and should show them dynamically', function() {\r
2398 makeGrid(null, {\r
2399 headerBorders: false\r
2400 });\r
2401 expect(colRef[0].el.getBorderWidth('r')).toBe(0);\r
2402 expect(colRef[1].el.getBorderWidth('r')).toBe(0);\r
2403 expect(colRef[2].el.getBorderWidth('r')).toBe(0);\r
2404 grid.setHeaderBorders(true);\r
2405 expect(colRef[0].el.getBorderWidth('r')).toBe(1);\r
2406 expect(colRef[1].el.getBorderWidth('r')).toBe(1);\r
2407 expect(colRef[2].el.getBorderWidth('r')).toBe(1);\r
2408 });\r
2409 });\r
2410 });\r
2411 }\r
2412 createSuite(false);\r
2413 createSuite(true);\r
2414});\r
2415\r