]>
git.proxmox.com Git - extjs.git/blob - extjs/modern/modern/test/specs/Button.js
1 describe('Ext.Button', function() {
4 function createButton(config
) {
8 button
= new Ext
.Button(config
);
11 afterEach(function() {
19 describe("configurations", function() {
20 describe("autoHandler", function() {
21 describe("configuration", function() {
23 it("should set the autoHandler configuration", function() {
24 createButton({autoEvent
: 'test'});
26 expect(button
.getAutoEvent()).not
.toBeNull();
29 it("should set a handler", function() {
30 createButton({autoEvent
: 'test'});
32 expect(button
.getHandler()).not
.toBeNull();
35 it("should set a scope", function() {
36 createButton({autoEvent
: 'test'});
38 expect(button
.getScope()).not
.toBeNull();
41 describe("transforming", function() {
42 it("should transform a string into an object", function() {
43 createButton({autoEvent
: 'test'});
45 var ae
= button
.getAutoEvent();
47 expect(ae
).not
.toBeNull();
48 expect(typeof ae
).toEqual("object");
51 it("should set the name of the object", function() {
52 createButton({autoEvent
: 'test'});
54 var ae
= button
.getAutoEvent();
56 expect(ae
.name
).toEqual('test');
59 it("should set the scope of the object", function() {
60 createButton({autoEvent
: 'test'});
62 var ae
= button
.getAutoEvent();
64 expect(ae
.scope
).not
.toBeNull();
69 describe("method", function() {
70 it("should set the autoHandler configuration", function() {
72 button
.setAutoEvent('test');
74 expect(button
.getAutoEvent()).not
.toBeNull();
77 it("should set a handler", function() {
79 button
.setAutoEvent('test');
81 expect(button
.getHandler()).not
.toBeNull();
84 it("should set a scope", function() {
86 button
.setAutoEvent('test');
88 expect(button
.getScope()).not
.toBeNull();
91 describe("transforming", function() {
92 it("should transform a string into an object", function() {
94 button
.setAutoEvent('test');
96 var ae
= button
.getAutoEvent();
98 expect(ae
).not
.toBeNull();
99 expect(typeof ae
).toEqual("object");
102 it("should set the name of the object", function() {
104 button
.setAutoEvent('test');
106 var ae
= button
.getAutoEvent();
108 expect(ae
.name
).toEqual('test');
111 it("should set the scope of the object", function() {
113 button
.setAutoEvent('test');
115 var ae
= button
.getAutoEvent();
117 expect(ae
.scope
).not
.toBeNull();
124 describe("badgeText", function() {
125 describe("configuration", function() {
126 beforeEach(function() {
127 createButton({badgeText
: 'test'});
130 it("should set the badgeText", function() {
131 expect(button
.getBadgeText()).toEqual('test');
134 describe("after render", function() {
135 beforeEach(function() {
136 button
.renderTo(Ext
.getBody());
138 it("should create a badgeEl", function() {
139 expect(button
.badgeElement
).not
.toBeNull();
141 it("should have the badgeText value in the badgeEl", function() {
142 expect(button
.badgeElement
.dom
.innerHTML
).toEqual('test');
147 describe("methods", function() {
148 beforeEach(function() {
152 describe("after render", function() {
153 beforeEach(function() {
154 button
.renderTo(Ext
.getBody());
156 button
.setBadgeText('test');
159 it("should set the badgeText", function() {
160 expect(button
.getBadgeText()).toEqual('test');
163 it("should create a badgeEl", function() {
164 expect(button
.badgeElement
).not
.toBeNull();
167 describe("when removing badgeText", function() {
168 beforeEach(function() {
169 button
.setBadgeText(null);
172 it("should remove the badgeText configuration", function() {
174 expect(button
.getBadgeText()).toBeNull();
178 it("should have the badgeText value in the badgeEl", function() {
179 expect(button
.badgeElement
.dom
.innerHTML
).toEqual('test');
186 describe("text", function() {
187 describe("configuration", function() {
188 beforeEach(function() {
194 it("should set the text", function() {
195 expect(button
.getText()).toEqual('test');
198 describe("after render", function() {
199 beforeEach(function() {
200 button
.renderTo(Ext
.getBody());
203 it("should create a textEl", function() {
204 expect(button
.textElement
).not
.toBeNull();
209 describe("methods", function() {
210 beforeEach(function() {
214 it("should set the text", function() {
215 button
.setText('test');
216 expect(button
.getText()).toEqual('test');
219 describe("after render", function() {
221 it("should create a textEl", function() {
222 expect(button
.textElement
).not
.toBeNull();
225 describe("when removing text", function() {
226 beforeEach(function() {
227 button
.setText(null);
230 it("should remove the text configuration", function() {
231 expect(button
.getText()).toBeNull();
239 describe("icon", function() {
240 describe("configuration", function() {
241 beforeEach(function() {
247 it("should set the icon", function() {
248 expect(button
.getIcon()).toEqual('test');
251 describe("after render", function() {
252 beforeEach(function() {
253 button
.renderTo(Ext
.getBody());
256 it("should create a iconEl", function() {
257 expect(button
.iconElement
).not
.toBeNull();
262 describe("methods", function() {
263 beforeEach(function() {
270 it("should set the icon", function() {
271 button
.setIcon('test');
272 expect(button
.getIcon()).toEqual('test');
275 describe("after render", function() {
276 beforeEach(function() {
277 button
.renderTo(Ext
.getBody());
280 it("should create a iconEl", function() {
281 expect(button
.iconElement
).not
.toBeNull();
284 describe("when remove the icon", function() {
285 beforeEach(function() {
286 button
.setIcon(null);
289 it("should remove the icon configuration", function() {
290 expect(button
.getIcon()).toBeNull();
294 it("should call refreshIconAlign when updating the icon", function() {
295 spyOn(button
, "refreshIconAlign");
297 button
.setIcon('another');
299 expect(button
.refreshIconAlign
.calls
.length
).toBe(1);
302 it("should have the new background-image on the iconEl", function() {
303 button
.setIcon('another');
305 expect(button
.iconElement
.getStyle('background-image')).toMatch('another');
308 it("should remove any old cls on the iconEl", function() {
309 button
.setIcon('another');
311 expect(button
.iconElement
.getStyle('background-image')).toMatch('another');
313 button
.setIcon('new');
315 expect(button
.iconElement
.getStyle('background-image')).not
.toMatch('another');
316 expect(button
.iconElement
.getStyle('background-image')).toMatch('new');
323 describe("iconCls", function() {
324 describe("configuration", function() {
325 beforeEach(function() {
331 it("should set the iconCls", function() {
332 expect(button
.getIconCls()).toEqual('test');
335 describe("after render", function() {
336 beforeEach(function() {
337 button
.renderTo(Ext
.getBody());
340 it("should insert the iconEl", function() {
341 expect(button
.iconElement
.parentNode
).not
.toBeNull();
346 describe("methods", function() {
347 beforeEach(function() {
351 it("should set the iconCls", function() {
352 button
.setIconCls('test');
353 expect(button
.getIconCls()).toEqual('test');
356 it("should create an iconEl", function() {
357 expect(button
.iconElement
).not
.toBeNull();
360 describe("after render", function() {
361 beforeEach(function() {
362 button
.renderTo(Ext
.getBody());
363 button
.setIconCls('test');
366 describe("when removing iconCls", function() {
367 beforeEach(function() {
368 button
.setIconCls(null);
371 it("should remove the iconCls configuration", function() {
372 expect(button
.getIconCls()).toBeNull();
375 it("should remove the iconCls", function() {
376 expect(button
.element
.hasCls('test')).toBeFalsy();
380 it("should call refreshIconAlign one time when updating the iconCls", function() {
381 spyOn(button
, "refreshIconAlign");
383 button
.setIconCls('another');
385 expect(button
.refreshIconAlign
.calls
.length
).toBe(1);
388 it("should have the new cls on the iconEl", function() {
389 button
.setIconCls('another');
391 expect(button
.iconElement
.hasCls('another')).toBeTruthy();
394 it("should remove any old cls on the iconEl", function() {
395 button
.setIconCls('another');
397 expect(button
.iconElement
.hasCls('another')).toBeTruthy();
399 button
.setIconCls('new');
401 expect(button
.iconElement
.hasCls('another')).toBeFalsy();
402 expect(button
.iconElement
.hasCls('new')).toBeTruthy();
409 describe("iconAlign", function() {
411 cls
= Ext
.baseCSSPrefix
+ 'iconalign-' + value
;
413 describe("with icon", function() {
414 describe("configuration", function() {
415 beforeEach(function() {
416 createButton({iconAlign
: value
, icon
: 'test', text
: 'test'});
419 it("should set the iconAlign", function() {
420 expect(button
.getIconAlign()).toEqual(value
);
423 describe("after render", function() {
424 beforeEach(function() {
425 button
.renderTo(Ext
.getBody());
428 it("should add the iconAlign class", function() {
429 expect(button
.element
.hasCls(cls
)).toBeTruthy();
434 describe("methods", function() {
435 beforeEach(function() {
436 createButton({icon
: 'test', text
: 'test'});
439 it("should set the iconAlign", function() {
440 button
.setIconAlign(value
);
441 expect(button
.getIconAlign()).toEqual(value
);
444 describe("after render", function() {
445 beforeEach(function() {
446 button
.renderTo(Ext
.getBody());
448 button
.setIconAlign(value
);
451 it("should add the iconAlign cls", function() {
452 expect(button
.element
.hasCls(cls
)).toBeTruthy();
455 describe("when removing iconAlign", function() {
456 beforeEach(function() {
457 button
.setIconAlign(null);
460 it("should remove the iconAlign configuration", function() {
461 expect(button
.getIconAlign()).toBeNull();
464 it("should remove the iconAlign cls", function() {
465 expect(button
.element
.hasCls(cls
)).not
.toBeTruthy();
472 describe("without icon", function() {
473 describe("configuration", function() {
474 beforeEach(function() {
475 createButton({iconAlign
: 'right'});
478 describe("after render", function() {
479 beforeEach(function() {
480 button
.renderTo(Ext
.getBody());
483 it("should add the iconAlign cls", function() {
484 expect(button
.element
.hasCls(cls
)).toBeFalsy();
489 describe("methods", function() {
490 beforeEach(function() {
494 describe("after render", function() {
495 beforeEach(function() {
496 button
.renderTo(Ext
.getBody());
497 button
.setIconAlign(value
);
500 it("should add the iconAlign cls", function() {
501 expect(button
.element
.hasCls(cls
)).toBeFalsy();
504 describe("when adding icon", function() {
505 beforeEach(function() {
506 button
.setText('another');
507 button
.setIcon('another');
510 it("should add the iconAlign configuration", function() {
511 expect(button
.getIconAlign()).toEqual(value
);
514 it("should add the iconAlign cls", function() {
515 expect(button
.element
.hasCls(cls
)).toBeTruthy();
524 describe("#refreshIconAlign", function() {
525 beforeEach(function() {
529 it("should call #updateIconAlign", function() {
530 spyOn(button
, "updateIconAlign");
532 button
.refreshIconAlign();
534 expect(button
.updateIconAlign
).wasCalled();
538 describe("#onTap", function() {
539 beforeEach(function() {
543 it("should return false if disabled", function() {
544 button
.disabled
= true;
546 expect(button
.onTap()).toBeFalsy();
549 it("should call fireAction", function() {
550 spyOn(button
, 'fireAction');
554 expect(button
.fireAction
).wasCalled();
558 describe("#doTap", function() {
559 beforeEach(function() {
563 describe("no handler", function() {
564 it("should return false", function() {
565 expect(button
.doTap(button
)).toBeFalsy();
569 describe("with handler", function() {
570 describe("string", function() {
571 it("should call the function", function() {
572 button
.testFoo = function() {};
573 spyOn(button
, 'testFoo');
575 button
.setHandler('testFoo');
577 button
.doTap(button
);
579 expect(button
.testFoo
).wasCalled();
583 describe("reference", function() {
584 it("should call the function", function() {
585 button
.testFoo = function() {};
586 spyOn(button
, 'testFoo');
588 button
.setHandler(button
.testFoo
);
590 button
.doTap(button
);
592 expect(button
.testFoo
).wasCalled();
598 describe("el", function() {
599 beforeEach(function() {
601 button
.renderTo(Ext
.getBody());
604 describe("tap", function() {
605 it("should call onTap", function() {
606 spyOn(button
, "onTap");
608 button
.el
.fireAction('tap', [], Ext
.emptyFn
);
610 expect(button
.onTap
).wasCalled();
614 (Ext
.supports
.Touch
? describe
: xdescribe
)("touchstart", function() {
615 it("should call onPress", function() {
616 spyOn(button
, "onPress");
618 button
.el
.fireAction('touchstart', [], Ext
.emptyFn
);
620 expect(button
.onPress
).wasCalled();
624 (Ext
.supports
.Touch
? describe
: xdescribe
)("touchend", function() {
625 it("should call onRelease", function() {
626 spyOn(button
, "onRelease");
628 button
.el
.fireAction('touchend', [], Ext
.emptyFn
);
630 expect(button
.onRelease
).wasCalled();