]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/grid/column/Check.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / grid / column / Check.js
CommitLineData
6527f429
DM
1describe("Ext.grid.column.Check", function() {\r
2 var grid, store, col;\r
3\r
4 function getColCfg() {\r
5 return {\r
6 xtype: 'checkcolumn',\r
7 text: 'Checked',\r
8 dataIndex: 'val'\r
9 };\r
10 }\r
11 \r
12 function makeGrid(columns) {\r
13 store = new Ext.data.Store({\r
14 model: spec.CheckColumnModel,\r
15 data: [{\r
16 val: true\r
17 }, {\r
18 val: true\r
19 }, {\r
20 val: false\r
21 }, {\r
22 val: true\r
23 }, {\r
24 val: false\r
25 }]\r
26 });\r
27\r
28 if (!columns) {\r
29 columns = [getColCfg()];\r
30 }\r
31 \r
32 grid = new Ext.grid.Panel({\r
33 width: 200,\r
34 height: 100,\r
35 renderTo: Ext.getBody(),\r
36 store: store,\r
37 columns: columns\r
38 });\r
39 col = grid.getColumnManager().getFirst();\r
40 }\r
41 \r
42 function triggerCellMouseEvent(type, rowIdx, cellIdx, button, x, y) {\r
43 var target = getCellImg(rowIdx, cellIdx);\r
44\r
45 jasmine.fireMouseEvent(target, type, x, y, button);\r
46 }\r
47 \r
48 function getCell(rowIdx) {\r
49 return grid.getView().getCellInclusive({\r
50 row: rowIdx,\r
51 column: 0\r
52 });\r
53 }\r
54 \r
55 function getCellImg(rowIdx) {\r
56 var cell = getCell(rowIdx);\r
57 return Ext.fly(cell).down('.x-grid-checkcolumn');\r
58 }\r
59 \r
60 function hasCls(el, cls) {\r
61 return Ext.fly(el).hasCls(cls);\r
62 }\r
63 \r
64 beforeEach(function() {\r
65 Ext.define('spec.CheckColumnModel', {\r
66 extend: 'Ext.data.Model',\r
67 fields: ['val']\r
68 });\r
69 });\r
70 \r
71 afterEach(function() {\r
72 Ext.destroy(grid, store);\r
73 col = grid = store = null;\r
74 Ext.undefine('spec.CheckColumnModel');\r
75 Ext.data.Model.schema.clear();\r
76 });\r
77 \r
78 describe("check rendering", function() {\r
79 \r
80 it("should add the x-grid-checkcolumn class to the checkbox element", function() {\r
81 makeGrid();\r
82 \r
83 expect(hasCls(getCellImg(0), 'x-grid-checkcolumn')).toBe(true);\r
84 });\r
85 \r
86 it("should set the x-grid-checkcolumn-checked class on checked items", function() {\r
87 makeGrid();\r
88 \r
89 expect(hasCls(getCellImg(0), 'x-grid-checkcolumn-checked')).toBe(true);\r
90 expect(hasCls(getCellImg(2), 'x-grid-checkcolumn-checked')).toBe(false);\r
91 });\r
92 });\r
93 \r
94 describe("enable/disable", function() {\r
95 describe("during config", function() {\r
96 it("should not include the disabledCls if the column is not disabled", function() {\r
97 makeGrid();\r
98 expect(hasCls(getCell(0), col.disabledCls)).toBe(false);\r
99 });\r
100 \r
101 it("should include the disabledCls if the column is disabled", function() {\r
102 var cfg = getColCfg();\r
103 cfg.disabled = true;\r
104 makeGrid([cfg]);\r
105 expect(hasCls(getCell(0), col.disabledCls)).toBe(true);\r
106 });\r
107 });\r
108 \r
109 describe("after render", function() {\r
110 it("should add the disabledCls if disabling", function() {\r
111 makeGrid();\r
112 col.disable();\r
113 expect(hasCls(getCell(0), col.disabledCls)).toBe(true);\r
114 expect(hasCls(getCell(1), col.disabledCls)).toBe(true);\r
115 expect(hasCls(getCell(2), col.disabledCls)).toBe(true);\r
116 expect(hasCls(getCell(3), col.disabledCls)).toBe(true);\r
117 expect(hasCls(getCell(4), col.disabledCls)).toBe(true);\r
118 });\r
119 \r
120 it("should remove the disabledCls if enabling", function() {\r
121 var cfg = getColCfg();\r
122 cfg.disabled = true;\r
123 makeGrid([cfg]);\r
124 col.enable();\r
125 expect(hasCls(getCell(0), col.disabledCls)).toBe(false);\r
126 expect(hasCls(getCell(1), col.disabledCls)).toBe(false);\r
127 expect(hasCls(getCell(2), col.disabledCls)).toBe(false);\r
128 expect(hasCls(getCell(3), col.disabledCls)).toBe(false);\r
129 expect(hasCls(getCell(4), col.disabledCls)).toBe(false);\r
130 });\r
131 });\r
132 });\r
133 \r
134 describe("interaction", function() {\r
135 describe("stopSelection", function() {\r
136 describe("stopSelection: false", function() {\r
137 it("should select when a full row update is required", function() {\r
138 var cfg = getColCfg();\r
139 cfg.stopSelection = false;\r
140 // Template column always required a full update\r
141 makeGrid([cfg, {\r
142 xtype: 'templatecolumn',\r
143 dataIndex: 'val',\r
144 tpl: '{val}'\r
145 }]);\r
146 triggerCellMouseEvent('click', 0);\r
147 expect(grid.getSelectionModel().isSelected(store.getAt(0))).toBe(true);\r
148 });\r
149\r
150 it("should select when a full row update is not required", function() {\r
151 var cfg = getColCfg();\r
152 cfg.stopSelection = false;\r
153 // Template column always required a full update\r
154 makeGrid([cfg, {\r
155 dataIndex: 'val'\r
156 }]);\r
157 triggerCellMouseEvent('click', 0);\r
158 expect(grid.getSelectionModel().isSelected(store.getAt(0))).toBe(true);\r
159 });\r
160 });\r
161\r
162 describe("stopSelection: true", function() {\r
163 it("should not select when a full row update is required", function() {\r
164 var cfg = getColCfg();\r
165 cfg.stopSelection = true;\r
166 // Template column always required a full update\r
167 makeGrid([cfg, {\r
168 xtype: 'templatecolumn',\r
169 dataIndex: 'val',\r
170 tpl: '{val}'\r
171 }]);\r
172 triggerCellMouseEvent('click', 0);\r
173 expect(grid.getSelectionModel().isSelected(store.getAt(0))).toBe(false);\r
174 });\r
175\r
176 it("should not select when a full row update is not required", function() {\r
177 var cfg = getColCfg();\r
178 cfg.stopSelection = true;\r
179 // Template column always required a full update\r
180 makeGrid([cfg, {\r
181 dataIndex: 'val'\r
182 }]);\r
183 triggerCellMouseEvent('click', 0);\r
184 expect(grid.getSelectionModel().isSelected(store.getAt(0))).toBe(false);\r
185 });\r
186 });\r
187 });\r
188\r
189 describe("events", function() {\r
190 it("should pass the column, record index & new checked state for beforecheckchange", function() {\r
191 var arg1, arg2, arg3;\r
192 makeGrid();\r
193 col.on('beforecheckchange', function(a, b, c) {\r
194 arg1 = a;\r
195 arg2 = b;\r
196 arg3 = c; \r
197 });\r
198 triggerCellMouseEvent('mousedown', 0);\r
199 expect(arg1).toBe(col);\r
200 expect(arg2).toBe(0);\r
201 expect(arg3).toBe(false);\r
202 });\r
203 \r
204 it("should pass the column, record index & new checked state for checkchange", function() {\r
205 var arg1, arg2, arg3;\r
206 makeGrid();\r
207 col.on('checkchange', function(a, b, c) {\r
208 arg1 = a;\r
209 arg2 = b;\r
210 arg3 = c; \r
211 });\r
212 triggerCellMouseEvent('mousedown', 2);\r
213 expect(arg1).toBe(col);\r
214 expect(arg2).toBe(2);\r
215 expect(arg3).toBe(true);\r
216 });\r
217 \r
218 it("should not fire fire checkchange if beforecheckchange returns false", function() {\r
219 var called = false;\r
220 makeGrid();\r
221 col.on('checkchange', function(a, b, c) {\r
222 called = true;\r
223 });\r
224 col.on('beforecheckchange', function() {\r
225 return false;\r
226 });\r
227 triggerCellMouseEvent('mousedown', 2);\r
228 expect(called).toBe(false);\r
229 });\r
230 });\r
231 \r
232 it("should invert the record value", function() {\r
233 makeGrid();\r
234 triggerCellMouseEvent('mousedown', 0);\r
235 expect(store.getAt(0).get('val')).toBe(false);\r
236 triggerCellMouseEvent('mousedown', 2);\r
237 expect(store.getAt(2).get('val')).toBe(true);\r
238 });\r
239 \r
240 it("should not trigger any changes when disabled", function() {\r
241 var cfg = getColCfg();\r
242 cfg.disabled = true;\r
243 makeGrid([cfg]);\r
244 triggerCellMouseEvent('mousedown', 0);\r
245 expect(store.getAt(0).get('val')).toBe(true);\r
246 triggerCellMouseEvent('mousedown', 2);\r
247 expect(store.getAt(2).get('val')).toBe(false);\r
248 });\r
249 });\r
250});\r