]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/test/specs/field/Select.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / test / specs / field / Select.js
CommitLineData
6527f429
DM
1describe('Ext.field.Select', function() {\r
2 var field,\r
3 createField = function(config) {\r
4 if (field) {\r
5 field.destroy();\r
6 }\r
7\r
8 field = Ext.create('Ext.field.Select', config || {});\r
9 },\r
10 synchronousLoad = true,\r
11 proxyStoreLoad = Ext.data.ProxyStore.prototype.load,\r
12 loadStore;\r
13\r
14 beforeEach(function() {\r
15 // Override so that we can control asynchronous loading\r
16 loadStore = Ext.data.ProxyStore.prototype.load = function() {\r
17 proxyStoreLoad.apply(this, arguments);\r
18 if (synchronousLoad) {\r
19 this.flushLoad.apply(this, arguments);\r
20 }\r
21 return this;\r
22 };\r
23 });\r
24\r
25 afterEach(function() {\r
26 // Undo the overrides.\r
27 Ext.data.ProxyStore.prototype.load = proxyStoreLoad;\r
28\r
29 if (field) {\r
30 field.destroy();\r
31 }\r
32 });\r
33\r
34 describe("configurations", function() {\r
35 describe("options", function() {\r
36 beforeEach(function() {\r
37 createField({\r
38 options: [\r
39 {text: 'One', value: 1},\r
40 {text: 'Two', value: 2},\r
41 {text: 'Three', value: 3}\r
42 ]\r
43 });\r
44 });\r
45\r
46 it("should create a store with 3 items", function() {\r
47 expect(field.getStore().getCount()).toEqual(3);\r
48 });\r
49\r
50 it("should set the value configuration to the first item", function() {\r
51 expect(field.getSelection()).toEqual(field.getStore().getAt(0));\r
52 });\r
53\r
54 describe("with value", function() {\r
55 beforeEach(function() {\r
56 createField({\r
57 value: 3,\r
58 options: [\r
59 {text: 'One', value: 1},\r
60 {text: 'Two', value: 2},\r
61 {text: 'Three', value: 3}\r
62 ]\r
63 });\r
64 });\r
65\r
66 it("should create a store with 3 items", function() {\r
67 expect(field.getStore().getCount()).toEqual(3);\r
68 });\r
69\r
70 it("should set the value configuration to the third item", function() {\r
71 expect(field.getSelection()).toEqual(field.getStore().getAt(2));\r
72 expect(field.getSelection().get('value')).toEqual(3);\r
73 expect(field.getSelection().get('text')).toEqual('Three');\r
74 expect(field.getValue()).toEqual(3);\r
75 });\r
76 });\r
77 });\r
78\r
79 describe("store", function() {\r
80 beforeEach(function() {\r
81 createField({\r
82 store: {\r
83 fields: ['text', 'value'],\r
84 data: [\r
85 {text: 'One', value: 1},\r
86 {text: 'Two', value: 2},\r
87 {text: 'Three', value: 3}\r
88 ]\r
89 }\r
90 });\r
91 });\r
92\r
93 it("should create a store with 3 items", function() {\r
94 expect(field.getStore().getCount()).toEqual(3);\r
95 });\r
96\r
97 describe("with value", function() {\r
98 beforeEach(function() {\r
99 createField({\r
100 value: 3,\r
101 store: {\r
102 fields: ['text', 'value'],\r
103 data: [\r
104 {text: 'One', value: 1},\r
105 {text: 'Two', value: 2},\r
106 {text: 'Three', value: 3}\r
107 ]\r
108 }\r
109 });\r
110 });\r
111\r
112 it("should create a store with 3 items", function() {\r
113 expect(field.getStore().getCount()).toEqual(3);\r
114 });\r
115\r
116 it("should set the value configuration to the third item", function() {\r
117 expect(field.getSelection()).toEqual(field.getStore().getAt(2));\r
118 expect(field.getSelection().get('value')).toEqual(3);\r
119 expect(field.getSelection().get('text')).toEqual('Three');\r
120 expect(field.getValue()).toEqual(3);\r
121 });\r
122 });\r
123 });\r
124\r
125 describe("value", function() {\r
126 describe("0", function() {\r
127 beforeEach(function() {\r
128 createField({\r
129 value: 0,\r
130 options: [\r
131 {text: 'One', value: 0},\r
132 {text: 'Two', value: 1},\r
133 {text: 'Three', value: 2}\r
134 ]\r
135 });\r
136 });\r
137\r
138 it("should set the value after adding options", function() {\r
139 expect(field.getValue()).toEqual(0);\r
140 });\r
141 });\r
142\r
143 describe("0", function() {\r
144 beforeEach(function() {\r
145 createField({\r
146 value: 1,\r
147 options: [\r
148 {text: 'One', value: 0},\r
149 {text: 'Two', value: 1},\r
150 {text: 'Three', value: 2}\r
151 ]\r
152 });\r
153 });\r
154\r
155 it("should set the value after adding options", function() {\r
156 expect(field.getValue()).toEqual(1);\r
157 });\r
158 });\r
159\r
160 describe("default value", function() {\r
161 describe("none", function() {\r
162 beforeEach(function() {\r
163 createField();\r
164 });\r
165\r
166 it("should set the value after adding options", function() {\r
167 expect(field.getValue()).toEqual(null);\r
168\r
169 field.setStore({\r
170 fields: ['text', 'value'],\r
171 data: [\r
172 {text: 'One', value: 1},\r
173 {text: 'Two', value: 2},\r
174 {text: 'Three', value: 3}\r
175 ]\r
176 });\r
177\r
178 //autoSelect\r
179 expect(field.getValue()).toEqual(1);\r
180 });\r
181 });\r
182\r
183 describe("value", function() {\r
184 beforeEach(function() {\r
185 createField({\r
186 value: 3\r
187 });\r
188 });\r
189\r
190 it("should set the value after adding options", function() {\r
191 expect(field.getValue()).toEqual(null);\r
192\r
193 field.setStore({\r
194 fields: ['text', 'value'],\r
195 data: [\r
196 {text: 'One', value: 1},\r
197 {text: 'Two', value: 2},\r
198 {text: 'Three', value: 3}\r
199 ]\r
200 });\r
201\r
202 expect(field.getValue()).toEqual(3);\r
203 });\r
204 });\r
205\r
206 describe("setValue", function() {\r
207 describe("with value and store", function() {\r
208 beforeEach(function() {\r
209 createField({\r
210 value: 3,\r
211 store: {\r
212 fields: ['text', 'value'],\r
213 data: [\r
214 {text: 'One', value: 1},\r
215 {text: 'Two', value: 2},\r
216 {text: 'Three', value: 3}\r
217 ]\r
218 }\r
219 });\r
220 });\r
221\r
222 it("should set to null", function() {\r
223 expect(field.getValue()).toEqual(3);\r
224 field.setValue(null);\r
225 expect(field.getValue()).toEqual(null);\r
226 });\r
227 });\r
228\r
229 describe("with no value", function() {\r
230 beforeEach(function() {\r
231 createField();\r
232 });\r
233\r
234 it("should set to null", function() {\r
235 expect(field.getValue()).toEqual(null);\r
236 field.setStore({\r
237 fields: ['text', 'value'],\r
238 data: [\r
239 {text: 'One', value: 1},\r
240 {text: 'Two', value: 2},\r
241 {text: 'Three', value: 3}\r
242 ]\r
243 });\r
244 expect(field.getValue()).toEqual(1);\r
245 field.setValue(null);\r
246 expect(field.getValue()).toEqual(null);\r
247 });\r
248 });\r
249 });\r
250 });\r
251 });\r
252\r
253 describe("autoSelect", function() {\r
254 describe("when on", function() {\r
255 beforeEach(function() {\r
256 createField({\r
257 store: {\r
258 fields: ['text', 'value'],\r
259 data: [\r
260 {text: 'One', value: 1},\r
261 {text: 'Two', value: 2},\r
262 {text: 'Three', value: 3}\r
263 ]\r
264 }\r
265 });\r
266 });\r
267\r
268 it("should set the value configuration to the first item", function() {\r
269 expect(field.getSelection()).toEqual(field.getStore().getAt(0));\r
270 });\r
271 });\r
272\r
273 describe("when off", function() {\r
274 beforeEach(function() {\r
275 createField({\r
276 autoSelect: false,\r
277 store: {\r
278 fields: ['text', 'value'],\r
279 data: [\r
280 {text: 'One', value: 1},\r
281 {text: 'Two', value: 2},\r
282 {text: 'Three', value: 3}\r
283 ]\r
284 }\r
285 });\r
286 });\r
287\r
288 it("should set the value to null", function() {\r
289 expect(field.getSelection()).toEqual(null);\r
290 });\r
291 });\r
292 });\r
293 });\r
294\r
295 describe("TOUCH-2431", function() {\r
296 it("should use store configuration", function() {\r
297 Ext.define('Ext.MySelect', {\r
298 extend: 'Ext.field.Select',\r
299\r
300 config: {\r
301 store: {\r
302 fields: ['name', 'value'],\r
303 data: [\r
304 {\r
305 name: 'one',\r
306 value: 1\r
307 },\r
308 {\r
309 name: 'two',\r
310 value: 2\r
311 }\r
312 ]\r
313 }\r
314 }\r
315 });\r
316\r
317 var select = Ext.create('Ext.MySelect');\r
318 expect(select.getStore().getCount()).toEqual(2);\r
319 \r
320 select.destroy();\r
321 });\r
322 });\r
323\r
324 describe("events", function() {\r
325 describe("change", function() {\r
326 describe("without options", function() {\r
327 beforeEach(function() {\r
328 createField();\r
329 });\r
330\r
331 it("should only fire change once when adding options", function() {\r
332 var spy = jasmine.createSpy();\r
333\r
334 field.on('change', spy);\r
335\r
336 field.setOptions([\r
337 {text: 'One', value: 1},\r
338 {text: 'Two', value: 2},\r
339 {text: 'Three', value: 3}\r
340 ]);\r
341\r
342 expect(spy.callCount).toBe(1);\r
343 });\r
344 });\r
345\r
346 describe("with options", function() {\r
347 beforeEach(function() {\r
348 createField({\r
349 options: [\r
350 {text: 'One', value: 1},\r
351 {text: 'Two', value: 2},\r
352 {text: 'Three', value: 3}\r
353 ]\r
354 });\r
355 });\r
356\r
357 it("should fire when you change the value", function() {\r
358 var spy = jasmine.createSpy();\r
359\r
360 field.on('change', spy);\r
361\r
362 field.setValue(2);\r
363\r
364 expect(spy.callCount).toBe(1);\r
365 });\r
366\r
367 it("should not fire when you dont change the value", function() {\r
368 var spy = jasmine.createSpy();\r
369\r
370 field.on('change', spy);\r
371\r
372 field.setValue(1);\r
373\r
374 expect(spy).not.toHaveBeenCalled();\r
375 });\r
376 });\r
377 });\r
378 });\r
379\r
380 describe("methods", function() {\r
381 describe("reset", function() {\r
382 describe("when autoSelect is on", function() {\r
383 beforeEach(function() {\r
384 createField({\r
385 store : {\r
386 fields : ['text', 'value'],\r
387 data : [\r
388 { text : 'One', value : 1 },\r
389 { text : 'Two', value : 2 },\r
390 { text : 'Three', value : 3 }\r
391 ]\r
392 }\r
393 });\r
394\r
395 field.setValue(3);\r
396 });\r
397\r
398 it("should set the value configuration to the first item", function() {\r
399 field.reset();\r
400\r
401 expect(field.getSelection()).toBe(field.getStore().getAt(0));\r
402 });\r
403 });\r
404\r
405 describe("when autoSelect is off", function() {\r
406 beforeEach(function() {\r
407 createField({\r
408 autoSelect : false,\r
409 store : {\r
410 fields : ['text', 'value'],\r
411 data : [\r
412 { text : 'One', value : 1 },\r
413 { text : 'Two', value : 2 },\r
414 { text : 'Three', value : 3 }\r
415 ]\r
416 }\r
417 });\r
418\r
419 field.setValue(3);\r
420 });\r
421\r
422 it("should set the value to null", function() {\r
423 field.reset();\r
424\r
425 expect(field.getSelection()).toBe(null);\r
426 });\r
427 });\r
428 });\r
429 });\r
430});\r