]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/test/specs/Button.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / test / specs / Button.js
CommitLineData
6527f429
DM
1describe('Ext.Button', function() {\r
2 var button;\r
3 \r
4 function createButton(config) {\r
5 config = Ext.apply({\r
6 }, config);\r
7 \r
8 button = new Ext.Button(config);\r
9 };\r
10\r
11 afterEach(function() {\r
12 if (button) {\r
13 button.destroy();\r
14 }\r
15 \r
16 button = null;\r
17 });\r
18\r
19 describe("configurations", function() {\r
20 describe("autoHandler", function() {\r
21 describe("configuration", function() {\r
22\r
23 it("should set the autoHandler configuration", function() {\r
24 createButton({autoEvent: 'test'});\r
25\r
26 expect(button.getAutoEvent()).not.toBeNull();\r
27 });\r
28\r
29 it("should set a handler", function() {\r
30 createButton({autoEvent: 'test'});\r
31\r
32 expect(button.getHandler()).not.toBeNull();\r
33 });\r
34\r
35 it("should set a scope", function() {\r
36 createButton({autoEvent: 'test'});\r
37\r
38 expect(button.getScope()).not.toBeNull();\r
39 });\r
40\r
41 describe("transforming", function() {\r
42 it("should transform a string into an object", function() {\r
43 createButton({autoEvent: 'test'});\r
44\r
45 var ae = button.getAutoEvent();\r
46\r
47 expect(ae).not.toBeNull();\r
48 expect(typeof ae).toEqual("object");\r
49 });\r
50\r
51 it("should set the name of the object", function() {\r
52 createButton({autoEvent: 'test'});\r
53\r
54 var ae = button.getAutoEvent();\r
55\r
56 expect(ae.name).toEqual('test');\r
57 });\r
58\r
59 it("should set the scope of the object", function() {\r
60 createButton({autoEvent: 'test'});\r
61\r
62 var ae = button.getAutoEvent();\r
63\r
64 expect(ae.scope).not.toBeNull();\r
65 });\r
66 });\r
67 });\r
68\r
69 describe("method", function() {\r
70 it("should set the autoHandler configuration", function() {\r
71 createButton();\r
72 button.setAutoEvent('test');\r
73\r
74 expect(button.getAutoEvent()).not.toBeNull();\r
75 });\r
76\r
77 it("should set a handler", function() {\r
78 createButton();\r
79 button.setAutoEvent('test');\r
80\r
81 expect(button.getHandler()).not.toBeNull();\r
82 });\r
83\r
84 it("should set a scope", function() {\r
85 createButton();\r
86 button.setAutoEvent('test');\r
87\r
88 expect(button.getScope()).not.toBeNull();\r
89 });\r
90\r
91 describe("transforming", function() {\r
92 it("should transform a string into an object", function() {\r
93 createButton();\r
94 button.setAutoEvent('test');\r
95\r
96 var ae = button.getAutoEvent();\r
97\r
98 expect(ae).not.toBeNull();\r
99 expect(typeof ae).toEqual("object");\r
100 });\r
101\r
102 it("should set the name of the object", function() {\r
103 createButton();\r
104 button.setAutoEvent('test');\r
105\r
106 var ae = button.getAutoEvent();\r
107\r
108 expect(ae.name).toEqual('test');\r
109 });\r
110\r
111 it("should set the scope of the object", function() {\r
112 createButton();\r
113 button.setAutoEvent('test');\r
114\r
115 var ae = button.getAutoEvent();\r
116\r
117 expect(ae.scope).not.toBeNull();\r
118 });\r
119 });\r
120 });\r
121 });\r
122\r
123\r
124 describe("badgeText", function() {\r
125 describe("configuration", function() {\r
126 beforeEach(function() {\r
127 createButton({badgeText: 'test'});\r
128 });\r
129\r
130 it("should set the badgeText", function() {\r
131 expect(button.getBadgeText()).toEqual('test');\r
132 });\r
133\r
134 describe("after render", function() {\r
135 beforeEach(function() {\r
136 button.renderTo(Ext.getBody());\r
137 });\r
138 it("should create a badgeEl", function() {\r
139 expect(button.badgeElement).not.toBeNull();\r
140 });\r
141 it("should have the badgeText value in the badgeEl", function() {\r
142 expect(button.badgeElement.dom.innerHTML).toEqual('test');\r
143 });\r
144 });\r
145 });\r
146\r
147 describe("methods", function() {\r
148 beforeEach(function() {\r
149 createButton();\r
150 });\r
151\r
152 describe("after render", function() {\r
153 beforeEach(function() {\r
154 button.renderTo(Ext.getBody());\r
155\r
156 button.setBadgeText('test');\r
157 });\r
158\r
159 it("should set the badgeText", function() {\r
160 expect(button.getBadgeText()).toEqual('test');\r
161 });\r
162\r
163 it("should create a badgeEl", function() {\r
164 expect(button.badgeElement).not.toBeNull();\r
165 });\r
166\r
167 describe("when removing badgeText", function() {\r
168 beforeEach(function() {\r
169 button.setBadgeText(null);\r
170 });\r
171\r
172 it("should remove the badgeText configuration", function() {\r
173\r
174 expect(button.getBadgeText()).toBeNull();\r
175 });\r
176 });\r
177\r
178 it("should have the badgeText value in the badgeEl", function() {\r
179 expect(button.badgeElement.dom.innerHTML).toEqual('test');\r
180 });\r
181 });\r
182 });\r
183 });\r
184\r
185\r
186 describe("text", function() {\r
187 describe("configuration", function() {\r
188 beforeEach(function() {\r
189 createButton({\r
190 text: 'test'\r
191 });\r
192 });\r
193\r
194 it("should set the text", function() {\r
195 expect(button.getText()).toEqual('test');\r
196 });\r
197\r
198 describe("after render", function() {\r
199 beforeEach(function() {\r
200 button.renderTo(Ext.getBody());\r
201 });\r
202\r
203 it("should create a textEl", function() {\r
204 expect(button.textElement).not.toBeNull();\r
205 });\r
206 });\r
207 });\r
208\r
209 describe("methods", function() {\r
210 beforeEach(function() {\r
211 createButton();\r
212 });\r
213\r
214 it("should set the text", function() {\r
215 button.setText('test');\r
216 expect(button.getText()).toEqual('test');\r
217 });\r
218\r
219 describe("after render", function() {\r
220\r
221 it("should create a textEl", function() {\r
222 expect(button.textElement).not.toBeNull();\r
223 });\r
224\r
225 describe("when removing text", function() {\r
226 beforeEach(function() {\r
227 button.setText(null);\r
228 });\r
229\r
230 it("should remove the text configuration", function() {\r
231 expect(button.getText()).toBeNull();\r
232 });\r
233 });\r
234 });\r
235 });\r
236 });\r
237\r
238\r
239 describe("icon", function() {\r
240 describe("configuration", function() {\r
241 beforeEach(function() {\r
242 createButton({\r
243 icon: 'test'\r
244 });\r
245 });\r
246\r
247 it("should set the icon", function() {\r
248 expect(button.getIcon()).toEqual('test');\r
249 });\r
250\r
251 describe("after render", function() {\r
252 beforeEach(function() {\r
253 button.renderTo(Ext.getBody());\r
254 });\r
255\r
256 it("should create a iconEl", function() {\r
257 expect(button.iconElement).not.toBeNull();\r
258 });\r
259 });\r
260 });\r
261\r
262 describe("methods", function() {\r
263 beforeEach(function() {\r
264 createButton({\r
265 icon: 'test'\r
266 });\r
267\r
268 });\r
269\r
270 it("should set the icon", function() {\r
271 button.setIcon('test');\r
272 expect(button.getIcon()).toEqual('test');\r
273 });\r
274\r
275 describe("after render", function() {\r
276 beforeEach(function() {\r
277 button.renderTo(Ext.getBody());\r
278 });\r
279\r
280 it("should create a iconEl", function() {\r
281 expect(button.iconElement).not.toBeNull();\r
282 });\r
283\r
284 describe("when remove the icon", function() {\r
285 beforeEach(function() {\r
286 button.setIcon(null);\r
287 });\r
288\r
289 it("should remove the icon configuration", function() {\r
290 expect(button.getIcon()).toBeNull();\r
291 });\r
292 });\r
293\r
294 it("should call refreshIconAlign when updating the icon", function() {\r
295 spyOn(button, "refreshIconAlign");\r
296\r
297 button.setIcon('another');\r
298\r
299 expect(button.refreshIconAlign.calls.length).toBe(1);\r
300 });\r
301\r
302 it("should have the new background-image on the iconEl", function() {\r
303 button.setIcon('another');\r
304\r
305 expect(button.iconElement.getStyle('background-image')).toMatch('another');\r
306 });\r
307\r
308 it("should remove any old cls on the iconEl", function() {\r
309 button.setIcon('another');\r
310\r
311 expect(button.iconElement.getStyle('background-image')).toMatch('another');\r
312\r
313 button.setIcon('new');\r
314\r
315 expect(button.iconElement.getStyle('background-image')).not.toMatch('another');\r
316 expect(button.iconElement.getStyle('background-image')).toMatch('new');\r
317 });\r
318 });\r
319 });\r
320 });\r
321\r
322\r
323 describe("iconCls", function() {\r
324 describe("configuration", function() {\r
325 beforeEach(function() {\r
326 createButton({\r
327 iconCls: 'test'\r
328 });\r
329 });\r
330\r
331 it("should set the iconCls", function() {\r
332 expect(button.getIconCls()).toEqual('test');\r
333 });\r
334\r
335 describe("after render", function() {\r
336 beforeEach(function() {\r
337 button.renderTo(Ext.getBody());\r
338 });\r
339\r
340 it("should insert the iconEl", function() {\r
341 expect(button.iconElement.parentNode).not.toBeNull();\r
342 });\r
343 });\r
344 });\r
345\r
346 describe("methods", function() {\r
347 beforeEach(function() {\r
348 createButton();\r
349 });\r
350\r
351 it("should set the iconCls", function() {\r
352 button.setIconCls('test');\r
353 expect(button.getIconCls()).toEqual('test');\r
354 });\r
355\r
356 it("should create an iconEl", function() {\r
357 expect(button.iconElement).not.toBeNull();\r
358 });\r
359\r
360 describe("after render", function() {\r
361 beforeEach(function() {\r
362 button.renderTo(Ext.getBody());\r
363 button.setIconCls('test');\r
364 });\r
365\r
366 describe("when removing iconCls", function() {\r
367 beforeEach(function() {\r
368 button.setIconCls(null);\r
369 });\r
370\r
371 it("should remove the iconCls configuration", function() {\r
372 expect(button.getIconCls()).toBeNull();\r
373 });\r
374\r
375 it("should remove the iconCls", function() {\r
376 expect(button.element.hasCls('test')).toBeFalsy();\r
377 });\r
378 });\r
379\r
380 it("should call refreshIconAlign one time when updating the iconCls", function() {\r
381 spyOn(button, "refreshIconAlign");\r
382\r
383 button.setIconCls('another');\r
384\r
385 expect(button.refreshIconAlign.calls.length).toBe(1);\r
386 });\r
387\r
388 it("should have the new cls on the iconEl", function() {\r
389 button.setIconCls('another');\r
390\r
391 expect(button.iconElement.hasCls('another')).toBeTruthy();\r
392 });\r
393\r
394 it("should remove any old cls on the iconEl", function() {\r
395 button.setIconCls('another');\r
396\r
397 expect(button.iconElement.hasCls('another')).toBeTruthy();\r
398\r
399 button.setIconCls('new');\r
400\r
401 expect(button.iconElement.hasCls('another')).toBeFalsy();\r
402 expect(button.iconElement.hasCls('new')).toBeTruthy();\r
403 });\r
404 });\r
405 });\r
406 });\r
407\r
408\r
409 describe("iconAlign", function() {\r
410 var value = 'right',\r
411 cls = Ext.baseCSSPrefix + 'iconalign-' + value;\r
412\r
413 describe("with icon", function() {\r
414 describe("configuration", function() {\r
415 beforeEach(function() {\r
416 createButton({iconAlign: value, icon: 'test', text: 'test'});\r
417 });\r
418\r
419 it("should set the iconAlign", function() {\r
420 expect(button.getIconAlign()).toEqual(value);\r
421 });\r
422\r
423 describe("after render", function() {\r
424 beforeEach(function() {\r
425 button.renderTo(Ext.getBody());\r
426 });\r
427\r
428 it("should add the iconAlign class", function() {\r
429 expect(button.element.hasCls(cls)).toBeTruthy();\r
430 });\r
431 });\r
432 });\r
433\r
434 describe("methods", function() {\r
435 beforeEach(function() {\r
436 createButton({icon: 'test', text: 'test'});\r
437 });\r
438\r
439 it("should set the iconAlign", function() {\r
440 button.setIconAlign(value);\r
441 expect(button.getIconAlign()).toEqual(value);\r
442 });\r
443\r
444 describe("after render", function() {\r
445 beforeEach(function() {\r
446 button.renderTo(Ext.getBody());\r
447\r
448 button.setIconAlign(value);\r
449 });\r
450\r
451 it("should add the iconAlign cls", function() {\r
452 expect(button.element.hasCls(cls)).toBeTruthy();\r
453 });\r
454\r
455 describe("when removing iconAlign", function() {\r
456 beforeEach(function() {\r
457 button.setIconAlign(null);\r
458 });\r
459\r
460 it("should remove the iconAlign configuration", function() {\r
461 expect(button.getIconAlign()).toBeNull();\r
462 });\r
463\r
464 it("should remove the iconAlign cls", function() {\r
465 expect(button.element.hasCls(cls)).not.toBeTruthy();\r
466 });\r
467 });\r
468 });\r
469 });\r
470 });\r
471\r
472 describe("without icon", function() {\r
473 describe("configuration", function() {\r
474 beforeEach(function() {\r
475 createButton({iconAlign: 'right'});\r
476 });\r
477\r
478 describe("after render", function() {\r
479 beforeEach(function() {\r
480 button.renderTo(Ext.getBody());\r
481 });\r
482\r
483 it("should add the iconAlign cls", function() {\r
484 expect(button.element.hasCls(cls)).toBeFalsy();\r
485 });\r
486 });\r
487 });\r
488\r
489 describe("methods", function() {\r
490 beforeEach(function() {\r
491 createButton();\r
492 });\r
493\r
494 describe("after render", function() {\r
495 beforeEach(function() {\r
496 button.renderTo(Ext.getBody());\r
497 button.setIconAlign(value);\r
498 });\r
499\r
500 it("should add the iconAlign cls", function() {\r
501 expect(button.element.hasCls(cls)).toBeFalsy();\r
502 });\r
503\r
504 describe("when adding icon", function() {\r
505 beforeEach(function() {\r
506 button.setText('another');\r
507 button.setIcon('another');\r
508 });\r
509\r
510 it("should add the iconAlign configuration", function() {\r
511 expect(button.getIconAlign()).toEqual(value);\r
512 });\r
513\r
514 it("should add the iconAlign cls", function() {\r
515 expect(button.element.hasCls(cls)).toBeTruthy();\r
516 });\r
517 });\r
518 });\r
519 });\r
520 });\r
521 });\r
522 });\r
523\r
524 describe("#refreshIconAlign", function() {\r
525 beforeEach(function() {\r
526 createButton();\r
527 });\r
528\r
529 it("should call #updateIconAlign", function() {\r
530 spyOn(button, "updateIconAlign");\r
531\r
532 button.refreshIconAlign();\r
533\r
534 expect(button.updateIconAlign).wasCalled();\r
535 });\r
536 });\r
537\r
538 describe("#onTap", function() {\r
539 beforeEach(function() {\r
540 createButton();\r
541 });\r
542\r
543 it("should return false if disabled", function() {\r
544 button.disabled = true;\r
545\r
546 expect(button.onTap()).toBeFalsy();\r
547 });\r
548\r
549 it("should call fireAction", function() {\r
550 spyOn(button, 'fireAction');\r
551\r
552 button.onTap();\r
553\r
554 expect(button.fireAction).wasCalled();\r
555 });\r
556 });\r
557\r
558 describe("#doTap", function() {\r
559 beforeEach(function() {\r
560 createButton();\r
561 });\r
562\r
563 describe("no handler", function() {\r
564 it("should return false", function() {\r
565 expect(button.doTap(button)).toBeFalsy();\r
566 });\r
567 });\r
568\r
569 describe("with handler", function() {\r
570 describe("string", function() {\r
571 it("should call the function", function() {\r
572 button.testFoo = function() {};\r
573 spyOn(button, 'testFoo');\r
574\r
575 button.setHandler('testFoo');\r
576\r
577 button.doTap(button);\r
578\r
579 expect(button.testFoo).wasCalled();\r
580 });\r
581 });\r
582\r
583 describe("reference", function() {\r
584 it("should call the function", function() {\r
585 button.testFoo = function() {};\r
586 spyOn(button, 'testFoo');\r
587\r
588 button.setHandler(button.testFoo);\r
589\r
590 button.doTap(button);\r
591\r
592 expect(button.testFoo).wasCalled();\r
593 });\r
594 });\r
595 });\r
596 });\r
597\r
598 describe("el", function() {\r
599 beforeEach(function() {\r
600 createButton();\r
601 button.renderTo(Ext.getBody());\r
602 });\r
603\r
604 describe("tap", function() {\r
605 it("should call onTap", function() {\r
606 spyOn(button, "onTap");\r
607\r
608 button.el.fireAction('tap', [], Ext.emptyFn);\r
609\r
610 expect(button.onTap).wasCalled();\r
611 });\r
612 });\r
613\r
614 (Ext.supports.Touch ? describe : xdescribe)("touchstart", function() {\r
615 it("should call onPress", function() {\r
616 spyOn(button, "onPress");\r
617\r
618 button.el.fireAction('touchstart', [], Ext.emptyFn);\r
619\r
620 expect(button.onPress).wasCalled();\r
621 });\r
622 });\r
623\r
624 (Ext.supports.Touch ? describe : xdescribe)("touchend", function() {\r
625 it("should call onRelease", function() {\r
626 spyOn(button, "onRelease");\r
627\r
628 button.el.fireAction('touchend', [], Ext.emptyFn);\r
629\r
630 expect(button.onRelease).wasCalled();\r
631 });\r
632 });\r
633 });\r
634});\r