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