/ext-4.0.7/src/core/test/unit/spec/Ext.js
JavaScript | 1559 lines | 1222 code | 321 blank | 16 comment | 1 complexity | 0ba5ab1ebf3713b47aed37b81d19612b MD5 | raw file
Large files files are truncated, but you can click here to view the full file
1/*
2
3This file is part of Ext JS 4
4
5Copyright (c) 2011 Sencha Inc
6
7Contact: http://www.sencha.com/contact
8
9GNU General Public License Usage
10This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14*/
15describe("Ext", function() {
16
17 describe("Ext.global", function() {
18 it("should return the global scope", function() {
19 expect(Ext.global).toBe((function(){ return this;}).call());
20 });
21 });
22
23 describe("Ext.apply", function() {
24 var origin, o;
25
26 beforeEach(function() {
27 origin = {
28 name: 'value',
29 something: 'cool',
30 items: [1,2,3],
31 method: function() {
32 this.myMethodCalled = true;
33 },
34 toString: function() {
35 this.myToStringCalled = true;
36 }
37 };
38 });
39
40 it("should copy normal properties", function() {
41 Ext.apply(origin, {
42 name: 'newName',
43 items: [4,5,6],
44 otherThing: 'not cool',
45 isCool: false
46 });
47
48 expect(origin.name).toEqual('newName');
49 expect(origin.items).toEqual([4,5,6]);
50 expect(origin.something).toEqual('cool');
51 expect(origin.otherThing).toEqual('not cool');
52 expect(origin.isCool).toEqual(false);
53 });
54
55 it("should copy functions", function() {
56 Ext.apply(origin, {
57 method: function() {
58 this.newMethodCalled = true;
59 }
60 });
61
62 origin.method();
63
64 expect(origin.myMethodCalled).not.toBeDefined();
65 expect(origin.newMethodCalled).toBeTruthy();
66 });
67
68 it("should copy non-enumerables", function() {
69 Ext.apply(origin, {
70 toString: function() {
71 this.newToStringCalled = true;
72 }
73 });
74
75 origin.toString();
76
77 expect(origin.myToStringCalled).not.toBeDefined();
78 expect(origin.newToStringCalled).toBeTruthy();
79 });
80
81 it("should apply properties and return an object", function() {
82 o = Ext.apply({}, {
83 foo: 1,
84 bar: 2
85 });
86
87 expect(o).toEqual({
88 foo: 1,
89 bar: 2
90 });
91 });
92
93 it("should change the reference of the object", function() {
94 o = {};
95 Ext.apply(o, {
96 opt1: 'x',
97 opt2: 'y'
98 });
99
100 expect(o).toEqual({
101 opt1: 'x',
102 opt2: 'y'
103 });
104 });
105
106 it("should overwrite properties", function() {
107 o = Ext.apply({
108 foo: 1,
109 baz: 4
110 }, {
111 foo: 2,
112 bar: 3
113 });
114
115 expect(o).toEqual({
116 foo: 2,
117 bar: 3,
118 baz: 4
119 });
120 });
121
122 it("should use default", function() {
123 o = {};
124
125 Ext.apply(o, {
126 foo: 'new',
127 exist: true
128 }, {
129 foo: 'old',
130 def: true
131 });
132
133 expect(o).toEqual({
134 foo: 'new',
135 def: true,
136 exist: true
137 });
138 });
139
140 it("should override all defaults", function() {
141 o = Ext.apply({}, {
142 foo: 'foo',
143 bar: 'bar'
144 }, {
145 foo: 'oldFoo',
146 bar: 'oldBar'
147 });
148
149 expect(o).toEqual( {
150 foo: 'foo',
151 bar: 'bar'
152 });
153 });
154
155 it("should return null if null is passed as first argument", function() {
156 expect(Ext.apply(null, {})).toBeNull();
157 });
158
159 it("should return the object if second argument is no defined", function() {
160 o = {
161 foo: 1
162 };
163 expect(Ext.apply(o)).toEqual(o);
164 });
165
166 it("should override valueOf", function() {
167 o = Ext.apply({}, {valueOf: 1});
168
169 expect(o.valueOf).toEqual(1);
170 });
171
172 it("should override toString", function() {
173 o = Ext.apply({}, {toString: 3});
174
175 expect(o.toString).toEqual(3);
176
177 });
178 });
179
180 describe("Ext.emptyFn", function() {
181 it("should return undefined without params", function() {
182 expect(Ext.emptyFn()).toBeUndefined();
183 });
184
185 it("should return undefined if you pass params", function() {
186 expect(Ext.emptyFn('aaaa', 'bbbbb')).toBeUndefined();
187 });
188 });
189
190 describe("Ext.iterate", function() {
191 var itFn;
192
193 beforeEach(function() {
194 itFn = jasmine.createSpy();
195 });
196
197 describe("iterate object", function() {
198 var o;
199
200 beforeEach(function() {
201 o = {
202 n1: 11,
203 n2: 13,
204 n3: 18
205 };
206 });
207
208 describe("if itFn does not return false", function() {
209 beforeEach(function() {
210 Ext.iterate(o, itFn);
211 });
212
213 it("should call the iterate function 3 times", function () {
214 expect(itFn.callCount).toEqual(3);
215 });
216
217 it("should call the iterate function with correct arguments", function () {
218 expect(itFn.calls[0].args).toEqual(["n1", 11, o]);
219 expect(itFn.calls[1].args).toEqual(["n2", 13, o]);
220 expect(itFn.calls[2].args).toEqual(["n3", 18, o]);
221 });
222 });
223
224 describe("if itFn return false", function() {
225 beforeEach(function() {
226 itFn.andReturn(false);
227 Ext.iterate(o, itFn);
228 });
229
230 it("should stop iteration if function return false", function() {
231 itFn.andReturn(false);
232
233 expect(itFn.calls.length).toEqual(1);
234 });
235 });
236 });
237
238 describe("do nothing on an empty object", function() {
239 var o;
240
241 beforeEach(function() {
242 o = {};
243 Ext.iterate(o, itFn);
244 });
245
246 it("should not call the iterate function", function () {
247 expect(itFn).not.toHaveBeenCalled();
248 });
249
250 });
251
252 describe("iterate array", function() {
253 var arr;
254
255 beforeEach(function() {
256 arr = [6, 7, 8, 9];
257 });
258
259 describe("if itFn does not return false", function() {
260 beforeEach(function() {
261 Ext.iterate(arr, itFn);
262 });
263
264 it("should call the iterate function 4 times", function () {
265 expect(itFn.callCount).toEqual(4);
266 });
267
268 it("should call the iterate function with correct arguments", function () {
269 expect(itFn.calls[0].args).toEqual([6, 0, arr]);
270 expect(itFn.calls[1].args).toEqual([7, 1, arr]);
271 expect(itFn.calls[2].args).toEqual([8, 2, arr]);
272 expect(itFn.calls[3].args).toEqual([9, 3, arr]);
273 });
274 });
275
276 describe("if itFn return false", function() {
277 beforeEach(function() {
278 itFn.andReturn(false);
279 Ext.iterate(arr, itFn);
280 });
281
282 it("should stop iteration if function return false", function() {
283 itFn.andReturn(false);
284
285 expect(itFn.calls.length).toEqual(1);
286 });
287 });
288 });
289
290 describe("do nothing on an empty array", function() {
291 var arr;
292
293 beforeEach(function() {
294 arr = [];
295 Ext.iterate(arr, itFn);
296 });
297
298 it("should not call the iterate function", function () {
299 expect(itFn).not.toHaveBeenCalled();
300 });
301
302 });
303 });
304
305 describe("Ext.applyIf", function(){
306 var o;
307
308 it("should apply properties and return an object with an empty destination object", function() {
309 o = Ext.applyIf({}, {
310 foo: 'foo',
311 bar: 'bar'
312 });
313
314 expect(o).toEqual( {
315 foo: 'foo',
316 bar: 'bar'
317 });
318 });
319
320 it("should not override default properties", function() {
321 o = Ext.applyIf({
322 foo: 'foo'
323 }, {
324 foo: 'oldFoo'
325 });
326
327 expect(o).toEqual({
328 foo: 'foo'
329 });
330 });
331
332 it("should not override default properties with mixing properties", function() {
333 o = Ext.applyIf({
334 foo: 1,
335 bar: 2
336 }, {
337 bar: 3,
338 baz: 4
339 });
340
341 expect(o).toEqual({
342 foo: 1,
343 bar: 2,
344 baz: 4
345 });
346 });
347
348 it("should change the reference of the object", function() {
349 o = {};
350 Ext.applyIf(o, {
351 foo: 2
352 }, {
353 foo: 1
354 });
355
356 expect(o).toEqual({
357 foo: 2
358 });
359 });
360
361 it("should return null if null is passed as first argument", function() {
362 expect(Ext.applyIf(null, {})).toBeNull();
363 });
364
365 it("should return the object if second argument is no defined", function() {
366 o = {
367 foo: 1
368 };
369
370 expect(Ext.applyIf(o)).toEqual(o);
371 });
372 });
373
374
375 describe("Ext.extend", function() {
376 var Dude, Awesome, david;
377
378 beforeEach(function() {
379 Dude = Ext.extend(Object, {
380 constructor: function(config){
381 Ext.apply(this, config);
382 this.isBadass = false;
383 }
384 });
385
386 Awesome = Ext.extend(Dude, {
387 constructor: function(){
388 Awesome.superclass.constructor.apply(this, arguments);
389 this.isBadass = true;
390 }
391 });
392
393 david = new Awesome({
394 davis: 'isAwesome'
395 });
396 });
397
398 it("should throw an error if superclass isn't defined", function() {
399 expect(function() {
400 Ext.extend(undefined, {});
401 }).toRaiseExtError("Attempting to extend from a class which has not been loaded on the page.");
402 });
403
404 it("should create a superclass that return the original classe", function() {
405 expect(david.superclass).toEqual(Dude.prototype);
406 });
407
408 it("should add override method", function() {
409 expect(typeof david.override === 'function').toBe(true);
410 });
411
412 it("should override redefined methods", function() {
413 expect(david.isBadass).toBe(true);
414 });
415
416 it("should keep new properties", function() {
417 expect(david.davis).toEqual('isAwesome');
418 });
419 });
420
421 describe("Ext.override", function(){
422 var Dude,
423 extApplySpy;
424
425 beforeEach(function(){
426 Dude = function(){}; // avoid to directly override Object class
427 extApplySpy = spyOn(Ext, "apply");
428 });
429
430 it("should apply override", function(){
431 var override = {foo: true};
432
433 Ext.override(Dude, override);
434
435 expect(extApplySpy).toHaveBeenCalledWith(Dude.prototype, override);
436 });
437 });
438
439 describe("Ext.valueFrom", function() {
440 var value, defaultValue;
441
442 describe("with allowBlank", function() {
443 describe("and an empty string", function() {
444 it("should return the value", function() {
445 expect(Ext.valueFrom('', 'aaa', true)).toBe('');
446 });
447 });
448
449 describe("and a string", function() {
450 it("should return the value", function() {
451 expect(Ext.valueFrom('bbb', 'aaa', true)).toBe('bbb');
452 });
453 });
454
455 describe("and an undefined value", function() {
456 it("should return the default value", function() {
457 expect(Ext.valueFrom(undefined, 'aaa', true)).toBe('aaa');
458 });
459 });
460
461 describe("and a null value", function() {
462 it("should return the default value", function() {
463 expect(Ext.valueFrom(null, 'aaa', true)).toBe('aaa');
464 });
465 });
466
467 describe("and a 0 value", function() {
468 it("should return the value", function() {
469 expect(Ext.valueFrom(0, 'aaa', true)).toBe(0);
470 });
471 });
472 });
473
474 describe("without allowBlank", function() {
475 describe("and an empty string", function() {
476 it("should return the default value", function() {
477 expect(Ext.valueFrom('', 'aaa')).toBe('aaa');
478 });
479 });
480
481 describe("and a string", function() {
482 it("should return the value", function() {
483 expect(Ext.valueFrom('bbb', 'aaa')).toBe('bbb');
484 });
485 });
486
487 describe("and an undefined value", function() {
488 it("should return the default value", function() {
489 expect(Ext.valueFrom(undefined, 'aaa')).toBe('aaa');
490 });
491 });
492
493 describe("and a null value", function() {
494 it("should return the default value", function() {
495 expect(Ext.valueFrom(null, 'aaa')).toBe('aaa');
496 });
497 });
498
499 describe("and a 0 value", function() {
500 it("should return the value", function() {
501 expect(Ext.valueFrom(0, 'aaa')).toBe(0);
502 });
503 });
504 });
505 });
506
507 describe("Ext.typeOf", function() {
508 it("should return null", function() {
509 expect(Ext.typeOf(null)).toEqual('null');
510 });
511 it("should return undefined", function() {
512 expect(Ext.typeOf(undefined)).toEqual('undefined');
513 });
514 it("should return undefined", function() {
515 expect(Ext.typeOf(window.someWeirdPropertyThatDoesntExist)).toEqual('undefined');
516 });
517 it("should return string", function() {
518 expect(Ext.typeOf('')).toEqual('string');
519 });
520 it("should return string", function() {
521 expect(Ext.typeOf('something')).toEqual('string');
522 });
523 it("should return string", function() {
524 expect(Ext.typeOf('1.2')).toEqual('string');
525 });
526 it("should return number", function() {
527 expect(Ext.typeOf(1)).toEqual('number');
528 });
529 it("should return number", function() {
530 expect(Ext.typeOf(1.2)).toEqual('number');
531 });
532 it("should return boolean", function() {
533 expect(Ext.typeOf(true)).toEqual('boolean');
534 });
535 it("should return boolean", function() {
536 expect(Ext.typeOf(false)).toEqual('boolean');
537 });
538 it("should return array", function() {
539 expect(Ext.typeOf([1,2,3])).toEqual('array');
540 });
541 it("should return array", function() {
542 expect(Ext.typeOf(new Array(1,2,3))).toEqual('array');
543 });
544 it("should return function 1", function() {
545 expect(Ext.typeOf(function(){})).toEqual('function');
546 });
547 // Don't run this test in IE
548 if (typeof alert === 'function') {
549 it("should return function 2", function() {
550 expect(Ext.typeOf(prompt)).toEqual('function');
551 });
552 }
553 it("should return function 3", function() {
554 expect(Ext.typeOf(new Function())).toEqual('function');
555 });
556 it("should return regexp 1", function() {
557 expect(Ext.typeOf(/test/)).toEqual('regexp');
558 });
559 it("should return regexp 2", function() {
560 expect(Ext.typeOf(new RegExp('test'))).toEqual('regexp');
561 });
562 it("should return date", function() {
563 expect(Ext.typeOf(new Date())).toEqual('date');
564 });
565 it("should return textnode", function() {
566 expect(Ext.typeOf(document.createTextNode('tada'))).toEqual('textnode');
567 });
568 it("should return whitespace", function() {
569 expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');
570 });
571 it("should return whitespace", function() {
572 expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');
573 });
574 it("should return element", function() {
575 expect(Ext.typeOf(document.getElementsByTagName('body')[0])).toEqual('element');
576 });
577 it("should return element", function() {
578 expect(Ext.typeOf(document.createElement('button'))).toEqual('element');
579 });
580 it("should return element", function() {
581 expect(Ext.typeOf(new Image())).toEqual('element');
582 });
583 it("should return object 1", function() {
584 expect(Ext.typeOf({some: 'stuff'})).toEqual('object');
585 });
586 it("should return object 2", function() {
587 expect(Ext.typeOf(new Object())).toEqual('object');
588 });
589 it("should return object 3", function() {
590 expect(Ext.typeOf(window)).toEqual('object');
591 });
592 it("should return boolean", function() {
593 expect(Ext.typeOf(new Boolean(true))).toEqual('boolean');
594 });
595 it("should return number", function() {
596 expect(Ext.typeOf(new Number(1.2))).toEqual('number');
597 });
598 });
599
600 describe("Ext.isIterable", function() {
601 it("should return true with empty array", function() {
602 expect(Ext.isIterable([])).toBe(true);
603 });
604
605 it("should return true with filled array", function() {
606 expect(Ext.isIterable([1, 2, 3, 4])).toBe(true);
607 });
608
609 it("should return false with boolean true", function() {
610 expect(Ext.isIterable(true)).toBe(false);
611 });
612
613 it("should return false with boolean false", function() {
614 expect(Ext.isIterable(false)).toBe(false);
615 });
616
617 it("should return false with string", function() {
618 expect(Ext.isIterable("foo")).toBe(false);
619 });
620
621 it("should return false with empty string", function() {
622 expect(Ext.isIterable("")).toBe(false);
623 });
624
625 it("should return false with number", function() {
626 expect(Ext.isIterable(1)).toBe(false);
627 });
628
629 it("should return false with null", function() {
630 expect(Ext.isIterable(null)).toBe(false);
631 });
632
633 it("should return false with undefined", function() {
634 expect(Ext.isIterable(undefined)).toBe(false);
635 });
636
637 it("should return false with date", function() {
638 expect(Ext.isIterable(new Date())).toBe(false);
639 });
640
641 it("should return false with empty object", function() {
642 expect(Ext.isIterable({})).toBe(false);
643 });
644
645 it("should return true with node list", function() {
646 expect(Ext.isIterable(document.getElementsByTagName('body'))).toBe(true);
647 });
648
649 it("should return true with html collection", function() {
650 expect(Ext.isIterable(document.images)).toBe(true);
651 });
652 });
653
654 describe("Ext.isArray", function() {
655 it("should return true with empty array", function() {
656 expect(Ext.isArray([])).toBe(true);
657 });
658
659 it("should return true with filled array", function() {
660 expect(Ext.isArray([1, 2, 3, 4])).toBe(true);
661 });
662
663 it("should return false with boolean true", function() {
664 expect(Ext.isArray(true)).toBe(false);
665 });
666
667 it("should return false with boolean false", function() {
668 expect(Ext.isArray(false)).toBe(false);
669 });
670
671 it("should return false with string", function() {
672 expect(Ext.isArray("foo")).toBe(false);
673 });
674
675 it("should return false with empty string", function() {
676 expect(Ext.isArray("")).toBe(false);
677 });
678
679 it("should return false with number", function() {
680 expect(Ext.isArray(1)).toBe(false);
681 });
682
683 it("should return false with null", function() {
684 expect(Ext.isArray(null)).toBe(false);
685 });
686
687 it("should return false with undefined", function() {
688 expect(Ext.isArray(undefined)).toBe(false);
689 });
690
691 it("should return false with date", function() {
692 expect(Ext.isArray(new Date())).toBe(false);
693 });
694
695 it("should return false with empty object", function() {
696 expect(Ext.isArray({})).toBe(false);
697 });
698
699 it("should return false with node list", function() {
700 expect(Ext.isArray(document.getElementsByTagName('body'))).toBe(false);
701 });
702
703 it("should return false with custom class that has a length property", function() {
704 var C = Ext.extend(Object, {
705 length: 1
706 });
707 expect(Ext.isArray(new C())).toBe(false);
708 });
709
710 it("should return false with element", function() {
711 expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
712 });
713 });
714
715 describe("Ext.isBoolean", function() {
716 it("should return false with empty array", function() {
717 expect(Ext.isBoolean([])).toBe(false);
718 });
719
720 it("should return false with filled array", function() {
721 expect(Ext.isBoolean([1, 2, 3, 4])).toBe(false);
722 });
723
724 it("should return true with boolean true", function() {
725 expect(Ext.isBoolean(true)).toBe(true);
726 });
727
728 it("should return true with boolean false", function() {
729 expect(Ext.isBoolean(false)).toBe(true);
730 });
731
732 it("should return false with string", function() {
733 expect(Ext.isBoolean("foo")).toBe(false);
734 });
735
736 it("should return false with empty string", function() {
737 expect(Ext.isBoolean("")).toBe(false);
738 });
739
740 it("should return false with number", function() {
741 expect(Ext.isBoolean(1)).toBe(false);
742 });
743
744 it("should return false with null", function() {
745 expect(Ext.isBoolean(null)).toBe(false);
746 });
747
748 it("should return false with undefined", function() {
749 expect(Ext.isBoolean(undefined)).toBe(false);
750 });
751
752 it("should return false with date", function() {
753 expect(Ext.isBoolean(new Date())).toBe(false);
754 });
755
756 it("should return false with empty object", function() {
757 expect(Ext.isBoolean({})).toBe(false);
758 });
759
760 it("should return false with node list", function() {
761 expect(Ext.isBoolean(document.getElementsByTagName('body'))).toBe(false);
762 });
763
764 it("should return false with element", function() {
765 expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
766 });
767 });
768
769 describe("Ext.isDate", function() {
770 it("should return false with empty array", function() {
771 expect(Ext.isDate([])).toBe(false);
772 });
773
774 it("should return false with filled array", function() {
775 expect(Ext.isDate([1, 2, 3, 4])).toBe(false);
776 });
777
778 it("should return false with boolean true", function() {
779 expect(Ext.isDate(true)).toBe(false);
780 });
781
782 it("should return false with boolean false", function() {
783 expect(Ext.isDate(false)).toBe(false);
784 });
785
786 it("should return false with string", function() {
787 expect(Ext.isDate("foo")).toBe(false);
788 });
789
790 it("should return false with empty string", function() {
791 expect(Ext.isDate("")).toBe(false);
792 });
793
794 it("should return false with number", function() {
795 expect(Ext.isDate(1)).toBe(false);
796 });
797
798 it("should return false with null", function() {
799 expect(Ext.isDate(null)).toBe(false);
800 });
801
802 it("should return false with undefined", function() {
803 expect(Ext.isDate(undefined)).toBe(false);
804 });
805
806 it("should return true with date", function() {
807 expect(Ext.isDate(new Date())).toBe(true);
808 });
809
810 it("should return false with empty object", function() {
811 expect(Ext.isDate({})).toBe(false);
812 });
813
814 it("should return false with node list", function() {
815 expect(Ext.isDate(document.getElementsByTagName('body'))).toBe(false);
816 });
817
818 it("should return false with element", function() {
819 expect(Ext.isDate(Ext.getBody().dom)).toBe(false);
820 });
821 });
822
823 describe("Ext.isDefined", function() {
824 it("should return true with empty array", function() {
825 expect(Ext.isDefined([])).toBe(true);
826 });
827
828 it("should return true with filled array", function() {
829 expect(Ext.isDefined([1, 2, 3, 4])).toBe(true);
830 });
831
832 it("should return true with boolean true", function() {
833 expect(Ext.isDefined(true)).toBe(true);
834 });
835
836 it("should return true with boolean false", function() {
837 expect(Ext.isDefined(false)).toBe(true);
838 });
839
840 it("should return true with string", function() {
841 expect(Ext.isDefined("foo")).toBe(true);
842 });
843
844 it("should return true with empty string", function() {
845 expect(Ext.isDefined("")).toBe(true);
846 });
847
848 it("should return true with number", function() {
849 expect(Ext.isDefined(1)).toBe(true);
850 });
851
852 it("should return true with null", function() {
853 expect(Ext.isDefined(null)).toBe(true);
854 });
855
856 it("should return false with undefined", function() {
857 expect(Ext.isDefined(undefined)).toBe(false);
858 });
859
860 it("should return true with date", function() {
861 expect(Ext.isDefined(new Date())).toBe(true);
862 });
863
864 it("should return true with empty object", function() {
865 expect(Ext.isDefined({})).toBe(true);
866 });
867
868 it("should return true with node list", function() {
869 expect(Ext.isDefined(document.getElementsByTagName('body'))).toBe(true);
870 });
871
872 it("should return true with element", function() {
873 expect(Ext.isDefined(Ext.getBody().dom)).toBe(true);
874 });
875 });
876
877 describe("Ext.isElement", function() {
878 it("should return false with empty array", function() {
879 expect(Ext.isElement([])).toBe(false);
880 });
881
882 it("should return false with filled array", function() {
883 expect(Ext.isElement([1, 2, 3, 4])).toBe(false);
884 });
885
886 it("should return false with boolean true", function() {
887 expect(Ext.isElement(true)).toBe(false);
888 });
889
890 it("should return false with boolean false", function() {
891 expect(Ext.isElement(false)).toBe(false);
892 });
893
894 it("should return false with string", function() {
895 expect(Ext.isElement("foo")).toBe(false);
896 });
897
898 it("should return false with empty string", function() {
899 expect(Ext.isElement("")).toBe(false);
900 });
901
902 it("should return false with number", function() {
903 expect(Ext.isElement(1)).toBe(false);
904 });
905
906 it("should return false with null", function() {
907 expect(Ext.isElement(null)).toBe(false);
908 });
909
910 it("should return false with undefined", function() {
911 expect(Ext.isElement(undefined)).toBe(false);
912 });
913
914 it("should return false with date", function() {
915 expect(Ext.isElement(new Date())).toBe(false);
916 });
917
918 it("should return false with empty object", function() {
919 expect(Ext.isElement({})).toBe(false);
920 });
921
922 it("should return false with node list", function() {
923 expect(Ext.isElement(document.getElementsByTagName('body'))).toBe(false);
924 });
925
926 it("should return true with element", function() {
927 expect(Ext.isElement(Ext.getBody().dom)).toBe(true);
928 });
929
930 it("should return false with Ext.Element", function() {
931 expect(Ext.isElement(Ext.getBody())).toBe(false);
932 });
933
934 it("should return false with TextNode", function() {
935 var textNode = document.createTextNode('foobar');
936 document.body.appendChild(textNode);
937 expect(Ext.isElement(textNode)).toBe(false);
938 document.body.removeChild(textNode);
939 });
940 });
941
942 describe("Ext.isEmpty", function() {
943 it("should return true with empty array", function() {
944 expect(Ext.isEmpty([])).toBe(true);
945 });
946
947 it("should return false with filled array", function() {
948 expect(Ext.isEmpty([1, 2, 3, 4])).toBe(false);
949 });
950
951 it("should return false with boolean true", function() {
952 expect(Ext.isEmpty(true)).toBe(false);
953 });
954
955 it("should return false with boolean false", function() {
956 expect(Ext.isEmpty(false)).toBe(false);
957 });
958
959 it("should return false with string", function() {
960 expect(Ext.isEmpty("foo")).toBe(false);
961 });
962
963 it("should return true with empty string", function() {
964 expect(Ext.isEmpty("")).toBe(true);
965 });
966
967 it("should return true with empty string with allowBlank", function() {
968 expect(Ext.isEmpty("", true)).toBe(false);
969 });
970
971 it("should return false with number", function() {
972 expect(Ext.isEmpty(1)).toBe(false);
973 });
974
975 it("should return true with null", function() {
976 expect(Ext.isEmpty(null)).toBe(true);
977 });
978
979 it("should return true with undefined", function() {
980 expect(Ext.isEmpty(undefined)).toBe(true);
981 });
982
983 it("should return false with date", function() {
984 expect(Ext.isEmpty(new Date())).toBe(false);
985 });
986
987 it("should return false with empty object", function() {
988 expect(Ext.isEmpty({})).toBe(false);
989 });
990 });
991
992 describe("Ext.isFunction", function() {
993 beforeEach(function() {
994 // add global variable in whitelist
995 addGlobal("ExtBox1");
996 });
997
998 it("should return true with anonymous function", function() {
999 expect(Ext.isFunction(function(){})).toBe(true);
1000 });
1001
1002 it("should return true with new Function syntax", function() {
1003 expect(Ext.isFunction(Ext.functionFactory('return "";'))).toBe(true);
1004 });
1005
1006 it("should return true with static function", function() {
1007 expect(Ext.isFunction(Ext.emptyFn)).toBe(true);
1008 });
1009
1010 it("should return true with instance function", function() {
1011 var stupidClass = function() {},
1012 testObject;
1013 stupidClass.prototype.testMe = function() {};
1014 testObject = new stupidClass();
1015
1016 expect(Ext.isFunction(testObject.testMe)).toBe(true);
1017 });
1018
1019 it("should return true with function on object", function() {
1020 var o = {
1021 fn: function() {
1022 }
1023 };
1024
1025 expect(Ext.isFunction(o.fn)).toBe(true);
1026 });
1027
1028 it("should return false with empty array", function() {
1029 expect(Ext.isFunction([])).toBe(false);
1030 });
1031
1032 it("should return false with filled array", function() {
1033 expect(Ext.isFunction([1, 2, 3, 4])).toBe(false);
1034 });
1035
1036 it("should return false with boolean true", function() {
1037 expect(Ext.isFunction(true)).toBe(false);
1038 });
1039
1040 it("should return false with boolean false", function() {
1041 expect(Ext.isFunction(false)).toBe(false);
1042 });
1043
1044 it("should return false with string", function() {
1045 expect(Ext.isFunction("foo")).toBe(false);
1046 });
1047
1048 it("should return false with empty string", function() {
1049 expect(Ext.isFunction("")).toBe(false);
1050 });
1051
1052 it("should return false with number", function() {
1053 expect(Ext.isFunction(1)).toBe(false);
1054 });
1055
1056 it("should return false with null", function() {
1057 expect(Ext.isFunction(null)).toBe(false);
1058 });
1059
1060 it("should return false with undefined", function() {
1061 expect(Ext.isFunction(undefined)).toBe(false);
1062 });
1063
1064 it("should return false with date", function() {
1065 expect(Ext.isFunction(new Date())).toBe(false);
1066 });
1067
1068 it("should return false with empty object", function() {
1069 expect(Ext.isFunction({})).toBe(false);
1070 });
1071
1072 it("should return false with node list", function() {
1073 expect(Ext.isFunction(document.getElementsByTagName('body'))).toBe(false);
1074 });
1075 });
1076
1077 describe("Ext.isNumber", function() {
1078 it("should return true with zero", function() {
1079 expect(Ext.isNumber(0)).toBe(true);
1080 });
1081
1082 it("should return true with non zero", function() {
1083 expect(Ext.isNumber(4)).toBe(true);
1084 });
1085
1086 it("should return true with negative integer", function() {
1087 expect(Ext.isNumber(-3)).toBe(true);
1088 });
1089
1090 it("should return true with float", function() {
1091 expect(Ext.isNumber(1.75)).toBe(true);
1092 });
1093
1094 it("should return true with negative float", function() {
1095 expect(Ext.isNumber(-4.75)).toBe(true);
1096 });
1097
1098 it("should return true with Number.MAX_VALUE", function() {
1099 expect(Ext.isNumber(Number.MAX_VALUE)).toBe(true);
1100 });
1101
1102 it("should return true with Number.MIN_VALUE", function() {
1103 expect(Ext.isNumber(Number.MIN_VALUE)).toBe(true);
1104 });
1105
1106 it("should return true with Math.PI", function() {
1107 expect(Ext.isNumber(Math.PI)).toBe(true);
1108 });
1109
1110 it("should return true with Number() contructor", function() {
1111 expect(Ext.isNumber(Number('3.1'))).toBe(true);
1112 });
1113
1114 it("should return false with NaN", function() {
1115 expect(Ext.isNumber(Number.NaN)).toBe(false);
1116 });
1117
1118 it("should return false with Number.POSITIVE_INFINITY", function() {
1119 expect(Ext.isNumber(Number.POSITIVE_INFINITY)).toBe(false);
1120 });
1121
1122 it("should return false with Number.NEGATIVE_INFINITY", function() {
1123 expect(Ext.isNumber(Number.NEGATIVE_INFINITY)).toBe(false);
1124 });
1125
1126 it("should return false with empty array", function() {
1127 expect(Ext.isNumber([])).toBe(false);
1128 });
1129
1130 it("should return false with filled array", function() {
1131 expect(Ext.isNumber([1, 2, 3, 4])).toBe(false);
1132 });
1133
1134 it("should return false with boolean true", function() {
1135 expect(Ext.isNumber(true)).toBe(false);
1136 });
1137
1138 it("should return false with boolean false", function() {
1139 expect(Ext.isNumber(false)).toBe(false);
1140 });
1141
1142 it("should return false with string", function() {
1143 expect(Ext.isNumber("foo")).toBe(false);
1144 });
1145
1146 it("should return false with empty string", function() {
1147 expect(Ext.isNumber("")).toBe(false);
1148 });
1149
1150 it("should return false with string containing a number", function() {
1151 expect(Ext.isNumber("1.0")).toBe(false);
1152 });
1153
1154 it("should return false with undefined", function() {
1155 expect(Ext.isNumber(undefined)).toBe(false);
1156 });
1157
1158 it("should return false with date", function() {
1159 expect(Ext.isNumber(new Date())).toBe(false);
1160 });
1161
1162 it("should return false with empty object", function() {
1163 expect(Ext.isNumber({})).toBe(false);
1164 });
1165
1166 it("should return false with node list", function() {
1167 expect(Ext.isNumber(document.getElementsByTagName('body'))).toBe(false);
1168 });
1169 });
1170
1171 describe("Ext.isNumeric", function() {
1172 it("should return true with zero", function() {
1173 expect(Ext.isNumeric(0)).toBe(true);
1174 });
1175
1176 it("should return true with non zero", function() {
1177 expect(Ext.isNumeric(4)).toBe(true);
1178 });
1179
1180 it("should return true with negative integer", function() {
1181 expect(Ext.isNumeric(-3)).toBe(true);
1182 });
1183
1184 it("should return true with float", function() {
1185 expect(Ext.isNumeric(1.75)).toBe(true);
1186 });
1187
1188 it("should return true with negative float", function() {
1189 expect(Ext.isNumeric(-4.75)).toBe(true);
1190 });
1191
1192 it("should return true with Number.MAX_VALUE", function() {
1193 expect(Ext.isNumeric(Number.MAX_VALUE)).toBe(true);
1194 });
1195
1196 it("should return true with Number.MIN_VALUE", function() {
1197 expect(Ext.isNumeric(Number.MIN_VALUE)).toBe(true);
1198 });
1199
1200 it("should return true with Math.PI", function() {
1201 expect(Ext.isNumeric(Math.PI)).toBe(true);
1202 });
1203
1204 it("should return true with Number() contructor", function() {
1205 expect(Ext.isNumeric(Number('3.1'))).toBe(true);
1206 });
1207
1208 it("should return false with NaN", function() {
1209 expect(Ext.isNumeric(Number.NaN)).toBe(false);
1210 });
1211
1212 it("should return false with Number.POSITIVE_INFINITY", function() {
1213 expect(Ext.isNumeric(Number.POSITIVE_INFINITY)).toBe(false);
1214 });
1215
1216 it("should return false with Number.NEGATIVE_INFINITY", function() {
1217 expect(Ext.isNumeric(Number.NEGATIVE_INFINITY)).toBe(false);
1218 });
1219
1220 it("should return false with empty array", function() {
1221 expect(Ext.isNumeric([])).toBe(false);
1222 });
1223
1224 it("should return false with filled array", function() {
1225 expect(Ext.isNumeric([1, 2, 3, 4])).toBe(false);
1226 });
1227
1228 it("should return false with boolean true", function() {
1229 expect(Ext.isNumeric(true)).toBe(false);
1230 });
1231
1232 it("should return false with boolean false", function() {
1233 expect(Ext.isNumeric(false)).toBe(false);
1234 });
1235
1236 it("should return false with string", function() {
1237 expect(Ext.isNumeric("foo")).toBe(false);
1238 });
1239
1240 it("should return false with empty string", function() {
1241 expect(Ext.isNumeric("")).toBe(false);
1242 });
1243
1244 it("should return true with string containing a number", function() {
1245 expect(Ext.isNumeric("1.0")).toBe(true);
1246 });
1247
1248 it("should return false with undefined", function() {
1249 expect(Ext.isNumeric(undefined)).toBe(false);
1250 });
1251
1252 it("should return false with date", function() {
1253 expect(Ext.isNumeric(new Date())).toBe(false);
1254 });
1255
1256 it("should return false with empty object", function() {
1257 expect(Ext.isNumeric({})).toBe(false);
1258 });
1259
1260 it("should return false with node list", function() {
1261 expect(Ext.isNumeric(document.getElementsByTagName('body'))).toBe(false);
1262 });
1263 });
1264
1265 describe("Ext.isObject", function() {
1266 it("should return false with empty array", function() {
1267 expect(Ext.isObject([])).toBe(false);
1268 });
1269
1270 it("should return false with filled array", function() {
1271 expect(Ext.isObject([1, 2, 3, 4])).toBe(false);
1272 });
1273
1274 it("should return false with boolean true", function() {
1275 expect(Ext.isObject(true)).toBe(false);
1276 });
1277
1278 it("should return false with boolean false", function() {
1279 expect(Ext.isObject(false)).toBe(false);
1280 });
1281
1282 it("should return false with string", function() {
1283 expect(Ext.isObject("foo")).toBe(false);
1284 });
1285
1286 it("should return false with empty string", function() {
1287 expect(Ext.isObject("")).toBe(false);
1288 });
1289
1290 it("should return false with number", function() {
1291 expect(Ext.isObject(1)).toBe(false);
1292 });
1293
1294 it("should return false with null", function() {
1295 expect(Ext.isObject(null)).toBe(false);
1296 });
1297
1298 it("should return false with undefined", function() {
1299 expect(Ext.isObject(undefined)).toBe(false);
1300 });
1301
1302 it("should return false with date", function() {
1303 expect(Ext.isObject(new Date())).toBe(false);
1304 });
1305
1306 it("should return true with empty object", function() {
1307 expect(Ext.isObject({})).toBe(true);
1308 });
1309
1310 it("should return false with a DOM node", function() {
1311 expect(Ext.isObject(document.body)).toBe(false);
1312 });
1313
1314 it("should return false with a Text node", function() {
1315 expect(Ext.isObject(document.createTextNode('test'))).toBe(false);
1316 });
1317
1318 it("should return true with object with properties", function() {
1319 expect(Ext.isObject({
1320 foo: 1
1321 })).toBe(true);
1322 });
1323
1324 it("should return true with object instance", function() {
1325 var stupidClass = function() {};
1326
1327 expect(Ext.isObject(new stupidClass())).toBe(true);
1328 });
1329
1330 it("should return true with new Object syntax", function() {
1331 expect(Ext.isObject(new Object())).toBe(true);
1332 });
1333
1334 it("should return false with dom element", function() {
1335 expect(Ext.isObject(document.body)).toBe(false);
1336 });
1337 });
1338
1339 describe("Ext.isPrimitive", function() {
1340 it("should return true with integer", function() {
1341 expect(Ext.isPrimitive(1)).toBe(true);
1342 });
1343
1344 it("should return true with negative integer", function() {
1345 expect(Ext.isPrimitive(-21)).toBe(true);
1346 });
1347
1348 it("should return true with float", function() {
1349 expect(Ext.isPrimitive(2.1)).toBe(true);
1350 });
1351
1352 it("should return true with negative float", function() {
1353 expect(Ext.isPrimitive(-12.1)).toBe(true);
1354 });
1355
1356 it("should return true with Number.MAX_VALUE", function() {
1357 expect(Ext.isPrimitive(Number.MAX_VALUE)).toBe(true);
1358 });
1359
1360 it("should return true with Math.PI", function() {
1361 expect(Ext.isPrimitive(Math.PI)).toBe(true);
1362 });
1363
1364 it("should return true with empty string", function() {
1365 expect(Ext.isPrimitive("")).toBe(true);
1366 });
1367
1368 it("should return true with non empty string", function() {
1369 expect(Ext.isPrimitive("foo")).toBe(true);
1370 });
1371
1372 it("should return true with boolean true", function() {
1373 expect(Ext.isPrimitive(true)).toBe(true);
1374 });
1375
1376 it("should return true with boolean false", function() {
1377 expect(Ext.isPrimitive(false)).toBe(true);
1378 });
1379
1380 it("should return false with null", function() {
1381 expect(Ext.isPrimitive(null)).toBe(false);
1382 });
1383
1384 it("should return false with undefined", function() {
1385 expect(Ext.isPrimitive(undefined)).toBe(false);
1386 });
1387
1388 it("should return false with object", function() {
1389 expect(Ext.isPrimitive({})).toBe(false);
1390 });
1391
1392 it("should return false with object instance", function() {
1393 var stupidClass = function() {};
1394 expect(Ext.isPrimitive(new stupidClass())).toBe(false);
1395 });
1396
1397 it("should return false with array", function() {
1398 expect(Ext.isPrimitive([])).toBe(false);
1399 });
1400 });
1401
1402 describe("Ext.isString", function() {
1403 it("should return true with empty string", function() {
1404 expect(Ext.isString("")).toBe(true);
1405 });
1406
1407 it("should return true with non empty string", function() {
1408 expect(Ext.isString("foo")).toBe(true);
1409 });
1410
1411 it("should return true with String() syntax", function() {
1412 expect(Ext.isString(String(""))).toBe(true);
1413 });
1414
1415 it("should return false with new String() syntax", function() { //should return an object that wraps the primitive
1416 expect(Ext.isString(new String(""))).toBe(false);
1417 });
1418
1419 it("should return false with number", function() {
1420 expect(Ext.isString(1)).toBe(false);
1421 });
1422
1423 it("should return false with boolean", function() {
1424 expect(Ext.isString(true)).toBe(false);
1425 });
1426
1427 it("should return false with null", function() {
1428 expect(Ext.isString(null)).toBe(false);
1429 });
1430
1431 it("should return false with undefined", function() {
1432 expect(Ext.isString(undefined)).toBe(false);
1433 });
1434
1435 it("should return false with array", function() {
1436 expect(Ext.isString([])).toBe(false);
1437 });
1438
1439 it("should return false with object", function() {
1440 expect(Ext.isString({})).toBe(false);
1441 });
1442 });
1443
1444 describe("Ext.isTextNode", function() {
1445 it("should return false with empty array", function() {
1446 expect(Ext.isTextNode([])).toBe(false);
1447 });
1448
1449 it("should return false with filled array", function() {
1450 expect(Ext.isTextNode([1, 2, 3, 4])).toBe(false);
1451 });
1452
1453 it("should return false with boolean true", function() {
1454 expect(Ext.isTextNode(true)).toBe(false);
1455 });
1456
1457 it("should return false with boolean false", function() {
1458 expect(Ext.isTextNode(false)).toBe(false);
1459 });
1460
1461 it("should return false with string", function() {
1462 expect(Ext.isTextNode("foo")).toBe(false);
1463 });
1464
1465 it("should return false with empty string", function() {
1466 expect(Ext.isTextNode("")).toBe(false);
1467 });
1468
1469 it("should return false with number", function() {
1470 expect(Ext.isTextNode(1)).toBe(false);
1471 });
1472
1473 it("should return false with null", function() {
1474 expect(Ext.isTextNode(null)).toBe(false);
1475 });
1476
1477 it("should return false with undefined", function() {
1478 expect(Ext.isTextNode(undefined)).toBe(false);
1479 });
1480
1481 it("should return false with date", function() {
1482 expect(Ext.isTextNode(new Date())).toBe(false);
1483 });
1484
1485 it("should return false with empty object", function() {
1486 expect(Ext.isTextNode({})).toBe(false);
1487 });
1488
1489 it("should return false with node list", function() {
1490 expect(Ext.isTextNode(document.getElementsByTagName('body'))).toBe(false);
1491 });
1492
1493 it("should return false with element", function() {
1494 expect(Ext.isTextNode(Ext.getBody().dom)).toBe(false);
1495 });
1496
1497 it("should return false with Ext.Element", function() {
1498 expect(Ext.isTextNode(Ext.getBody())).toBe(false);
1499 });
1500
1501 it("should return true with TextNode", function() {
1502 var textNode = document.createTextNode('foobar');
1503 document.body.appendChild(textNode);
1504 expect(Ext.isTextNode(textNode)).toBe(true);
1505 document.body.removeChild(textNode);
1506 });
1507 });
1508
1509 describe("Ext.clone", function() {
1510 var clone;
1511
1512 afterEach(function() {
1513 clone = null;
1514 });
1515
1516 it("should clone an array", function() {
1517 var array = [2,'5',[1,3,4]];
1518 clone = Ext.clone(array);
1519 expect(clone).toEqual(array);
1520 expect(clone).not.toBe(array);
1521 });
1522
1523 it("should clone an object", function() {
1524 var object = {
1525 fn: function() {
1526 return 1;
1527 },
1528 b: 2
1529 };
1530 clone = Ext.clone(object);
1531 expect(clone).toEqual(object);
1532 expect(clone).not.toBe(object);
1533 });
1534
1535 it("should clone a date", function(){
1536 var date = new Date();
1537 clone = Ext.clone(date);
1538 expect(clone).toEqual(date);
1539 expect(clone).not.toBe(date);
1540 });
1541
1542 it("should clone a dom node", function(){
1543 var node = document.createElement('DIV');
1544 document.body.appendChild(node);
1545 clone = Ext.clone(node);
1546 exp…
Large files files are truncated, but you can click here to view the full file