]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/form/CheckboxGroup.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / form / CheckboxGroup.js
CommitLineData
6527f429
DM
1describe("Ext.form.CheckboxGroup", function() {\r
2 var component;\r
3\r
4 function makeComponent(config) {\r
5 config = config || {};\r
6 component = new Ext.form.CheckboxGroup(config);\r
7 }\r
8\r
9 afterEach(function() {\r
10 if (component) {\r
11 component.destroy();\r
12 }\r
13 component = null;\r
14 });\r
15\r
16\r
17 describe("initial value", function() {\r
18 it("should set its originalValue to the aggregated value of its sub-checkboxes", function() {\r
19 makeComponent({\r
20 items: [\r
21 {name: 'one', checked: true},\r
22 {name: 'two', checked: true, inputValue: 'two-1'},\r
23 {name: 'two', checked: false, inputValue: 'two-2'},\r
24 {name: 'two', checked: true, inputValue: 'two-3'}\r
25 ]\r
26 });\r
27 expect(component.originalValue).toEqual({one:'on', two: ['two-1', 'two-3']});\r
28 });\r
29\r
30 it("should set the values of its sub-checkboxes if the value config is specified", function() {\r
31 makeComponent({\r
32 items: [\r
33 {name: 'one', checked: true},\r
34 {name: 'two', checked: true, inputValue: 'two-1'},\r
35 {name: 'two', checked: false, inputValue: 'two-2'},\r
36 {name: 'two', checked: true, inputValue: 'two-3'}\r
37 ],\r
38 value: {two: ['two-1', 'two-2']}\r
39 });\r
40 expect(component.originalValue).toEqual({two: ['two-1', 'two-2']});\r
41 expect(component.items.getAt(0).getValue()).toBe(false);\r
42 expect(component.items.getAt(1).getValue()).toBe(true);\r
43 expect(component.items.getAt(2).getValue()).toBe(true);\r
44 expect(component.items.getAt(3).getValue()).toBe(false);\r
45 });\r
46 });\r
47\r
48 describe("sizing", function() {\r
49 it("should respect a configured height", function() {\r
50 makeComponent({\r
51 renderTo: Ext.getBody(),\r
52 height: 100,\r
53 width: 300,\r
54 vertical: true,\r
55 columns: 2,\r
56 scrollable: 'y',\r
57 items: (function() {\r
58 var checkboxes = [],\r
59 i;\r
60\r
61 for (i = 0; i < 50; ++i) {\r
62 checkboxes.push({\r
63 xtype: 'checkbox'\r
64 });\r
65 } \r
66 return checkboxes;\r
67 })()\r
68 });\r
69 expect(component.getHeight()).toBe(100);\r
70 });\r
71 })\r
72\r
73 it("should fire the change event when a sub-checkbox is changed", function() {\r
74 makeComponent({\r
75 items: [{name: 'foo', checked: true}]\r
76 });\r
77 var spy = jasmine.createSpy();\r
78 component.on('change', spy);\r
79\r
80 component.items.getAt(0).setValue(false);\r
81 expect(spy.calls[0].args).toEqual([component, {}, {foo:'on'}]);\r
82\r
83 component.items.getAt(0).setValue(true);\r
84 expect(spy.calls[1].args).toEqual([component, {foo:'on'}, {}]);\r
85 });\r
86\r
87 describe("getValue", function() {\r
88 it("should return an object with keys matching the names of checked items", function() {\r
89 makeComponent({\r
90 items: [{name: 'one', checked: true}, {name: 'two'}]\r
91 });\r
92 var val = component.getValue();\r
93 expect(val.one).toBeDefined();\r
94 expect(val.two).not.toBeDefined();\r
95 });\r
96 it("should give the inputValue of a single checked item with a given name", function() {\r
97 makeComponent({\r
98 items: [{name: 'one', checked: true, inputValue: 'foo'}, {name: 'two'}]\r
99 });\r
100 expect(component.getValue().one).toEqual('foo');\r
101 });\r
102 it("should give an array of inputValues of multiple checked items with the same name", function() {\r
103 makeComponent({\r
104 items: [{name: 'one', checked: true, inputValue: '1'}, {name: 'one', checked: true, inputValue: '2'}, {name: 'one'}]\r
105 });\r
106 expect(component.getValue().one).toEqual(['1', '2']);\r
107 });\r
108 });\r
109\r
110 describe("getSubmitData", function() {\r
111 it("should return null", function() {\r
112 makeComponent({\r
113 value: {foo: true},\r
114 items: [{name: 'foo', inputValue: 'bar'}]\r
115 });\r
116 expect(component.getSubmitData()).toBeNull();\r
117 });\r
118 });\r
119\r
120 describe("getModelData", function() {\r
121 it("should return null", function() {\r
122 makeComponent({\r
123 value: {foo: true},\r
124 items: [{name: 'foo', inputValue: 'bar'}]\r
125 });\r
126 expect(component.getModelData()).toBeNull();\r
127 });\r
128 });\r
129\r
130 describe("reset", function() {\r
131 it("should reset each checkbox to its initial checked state", function() {\r
132 makeComponent({\r
133 items: [{name: 'one', checked: true}, {name: 'two'}, {name: 'three', checked: true}]\r
134 });\r
135 component.setValue({one: false, two: true});\r
136 component.reset();\r
137 expect(component.items.getAt(0).getValue()).toBe(true);\r
138 expect(component.items.getAt(1).getValue()).toBe(false);\r
139 expect(component.items.getAt(2).getValue()).toBe(true);\r
140 });\r
141 });\r
142\r
143 describe("allowBlank = false", function() {\r
144 it("should return a validation error when no sub-checkboxes are checked", function() {\r
145 makeComponent({\r
146 allowBlank: false,\r
147 items: [{name: 'one'}]\r
148 });\r
149 expect(component.isValid()).toBe(false);\r
150 });\r
151\r
152 it("should not return an error when a sub-checkbox is checked", function() {\r
153 makeComponent({\r
154 allowBlank: false,\r
155 items: [{name: 'one', checked: true}]\r
156 });\r
157 expect(component.isValid()).toBe(true);\r
158 });\r
159 \r
160 it("should fire the validitychange event with true when checking a box previously undefined", function(){\r
161 makeComponent({\r
162 allowBlank: false,\r
163 items: [{name: 'one'}]\r
164 });\r
165 var isValid;\r
166 component.on('validitychange', function(field, validState){\r
167 isValid = validState;\r
168 });\r
169 component.setValue({\r
170 one: true\r
171 });\r
172 expect(isValid).toBe(true);\r
173 });\r
174 \r
175 it("should fire the validitychange event with true when unchecking a box", function(){\r
176 makeComponent({\r
177 allowBlank: false,\r
178 items: [{name: 'one', checked: true}]\r
179 });\r
180 var isValid;\r
181 component.on('validitychange', function(field, validState){\r
182 isValid = validState;\r
183 });\r
184 component.setValue({\r
185 one: false\r
186 });\r
187 expect(isValid).toBe(false);\r
188 });\r
189 });\r
190\r
191 describe("setValue", function() {\r
192 describe("with a view model", function() {\r
193 it("should be able to set the value with inline data", function() {\r
194 var vm = new Ext.app.ViewModel({\r
195 data: {\r
196 theValue: {\r
197 foo: true,\r
198 baz: true\r
199 }\r
200 }\r
201 });\r
202\r
203 makeComponent({\r
204 renderTo: Ext.getBody(),\r
205 items: [{\r
206 name: 'foo'\r
207 }, {\r
208 name: 'bar'\r
209 }, {\r
210 name: 'baz'\r
211 }],\r
212 viewModel: vm,\r
213 bind: {\r
214 value: '{theValue}'\r
215 }\r
216 });\r
217 vm.notify();\r
218 expect(component.getValue()).toEqual({\r
219 foo: 'on',\r
220 baz: 'on'\r
221 });\r
222\r
223 });\r
224\r
225 it("should be able to set the value with a defined viewmodel", function() {\r
226 Ext.define('spec.Bar', {\r
227 extend: 'Ext.app.ViewModel',\r
228 alias: 'viewmodel.bar',\r
229 data: {\r
230 theValue: {\r
231 foo: true,\r
232 baz: true\r
233 }\r
234 }\r
235 });\r
236\r
237 makeComponent({\r
238 renderTo: Ext.getBody(),\r
239 items: [{\r
240 name: 'foo'\r
241 }, {\r
242 name: 'bar'\r
243 }, {\r
244 name: 'baz'\r
245 }],\r
246 viewModel: {\r
247 type: 'bar'\r
248 },\r
249 bind: {\r
250 value: '{theValue}'\r
251 }\r
252 });\r
253\r
254 component.getViewModel().notify();\r
255\r
256 expect(component.getValue()).toEqual({\r
257 foo: 'on',\r
258 baz: 'on'\r
259 });\r
260 Ext.undefine('spec.Bar');\r
261 Ext.Factory.viewModel.instance.clearCache();\r
262 });\r
263 });\r
264 });\r
265 \r
266 describe("ARIA", function() {\r
267 function expectAria(attr, value) {\r
268 jasmine.expectAriaAttr(component, attr, value);\r
269 }\r
270 \r
271 beforeEach(function() {\r
272 makeComponent({\r
273 renderTo: Ext.getBody(),\r
274 items: [{\r
275 name: 'foo'\r
276 }, {\r
277 name: 'bar'\r
278 }, {\r
279 name: 'baz'\r
280 }]\r
281 });\r
282 });\r
283 \r
284 describe("ariaEl", function() {\r
285 it("should have containerEl as ariaEl", function() {\r
286 expect(component.ariaEl).toBe(component.containerEl);\r
287 });\r
288 });\r
289 \r
290 describe("attributes", function() {\r
291 it("should have group role", function() {\r
292 expectAria('role', 'group');\r
293 });\r
294 \r
295 it("should have aria-owns", function() {\r
296 var foo = component.down('[name=foo]').inputEl,\r
297 bar = component.down('[name=bar]').inputEl,\r
298 baz = component.down('[name=baz]').inputEl;\r
299 \r
300 expectAria('aria-owns', foo.id + ' ' + bar.id + ' ' + baz.id);\r
301 });\r
302 });\r
303 });\r
304});