]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/grid/header/Container.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / grid / header / Container.js
CommitLineData
6527f429
DM
1describe('Ext.grid.header.Container', function () {\r
2 var createGrid = function (storeCfg, gridCfg) {\r
3 store = Ext.create('Ext.data.Store', Ext.apply({\r
4 storeId:'simpsonsStore',\r
5 fields:['name', 'email', 'phone'],\r
6 data:{'items':[\r
7 { 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224" },\r
8 { 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234" },\r
9 { 'name': 'Homer', "email":"homer@simpsons.com", "phone":"555-222-1244" },\r
10 { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254" }\r
11 ]},\r
12 proxy: {\r
13 type: 'memory',\r
14 reader: {\r
15 type: 'json',\r
16 rootProperty: 'items'\r
17 }\r
18 }\r
19 }, storeCfg));\r
20\r
21 grid = Ext.create('Ext.grid.Panel', Ext.apply({\r
22 title: 'Simpsons',\r
23 store: store,\r
24 columns: [\r
25 { header: 'Name', dataIndex: 'name', width: 100 },\r
26 { header: 'Email', dataIndex: 'email', flex: 1 },\r
27 { header: 'Phone', dataIndex: 'phone', flex: 1, hidden: true }\r
28 ],\r
29 height: 200,\r
30 width: 400,\r
31 renderTo: Ext.getBody()\r
32 }, gridCfg));\r
33 },\r
34 store, grid;\r
35\r
36 afterEach(function(){\r
37 store.destroy();\r
38 grid = store = Ext.destroy(grid);\r
39 Ext.state.Manager.clear('foo');\r
40 });\r
41\r
42 describe('column menu showing', function() {\r
43 it('should show the menu on trigger click', function() {\r
44 var col,\r
45 menu;\r
46\r
47 runs(function() {\r
48 createGrid({}, {\r
49 renderTo: Ext.getBody()\r
50 });\r
51\r
52 col = grid.columns[0];\r
53 col.triggerEl.show();\r
54 jasmine.fireMouseEvent(col.triggerEl.dom, 'click');\r
55\r
56 menu = col.activeMenu;\r
57 expect(menu.isVisible()).toBe(true);\r
58 expect(menu.containsFocus).toBeFalsy();\r
59\r
60 jasmine.fireMouseEvent(col.triggerEl.dom, 'mousedown');\r
61 expect(menu.isVisible()).toBe(false);\r
62\r
63 // Opening the menu with down arrow focuses it\r
64 col.el.focus();\r
65 jasmine.fireKeyEvent(col.el.dom, 'keydown', Ext.event.Event.DOWN);\r
66 });\r
67 waitsFor(function() {\r
68 return menu.isVisible() && menu.containsFocus;\r
69 });\r
70 });\r
71 });\r
72\r
73 describe('columnManager delegations', function () {\r
74 it('should allow columns to call methods on the ColumnManager', function () {\r
75 var col;\r
76\r
77 createGrid({}, {\r
78 renderTo: Ext.getBody()\r
79 });\r
80\r
81 col = grid.columns[0];\r
82\r
83 expect(col.getHeaderIndex(col)).toBe(0);\r
84 expect(col.getHeaderAtIndex(0)).toBe(col);\r
85 expect(col.getVisibleHeaderClosestToIndex(0)).toBe(col);\r
86 });\r
87 });\r
88\r
89 describe('gridVisibleColumns', function () {\r
90 it('should keep track of state information for visible grid columns', function () {\r
91 var columns = [\r
92 // It's necessary to pass in columns with a headerId property for this test.\r
93 { header: 'Name', headerId: 'a', dataIndex: 'name', width: 100 },\r
94 { header: 'Email', headerId: 'b', dataIndex: 'email', flex: 1 },\r
95 { header: 'Phone', headerId: 'c', dataIndex: 'phone', flex: 1, hidden: true }\r
96 ];\r
97\r
98 new Ext.state.Provider();\r
99\r
100 createGrid({}, {\r
101 columns: columns,\r
102 stateful: true,\r
103 stateId: 'foo'\r
104 });\r
105\r
106 // Update state information.\r
107 grid.columns[2].show();\r
108\r
109 grid.saveState();\r
110\r
111 Ext.destroy(grid);\r
112\r
113 createGrid({}, {\r
114 columns: columns,\r
115 stateful: true,\r
116 stateId: 'foo'\r
117 });\r
118\r
119 expect(grid.headerCt.gridVisibleColumns.length).toBe(3);\r
120 });\r
121\r
122 it('should keep track of state information for visible grid columns when moved', function () {\r
123 // This spec simulates a stateful bug: EXTJSIV-10262. This bug occurs when a previously hidden\r
124 // header is shown and then moved. The bug occurs because the gridVisibleColumns cache is created\r
125 // from stale information. This happens when the visible grid columns are retrieved before applying\r
126 // the updated state info.\r
127 var columns = [\r
128 // It's necessary to pass in columns with a headerId property for this test.\r
129 { header: 'Name', headerId: 'a', dataIndex: 'name', width: 100 },\r
130 { header: 'Email', headerId: 'b', dataIndex: 'email', flex: 1 },\r
131 { header: 'Phone', headerId: 'c', dataIndex: 'phone', flex: 1, hidden: true }\r
132 ];\r
133\r
134 new Ext.state.Provider();\r
135\r
136 createGrid({}, {\r
137 columns: columns,\r
138 stateful: true,\r
139 stateId: 'foo'\r
140 });\r
141\r
142 // Update state information.\r
143 grid.columns[2].show();\r
144 grid.headerCt.move(2, 0);\r
145\r
146 grid.saveState();\r
147\r
148 Ext.destroy(grid);\r
149\r
150 createGrid({}, {\r
151 columns: columns,\r
152 stateful: true,\r
153 stateId: 'foo'\r
154 });\r
155\r
156 expect(grid.headerCt.gridVisibleColumns.length).toBe(3);\r
157 expect(grid.headerCt.gridVisibleColumns[0].dataIndex).toBe('phone');\r
158 });\r
159\r
160 it('should insert new columns into their correct new ordinal position after state restoration', function () {\r
161 // Test ticket EXTJS-15690.\r
162 var initialColumns = [\r
163 // It's necessary to pass in columns with a headerId property for this test.\r
164 { header: 'Email', headerId: 'b', dataIndex: 'email', flex: 1 },\r
165 { header: 'Phone', headerId: 'c', dataIndex: 'phone', flex: 1 }\r
166 ],\r
167 newColumns = [\r
168 // It's necessary to pass in columns with a headerId property for this test.\r
169 { header: 'Name', headerId: 'a', dataIndex: 'name', width: 100 },\r
170 { header: 'Email', headerId: 'b', dataIndex: 'email', flex: 1 },\r
171 { header: 'Phone', headerId: 'c', dataIndex: 'phone', flex: 1 }\r
172 ];\r
173\r
174 new Ext.state.Provider();\r
175\r
176 createGrid({}, {\r
177 columns: initialColumns,\r
178 stateful: true,\r
179 stateId: 'foo'\r
180 });\r
181\r
182 // Update state information.\r
183 // Should now be Phone,Email\r
184 grid.headerCt.move(1, 0);\r
185\r
186 grid.saveState();\r
187\r
188 Ext.destroy(grid);\r
189\r
190 // Create the grids with a new column in at index 0\r
191 // The stateful columns should be in their stateful *order*\r
192 // But the insertion point of the new column must be honoured.\r
193 createGrid({}, {\r
194 columns: newColumns,\r
195 stateful: true,\r
196 stateId: 'foo'\r
197 });\r
198\r
199 // The order of the two initial stateful columns should be restored.\r
200 // And the new, previously unknown column "name" which was configured\r
201 // At index 0 should have been inserted at index 0\r
202 expect(grid.headerCt.gridVisibleColumns[0].dataIndex).toBe('name');\r
203 expect(grid.headerCt.gridVisibleColumns[1].dataIndex).toBe('phone');\r
204 expect(grid.headerCt.gridVisibleColumns[2].dataIndex).toBe('email');\r
205 });\r
206 });\r
207\r
208 describe('non-column descendants of headerCt', function () {\r
209 describe('headerCt events', function () {\r
210 var headerCt, field;\r
211\r
212 beforeEach(function () {\r
213 createGrid(null, {\r
214 columns: [\r
215 { header: 'Name', dataIndex: 'name', width: 100 },\r
216 { header: 'Email', dataIndex: 'email', flex: 1,\r
217 items: [{\r
218 xtype: 'textfield'\r
219 }]\r
220 }\r
221 ]\r
222 });\r
223\r
224 headerCt = grid.headerCt;\r
225 field = headerCt.down('textfield');\r
226 });\r
227\r
228 afterEach(function () {\r
229 headerCt = field = null;\r
230 });\r
231\r
232 it('should not throw in reaction to a delegated keydown event', function () {\r
233 // Note that unfortunately we're testing a private method since that's where it throws.\r
234 jasmine.fireKeyEvent(field.inputEl, 'keydown', 13);\r
235\r
236 expect(function () {\r
237 var e = {\r
238 getTarget: function () {\r
239 return field.inputEl.dom;\r
240 }\r
241 };\r
242\r
243 headerCt.onHeaderActivate(e);\r
244 }).not.toThrow();\r
245 });\r
246\r
247 it('should not react to keydown events delegated from the headerCt', function () {\r
248 // For this test, we'll know that the event was short-circuited b/c the sortable column\r
249 // wasn't sorted.\r
250 var wasCalled = false,\r
251 fn = function () {\r
252 wasCalled = true;\r
253 };\r
254\r
255 headerCt.on('sortchange', fn);\r
256 jasmine.fireKeyEvent(field.inputEl, 'keydown', 13);\r
257\r
258 expect(wasCalled).toBe(false);\r
259 });\r
260 });\r
261 });\r
262 \r
263 describe("keyboard events", function() {\r
264 beforeEach(function() {\r
265 createGrid();\r
266 });\r
267 \r
268 it("should focus first column header on Home key", function() {\r
269 jasmine.syncPressKey(grid.headerCt.el, 'home');\r
270 jasmine.expectFocused(grid.headerCt.gridVisibleColumns[0]);\r
271 });\r
272 \r
273 it("should focus last column header on End key", function() {\r
274 jasmine.syncPressKey(grid.headerCt.el, 'end');\r
275 jasmine.expectFocused(grid.headerCt.gridVisibleColumns[1]);\r
276 });\r
277 });\r
278\r
279 describe('Disabling column hiding', function() {\r
280 beforeEach(function() {\r
281 createGrid();\r
282 });\r
283 \r
284 it('should disable hiding the last visible column', function() {\r
285 var menu,\r
286 col = grid.columns[0],\r
287 colItem,\r
288 colMenu,\r
289 nameItem,\r
290 emailItem;\r
291\r
292 // Open the header menu and mouseover the "Columns" item.\r
293 col.triggerEl.show();\r
294 jasmine.fireMouseEvent(col.triggerEl.dom, 'click');\r
295 menu = col.activeMenu;\r
296 colItem = menu.child('#columnItem');\r
297 jasmine.fireMouseEvent(colItem.el.dom, 'mouseover');\r
298\r
299 // Wait for the column show/hide menu to appear\r
300 waitsFor(function() {\r
301 colMenu = colItem.menu;\r
302 return colMenu && colMenu.isVisible();\r
303 });\r
304 \r
305 // Hide the "Name" column, leaving only the "Email" column visible\r
306 runs(function() {\r
307 nameItem = colMenu.child('[text=Name]');\r
308 emailItem = colMenu.child('[text=Email]');\r
309 jasmine.fireMouseEvent(nameItem.el.dom, 'click');\r
310 });\r
311\r
312 // The "Email" column is the last visible column, so its\r
313 // hide menu check item must be disabled.\r
314 waitsFor(function() {\r
315 return emailItem.disabled;\r
316 });\r
317 });\r
318 });\r
319});\r