]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/Ext.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / Ext.js
CommitLineData
6527f429
DM
1describe("Ext", function() {\r
2\r
3 describe("Ext.global", function() {\r
4 it("should return the global scope", function() {\r
5 expect(Ext.global).toBe((function(){ return this;}).call());\r
6 });\r
7 });\r
8\r
9 describe("Ext.apply", function() {\r
10 var origin, o;\r
11\r
12 beforeEach(function() {\r
13 origin = {\r
14 name: 'value',\r
15 something: 'cool',\r
16 items: [1,2,3],\r
17 method: function() {\r
18 this.myMethodCalled = true;\r
19 },\r
20 toString: function() {\r
21 this.myToStringCalled = true;\r
22 }\r
23 };\r
24 });\r
25\r
26 it("should copy normal properties", function() {\r
27 Ext.apply(origin, {\r
28 name: 'newName',\r
29 items: [4,5,6],\r
30 otherThing: 'not cool',\r
31 isCool: false\r
32 });\r
33\r
34 expect(origin.name).toEqual('newName');\r
35 expect(origin.items).toEqual([4,5,6]);\r
36 expect(origin.something).toEqual('cool');\r
37 expect(origin.otherThing).toEqual('not cool');\r
38 expect(origin.isCool).toEqual(false);\r
39 });\r
40\r
41 it("should copy functions", function() {\r
42 Ext.apply(origin, {\r
43 method: function() {\r
44 this.newMethodCalled = true;\r
45 }\r
46 });\r
47\r
48 origin.method();\r
49\r
50 expect(origin.myMethodCalled).not.toBeDefined();\r
51 expect(origin.newMethodCalled).toBeTruthy();\r
52 });\r
53\r
54 it("should copy non-enumerables", function() {\r
55 Ext.apply(origin, {\r
56 toString: function() {\r
57 this.newToStringCalled = true;\r
58 }\r
59 });\r
60\r
61 origin.toString();\r
62\r
63 expect(origin.myToStringCalled).not.toBeDefined();\r
64 expect(origin.newToStringCalled).toBeTruthy();\r
65 });\r
66\r
67 it("should apply properties and return an object", function() {\r
68 o = Ext.apply({}, {\r
69 foo: 1,\r
70 bar: 2\r
71 });\r
72\r
73 expect(o).toEqual({\r
74 foo: 1,\r
75 bar: 2\r
76 });\r
77 });\r
78\r
79 it("should change the reference of the object", function() {\r
80 o = {};\r
81 Ext.apply(o, {\r
82 opt1: 'x',\r
83 opt2: 'y'\r
84 });\r
85\r
86 expect(o).toEqual({\r
87 opt1: 'x',\r
88 opt2: 'y'\r
89 });\r
90 });\r
91\r
92 it("should overwrite properties", function() {\r
93 o = Ext.apply({\r
94 foo: 1,\r
95 baz: 4\r
96 }, {\r
97 foo: 2,\r
98 bar: 3\r
99 });\r
100\r
101 expect(o).toEqual({\r
102 foo: 2,\r
103 bar: 3,\r
104 baz: 4\r
105 });\r
106 });\r
107\r
108 it("should use default", function() {\r
109 o = {};\r
110\r
111 Ext.apply(o, {\r
112 foo: 'new',\r
113 exist: true\r
114 }, {\r
115 foo: 'old',\r
116 def: true\r
117 });\r
118\r
119 expect(o).toEqual({\r
120 foo: 'new',\r
121 def: true,\r
122 exist: true\r
123 });\r
124 });\r
125\r
126 it("should override all defaults", function() {\r
127 o = Ext.apply({}, {\r
128 foo: 'foo',\r
129 bar: 'bar'\r
130 }, {\r
131 foo: 'oldFoo',\r
132 bar: 'oldBar'\r
133 });\r
134\r
135 expect(o).toEqual( {\r
136 foo: 'foo',\r
137 bar: 'bar'\r
138 });\r
139 });\r
140\r
141 it("should return null if null is passed as first argument", function() {\r
142 expect(Ext.apply(null, {})).toBeNull();\r
143 });\r
144\r
145 it("should return the object if second argument is not defined", function() {\r
146 o = {\r
147 foo: 1\r
148 };\r
149 expect(Ext.apply(o)).toEqual(o);\r
150 });\r
151\r
152 it("should override valueOf", function() {\r
153 o = Ext.apply({}, {valueOf: 1});\r
154\r
155 expect(o.valueOf).toEqual(1);\r
156 });\r
157\r
158 it("should override toString", function() {\r
159 o = Ext.apply({}, {toString: 3});\r
160\r
161 expect(o.toString).toEqual(3);\r
162\r
163 });\r
164 });\r
165\r
166 describe("Ext.emptyFn", function() {\r
167 it("should return undefined without params", function() {\r
168 expect(Ext.emptyFn()).toBeUndefined();\r
169 });\r
170\r
171 it("should return undefined if you pass params", function() {\r
172 expect(Ext.emptyFn('aaaa', 'bbbbb')).toBeUndefined();\r
173 });\r
174 });\r
175 \r
176 describe("Ext.iterate", function() {\r
177 var itFn;\r
178\r
179 beforeEach(function() {\r
180 itFn = jasmine.createSpy();\r
181 });\r
182\r
183 describe("iterate object", function() {\r
184 var o;\r
185\r
186 beforeEach(function() {\r
187 o = {\r
188 n1: 11,\r
189 n2: 13,\r
190 n3: 18\r
191 };\r
192 });\r
193\r
194 describe("if itFn does not return false", function() {\r
195 beforeEach(function() {\r
196 Ext.iterate(o, itFn);\r
197 });\r
198\r
199 it("should call the iterate function 3 times", function () {\r
200 expect(itFn.callCount).toEqual(3);\r
201 });\r
202\r
203 it("should call the iterate function with correct arguments", function () {\r
204 expect(itFn.calls[0].args).toEqual(["n1", 11, o]);\r
205 expect(itFn.calls[1].args).toEqual(["n2", 13, o]);\r
206 expect(itFn.calls[2].args).toEqual(["n3", 18, o]);\r
207 });\r
208 });\r
209\r
210 describe("if itFn return false", function() {\r
211 beforeEach(function() {\r
212 itFn.andReturn(false);\r
213 Ext.iterate(o, itFn);\r
214 });\r
215\r
216 it("should stop iteration if function return false", function() {\r
217 itFn.andReturn(false);\r
218\r
219 expect(itFn.calls.length).toEqual(1);\r
220 });\r
221 });\r
222 });\r
223\r
224 describe("do nothing on an empty object", function() {\r
225 var o;\r
226\r
227 beforeEach(function() {\r
228 o = {};\r
229 Ext.iterate(o, itFn);\r
230 });\r
231\r
232 it("should not call the iterate function", function () {\r
233 expect(itFn).not.toHaveBeenCalled();\r
234 });\r
235\r
236 });\r
237\r
238 describe("iterate array", function() {\r
239 var arr;\r
240\r
241 beforeEach(function() {\r
242 arr = [6, 7, 8, 9];\r
243 });\r
244\r
245 describe("if itFn does not return false", function() {\r
246 beforeEach(function() {\r
247 Ext.iterate(arr, itFn);\r
248 });\r
249\r
250 it("should call the iterate function 4 times", function () {\r
251 expect(itFn.callCount).toEqual(4);\r
252 });\r
253\r
254 it("should call the iterate function with correct arguments", function () {\r
255 expect(itFn.calls[0].args).toEqual([6, 0, arr]);\r
256 expect(itFn.calls[1].args).toEqual([7, 1, arr]);\r
257 expect(itFn.calls[2].args).toEqual([8, 2, arr]);\r
258 expect(itFn.calls[3].args).toEqual([9, 3, arr]);\r
259 });\r
260 });\r
261\r
262 describe("if itFn return false", function() {\r
263 beforeEach(function() {\r
264 itFn.andReturn(false);\r
265 Ext.iterate(arr, itFn);\r
266 });\r
267\r
268 it("should stop iteration if function return false", function() {\r
269 itFn.andReturn(false);\r
270\r
271 expect(itFn.calls.length).toEqual(1);\r
272 });\r
273 });\r
274 });\r
275\r
276 describe("do nothing on an empty array", function() {\r
277 var arr;\r
278\r
279 beforeEach(function() {\r
280 arr = [];\r
281 Ext.iterate(arr, itFn);\r
282 });\r
283\r
284 it("should not call the iterate function", function () {\r
285 expect(itFn).not.toHaveBeenCalled();\r
286 });\r
287\r
288 });\r
289 });\r
290\r
291 describe("Ext.applyIf", function(){\r
292 var o;\r
293\r
294 it("should apply properties and return an object with an empty destination object", function() {\r
295 o = Ext.applyIf({}, {\r
296 foo: 'foo',\r
297 bar: 'bar'\r
298 });\r
299\r
300 expect(o).toEqual( {\r
301 foo: 'foo',\r
302 bar: 'bar'\r
303 });\r
304 });\r
305\r
306 it("should not override default properties", function() {\r
307 o = Ext.applyIf({\r
308 foo: 'foo'\r
309 }, {\r
310 foo: 'oldFoo'\r
311 });\r
312\r
313 expect(o).toEqual({\r
314 foo: 'foo'\r
315 });\r
316 });\r
317\r
318 it("should not override default properties with mixing properties", function() {\r
319 o = Ext.applyIf({\r
320 foo: 1,\r
321 bar: 2\r
322 }, {\r
323 bar: 3,\r
324 baz: 4\r
325 });\r
326\r
327 expect(o).toEqual({\r
328 foo: 1,\r
329 bar: 2,\r
330 baz: 4\r
331 });\r
332 });\r
333\r
334 it("should change the reference of the object", function() {\r
335 o = {};\r
336 Ext.applyIf(o, {\r
337 foo: 2\r
338 }, {\r
339 foo: 1\r
340 });\r
341\r
342 expect(o).toEqual({\r
343 foo: 2\r
344 });\r
345 });\r
346\r
347 it("should return null if null is passed as first argument", function() {\r
348 expect(Ext.applyIf(null, {})).toBeNull();\r
349 });\r
350\r
351 it("should return the object if second argument is no defined", function() {\r
352 o = {\r
353 foo: 1\r
354 };\r
355\r
356 expect(Ext.applyIf(o)).toEqual(o);\r
357 });\r
358 });\r
359\r
360\r
361 describe("Ext.extend", function() {\r
362 describe("class creation", function () {\r
363 var Child, Parent, baz;\r
364\r
365 Parent = Ext.extend(Object, {\r
366 constructor: function(config){\r
367 Ext.apply(this, config);\r
368 this.foobar = false;\r
369 }\r
370 });\r
371\r
372 Child = Ext.extend(Parent, {\r
373 constructor: function(){\r
374 Child.superclass.constructor.apply(this, arguments);\r
375 this.foobar = true;\r
376 }\r
377 });\r
378\r
379 baz = new Child({\r
380 sencha: 'isAwesome'\r
381 });\r
382\r
383 it("should throw an error if superclass isn't defined", function() {\r
384 expect(function() {\r
385 Ext.extend(undefined, {});\r
386 }).toThrow("Attempting to extend from a class which has not been loaded on the page.");\r
387 });\r
388\r
389 it("should create a superclass that refers to its (usually unreachable) parent prototype", function() {\r
390 expect(baz.superclass).toEqual(Parent.prototype);\r
391 });\r
392\r
393 it("should add override method", function() {\r
394 expect(typeof baz.override === 'function').toBe(true);\r
395 });\r
396\r
397 it("should override redefined methods", function() {\r
398 expect(baz.foobar).toBe(true);\r
399 });\r
400\r
401 it("should keep new properties", function() {\r
402 expect(baz.sencha).toEqual('isAwesome');\r
403 });\r
404 });\r
405\r
406 describe("constructors", function () {\r
407 // Extending Object\r
408 var A = function () {\r
409 A.superclass.constructor.call(this);\r
410 this.data = 'a';\r
411 };\r
412 Ext.extend(A, Object, {});\r
413\r
414 // Extending class created via 3 argument form using 3 arg form\r
415 var B = function () {\r
416 B.superclass.constructor.call(this);\r
417 this.data += 'b';\r
418 };\r
419 Ext.extend(B, A, {});\r
420\r
421 // Extending class produced via 3 argument form using 2 argument form\r
422 var C = Ext.extend(B, {\r
423 constructor: function () {\r
424 C.superclass.constructor.call(this);\r
425 this.data += 'c';\r
426 }\r
427 });\r
428\r
429 // Extending class produced via 2 argument form using 2 argument form\r
430 var D = Ext.extend(C, {\r
431 constructor: function () {\r
432 D.superclass.constructor.call(this);\r
433 this.data += 'd';\r
434 }\r
435 });\r
436\r
437 // Extending again using 3 argument form\r
438 var E = function () {\r
439 E.superclass.constructor.call(this);\r
440 this.data += 'e';\r
441 };\r
442 Ext.extend(E, D, {});\r
443\r
444 it("should call each constructor ", function () {\r
445 var instance = new E();\r
446 expect(instance.data).toBe('abcde');\r
447 });\r
448\r
449 it("should correctly set the constructor", function () {\r
450 expect(E.superclass.constructor).toEqual(D.prototype.constructor);\r
451 expect(D.superclass.constructor).toEqual(C.prototype.constructor);\r
452 expect(C.superclass.constructor).toEqual(B);\r
453 expect(B.superclass.constructor).toEqual(A);\r
454 });\r
455 });\r
456\r
457 describe("derive from Ext.define'd base", function () {\r
458 var A = Ext.define(null, {\r
459 constructor: function () {\r
460 this.data = 'a';\r
461 }\r
462 });\r
463\r
464 // Extending class created via 3 argument form using 3 arg form\r
465 var B = function () {\r
466 B.superclass.constructor.call(this);\r
467 this.data += 'b';\r
468 };\r
469 Ext.extend(B, A, {});\r
470\r
471 // Extending class produced via 3 argument form using 2 argument form\r
472 var C = Ext.extend(B, {\r
473 constructor: function () {\r
474 C.superclass.constructor.call(this);\r
475 this.data += 'c';\r
476 }\r
477 });\r
478\r
479 // Extending class produced via 2 argument form using 2 argument form\r
480 var D = Ext.extend(C, {\r
481 constructor: function () {\r
482 D.superclass.constructor.call(this);\r
483 this.data += 'd';\r
484 }\r
485 });\r
486\r
487 // Extending again using 3 argument form\r
488 var E = function () {\r
489 E.superclass.constructor.call(this);\r
490 this.data += 'e';\r
491 };\r
492 Ext.extend(E, D, {});\r
493\r
494 it("should call each constructor ", function () {\r
495 var instance = new E();\r
496 expect(instance.data).toBe('abcde');\r
497 });\r
498\r
499 it("should correctly set the constructor", function () {\r
500 expect(E.superclass.constructor).toEqual(D.prototype.constructor);\r
501 expect(D.superclass.constructor).toEqual(C.prototype.constructor);\r
502 expect(C.superclass.constructor).toEqual(B);\r
503 expect(B.superclass.constructor).toEqual(A.prototype.constructor);\r
504 });\r
505 });\r
506 });\r
507\r
508 describe("Ext.override", function(){\r
509 describe("on a raw JS class", function() {\r
510 it("should override existing methods and add new methods to the prototype", function(){\r
511 var Cls = function() {},\r
512 fn1 = function() {},\r
513 fn2 = function() {},\r
514 fn3 = function() {},\r
515 fn4 = function() {};\r
516\r
517 Cls.prototype.foo = fn1;\r
518 Cls.prototype.baz = fn2;\r
519\r
520 Ext.override(Cls, {\r
521 foo: fn3,\r
522 bar: fn4\r
523 });\r
524\r
525 expect(Cls.prototype.foo).toBe(fn3);\r
526 expect(Cls.prototype.bar).toBe(fn4);\r
527 expect(Cls.prototype.baz).toBe(fn2);\r
528 });\r
529 });\r
530\r
531 describe("on an Ext class", function() {\r
532 it("should overwrite existing methods", function() {\r
533 var fn1 = function() {},\r
534 fn2 = function() {};\r
535\r
536 var Cls = Ext.define(null, {\r
537 foo: fn1\r
538 });\r
539\r
540 expect(Cls.prototype.foo).toBe(fn1);\r
541\r
542 Ext.override(Cls, {\r
543 foo: fn2\r
544 });\r
545\r
546 expect(Cls.prototype.foo).toBe(fn2);\r
547 });\r
548\r
549 it("should add new methods", function() {\r
550 var fn1 = function() {},\r
551 fn2 = function() {};\r
552\r
553 var Cls = Ext.define(null, {\r
554 foo: fn1\r
555 });\r
556\r
557 expect(Cls.prototype.bar).toBeUndefined();\r
558\r
559 Ext.override(Cls, {\r
560 bar: fn2\r
561 });\r
562\r
563 expect(Cls.prototype.foo).toBe(fn1);\r
564 expect(Cls.prototype.bar).toBe(fn2);\r
565 });\r
566\r
567 it("should be able to override privates", function() {\r
568 var fn1 = function() {},\r
569 fn2 = function() {};\r
570\r
571 var Cls = Ext.define(null, {\r
572 privates: {\r
573 foo: fn1\r
574 }\r
575 });\r
576\r
577 expect(Cls.prototype.foo).toBe(fn1);\r
578\r
579 Ext.override(Cls, {\r
580 privates: {\r
581 foo: fn2\r
582 }\r
583 });\r
584\r
585 expect(Cls.prototype.foo).toBe(fn2);\r
586 });\r
587\r
588 it("should be able to override statics", function() {\r
589 var fn1 = function() {},\r
590 fn2 = function() {};\r
591\r
592 var Cls = Ext.define(null, {\r
593 statics: {\r
594 foo: fn1\r
595 }\r
596 });\r
597\r
598 expect(Cls.foo).toBe(fn1);\r
599\r
600 Ext.override(Cls, {\r
601 statics: {\r
602 foo: fn2\r
603 }\r
604 });\r
605\r
606 expect(Cls.foo).toBe(fn2);\r
607 });\r
608\r
609 it("should be able to override static privates", function() {\r
610 var fn1 = function() {},\r
611 fn2 = function() {};\r
612\r
613 var Cls = Ext.define(null, {\r
614 privates: {\r
615 statics: {\r
616 foo: fn1\r
617 }\r
618 }\r
619 });\r
620\r
621 expect(Cls.foo).toBe(fn1);\r
622\r
623 Ext.override(Cls, {\r
624 privates: {\r
625 statics: {\r
626 foo: fn2\r
627 }\r
628 }\r
629 });\r
630\r
631 expect(Cls.foo).toBe(fn2);\r
632 });\r
633\r
634 it("should be able to callParent()", function() {\r
635 var Cls = Ext.define(null, {\r
636 doIt: function() {\r
637 return 100;\r
638 }\r
639 });\r
640\r
641 Ext.override(Cls, {\r
642 doIt: function() {\r
643 return this.callParent() + 1;\r
644 }\r
645 });\r
646\r
647 var o = new Cls();\r
648 expect(o.doIt()).toBe(101);\r
649 });\r
650 });\r
651\r
652 describe("on an Ext class instance", function() {\r
653 it("should write methods to the instance, but not the prototype", function() {\r
654 var fn1 = function() {},\r
655 fn2 = function() {};\r
656\r
657 var Cls = Ext.define(null, {\r
658 foo: fn1\r
659 });\r
660\r
661 var o = new Cls();\r
662\r
663 Ext.override(o, {\r
664 foo: fn2\r
665 });\r
666\r
667 expect(o.foo).toBe(fn2);\r
668 expect(o.self.prototype.foo).toBe(fn1);\r
669 });\r
670\r
671 it("should add new methods to the instance, not the prototype", function() {\r
672 var fn1 = function() {};\r
673\r
674 var Cls = Ext.define(null, {});\r
675\r
676 var o = new Cls();\r
677\r
678 Ext.override(o, {\r
679 foo: fn1\r
680 });\r
681\r
682 expect(o.foo).toBe(fn1);\r
683 expect(o.self.prototype.foo).toBeUndefined();\r
684 });\r
685\r
686 it("should be able to override privates", function() {\r
687 var fn1 = function() {},\r
688 fn2 = function() {};\r
689\r
690 var Cls = Ext.define(null, {\r
691 privates: {\r
692 foo: fn1\r
693 }\r
694 });\r
695\r
696 var o = new Cls();\r
697\r
698 Ext.override(o, {\r
699 privates: {\r
700 foo: fn2\r
701 }\r
702 });\r
703\r
704 expect(o.foo).toBe(fn2);\r
705 expect(o.self.prototype.foo).toBe(fn1);\r
706 });\r
707\r
708 it("should be able to callParent()", function() {\r
709 var Cls = Ext.define(null, {\r
710 doIt: function() {\r
711 return 100;\r
712 }\r
713 });\r
714\r
715 var o = new Cls();\r
716\r
717 Ext.override(o, {\r
718 doIt: function() {\r
719 return this.callParent() + 1;\r
720 }\r
721 });\r
722 expect(o.doIt()).toBe(101);\r
723 });\r
724 });\r
725 });\r
726\r
727 describe("Ext.valueFrom", function() {\r
728 var value, defaultValue;\r
729\r
730 describe("with allowBlank", function() {\r
731 describe("and an empty string", function() {\r
732 it("should return the value", function() {\r
733 expect(Ext.valueFrom('', 'aaa', true)).toBe('');\r
734 });\r
735 });\r
736\r
737 describe("and a string", function() {\r
738 it("should return the value", function() {\r
739 expect(Ext.valueFrom('bbb', 'aaa', true)).toBe('bbb');\r
740 });\r
741 });\r
742\r
743 describe("and an undefined value", function() {\r
744 it("should return the default value", function() {\r
745 expect(Ext.valueFrom(undefined, 'aaa', true)).toBe('aaa');\r
746 });\r
747 });\r
748\r
749 describe("and a null value", function() {\r
750 it("should return the default value", function() {\r
751 expect(Ext.valueFrom(null, 'aaa', true)).toBe('aaa');\r
752 });\r
753 });\r
754\r
755 describe("and a 0 value", function() {\r
756 it("should return the value", function() {\r
757 expect(Ext.valueFrom(0, 'aaa', true)).toBe(0);\r
758 });\r
759 });\r
760 });\r
761\r
762 describe("without allowBlank", function() {\r
763 describe("and an empty string", function() {\r
764 it("should return the default value", function() {\r
765 expect(Ext.valueFrom('', 'aaa')).toBe('aaa');\r
766 });\r
767 });\r
768\r
769 describe("and a string", function() {\r
770 it("should return the value", function() {\r
771 expect(Ext.valueFrom('bbb', 'aaa')).toBe('bbb');\r
772 });\r
773 });\r
774\r
775 describe("and an undefined value", function() {\r
776 it("should return the default value", function() {\r
777 expect(Ext.valueFrom(undefined, 'aaa')).toBe('aaa');\r
778 });\r
779 });\r
780\r
781 describe("and a null value", function() {\r
782 it("should return the default value", function() {\r
783 expect(Ext.valueFrom(null, 'aaa')).toBe('aaa');\r
784 });\r
785 });\r
786\r
787 describe("and a 0 value", function() {\r
788 it("should return the value", function() {\r
789 expect(Ext.valueFrom(0, 'aaa')).toBe(0);\r
790 });\r
791 });\r
792 });\r
793 });\r
794\r
795 describe("Ext.typeOf", function() {\r
796 \r
797 it("should return null", function() {\r
798 expect(Ext.typeOf(null)).toEqual('null');\r
799 });\r
800 \r
801 it("should return undefined", function() {\r
802 expect(Ext.typeOf(undefined)).toEqual('undefined');\r
803 expect(Ext.typeOf(window.someWeirdPropertyThatDoesntExist)).toEqual('undefined');\r
804 });\r
805\r
806\r
807 it("should return string", function() {\r
808 expect(Ext.typeOf('')).toEqual('string');\r
809 expect(Ext.typeOf('something')).toEqual('string');\r
810 expect(Ext.typeOf('1.2')).toEqual('string');\r
811 });\r
812\r
813 it("should return number", function() {\r
814 expect(Ext.typeOf(1)).toEqual('number');\r
815 expect(Ext.typeOf(1.2)).toEqual('number');\r
816 expect(Ext.typeOf(new Number(1.2))).toEqual('number');\r
817 });\r
818\r
819\r
820 it("should return boolean", function() {\r
821 expect(Ext.typeOf(true)).toEqual('boolean');\r
822 expect(Ext.typeOf(false)).toEqual('boolean');\r
823 expect(Ext.typeOf(new Boolean(true))).toEqual('boolean');\r
824 });\r
825 \r
826\r
827 it("should return array", function() {\r
828 expect(Ext.typeOf([1,2,3])).toEqual('array');\r
829 expect(Ext.typeOf(new Array(1,2,3))).toEqual('array');\r
830 });\r
831 \r
832 it("should return function", function() {\r
833 expect(Ext.typeOf(function(){})).toEqual('function');\r
834 expect(Ext.typeOf(new Function())).toEqual('function');\r
835 expect(Ext.typeOf(Object)).toEqual('function');\r
836 expect(Ext.typeOf(Array)).toEqual('function');\r
837 expect(Ext.typeOf(Number)).toEqual('function');\r
838 expect(Ext.typeOf(Function)).toEqual('function');\r
839 expect(Ext.typeOf(Boolean)).toEqual('function');\r
840 expect(Ext.typeOf(String)).toEqual('function');\r
841 expect(Ext.typeOf(Date)).toEqual('function');\r
842 expect(Ext.typeOf(Ext.typeOf)).toEqual('function');\r
843\r
844 // In IE certain native functions come back as objects, e.g. alert, prompt and document.getElementById. It\r
845 // isn't clear exactly what correct behaviour should be in those cases as attempting to treat them like\r
846 // normal functions can causes various problems. Some, like document.getElementBy, have call and apply\r
847 // methods so in most cases will behave like any other function. It might be possible to detect them by\r
848 // using something like this:\r
849 //\r
850 // if (typeof obj === 'object' && !obj.toString && obj.call && obj.apply && (obj + '')) {...}\r
851 });\r
852 \r
853 it("should return regexp", function() {\r
854 expect(Ext.typeOf(/test/)).toEqual('regexp');\r
855 expect(Ext.typeOf(new RegExp('test'))).toEqual('regexp');\r
856 });\r
857\r
858 it("should return date", function() {\r
859 expect(Ext.typeOf(new Date())).toEqual('date');\r
860 });\r
861 \r
862 it("should return textnode", function() {\r
863 expect(Ext.typeOf(document.createTextNode('tada'))).toEqual('textnode');\r
864 expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');\r
865 expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');\r
866 });\r
867\r
868 it("should return element", function() {\r
869 expect(Ext.typeOf(document.getElementsByTagName('body')[0])).toEqual('element');\r
870 expect(Ext.typeOf(document.createElement('button'))).toEqual('element');\r
871 expect(Ext.typeOf(new Image())).toEqual('element');\r
872 });\r
873\r
874 it("should return object", function() {\r
875 expect(Ext.typeOf({some: 'stuff'})).toEqual('object');\r
876 expect(Ext.typeOf(new Object())).toEqual('object');\r
877 expect(Ext.typeOf(window)).toEqual('object');\r
878 });\r
879\r
880 });\r
881\r
882 describe("Ext.isIterable", function() {\r
883 var LengthyClass = function(){},\r
884 ClassWithItem = function(){},\r
885 LengthyItemClass = function(){};\r
886\r
887 LengthyClass.prototype.length = 1;\r
888 ClassWithItem.prototype.item = function(){};\r
889 LengthyItemClass.prototype.length = 1;\r
890 LengthyItemClass.prototype.item = function(){};\r
891\r
892 it("should return true with an arguments object", function() {\r
893 expect(Ext.isIterable(arguments)).toBe(true);\r
894 });\r
895\r
896 it("should return true with empty array", function() {\r
897 expect(Ext.isIterable([])).toBe(true);\r
898 });\r
899\r
900 it("should return true with filled array", function() {\r
901 expect(Ext.isIterable([1, 2, 3, 4])).toBe(true);\r
902 });\r
903\r
904 it("should return false with boolean true", function() {\r
905 expect(Ext.isIterable(true)).toBe(false);\r
906 });\r
907\r
908 it("should return false with boolean false", function() {\r
909 expect(Ext.isIterable(false)).toBe(false);\r
910 });\r
911\r
912 it("should return false with string", function() {\r
913 expect(Ext.isIterable("foo")).toBe(false);\r
914 });\r
915\r
916 it("should return false with empty string", function() {\r
917 expect(Ext.isIterable("")).toBe(false);\r
918 });\r
919\r
920 it("should return false with number", function() {\r
921 expect(Ext.isIterable(1)).toBe(false);\r
922 });\r
923\r
924 it("should return false with null", function() {\r
925 expect(Ext.isIterable(null)).toBe(false);\r
926 });\r
927\r
928 it("should return false with undefined", function() {\r
929 expect(Ext.isIterable(undefined)).toBe(false);\r
930 });\r
931\r
932 it("should return false with date", function() {\r
933 expect(Ext.isIterable(new Date())).toBe(false);\r
934 });\r
935\r
936 it("should return false with empty object", function() {\r
937 expect(Ext.isIterable({})).toBe(false);\r
938 });\r
939\r
940 it("should return true with node list", function() {\r
941 expect(Ext.isIterable(document.getElementsByTagName('body'))).toBe(true);\r
942 });\r
943\r
944 it("should return true with html collection", function() {\r
945 expect(Ext.isIterable(document.images)).toBe(true);\r
946 });\r
947 \r
948 it("should return false for a function", function(){\r
949 expect(Ext.isIterable(function(){})).toBe(false);\r
950 });\r
951\r
952 it('should return false for objects with a length property', function() {\r
953 expect(Ext.isIterable({length:1})).toBe(false);\r
954 });\r
955\r
956 it('should return false for objects with an item property', function() {\r
957 expect(Ext.isIterable({item: function(){}})).toBe(false);\r
958 });\r
959 \r
960 it('should return false for objects with a length prototype property', function() {\r
961 expect(Ext.isIterable(new LengthyClass())).toBe(false);\r
962 });\r
963 \r
964 it('should return false for objects with an item prototype property', function() {\r
965 expect(Ext.isIterable(new ClassWithItem())).toBe(false);\r
966 });\r
967 \r
968 it('should return false for objects with item and length prototype properties', function() {\r
969 expect(Ext.isIterable(new LengthyItemClass())).toBe(false);\r
970 });\r
971\r
972 it('should return true for arguments object', function() {\r
973 expect(Ext.isIterable(arguments)).toBe(true);\r
974 });\r
975\r
976 describe('stylesheets', function() {\r
977 var styleEl;\r
978\r
979 beforeEach(function() {\r
980 // if the test index page has no stylesheets, then document.styleSheets\r
981 // will be undefined. Create a style element to make sure\r
982 // document.styleSheets is a StyleSheetList\r
983 styleEl = document.createElement('style');\r
984 document.body.appendChild(styleEl);\r
985 });\r
986\r
987 afterEach(function() {\r
988 document.body.removeChild(styleEl);\r
989 });\r
990\r
991 it('should return true for StyleSheetList', function() {\r
992 expect(Ext.isIterable(document.styleSheets)).toBe(true);\r
993 });\r
994\r
995 it('should return true for CSSRuleList', function() {\r
996 expect(Ext.isIterable(document.styleSheets[0].cssRules || document.styleSheets[0].rules)).toBe(true);\r
997 });\r
998 });\r
999 });\r
1000\r
1001 describe("Ext.isArray", function() {\r
1002 it("should return true with empty array", function() {\r
1003 expect(Ext.isArray([])).toBe(true);\r
1004 });\r
1005\r
1006 it("should return true with filled array", function() {\r
1007 expect(Ext.isArray([1, 2, 3, 4])).toBe(true);\r
1008 });\r
1009\r
1010 it("should return false with boolean true", function() {\r
1011 expect(Ext.isArray(true)).toBe(false);\r
1012 });\r
1013\r
1014 it("should return false with boolean false", function() {\r
1015 expect(Ext.isArray(false)).toBe(false);\r
1016 });\r
1017\r
1018 it("should return false with string", function() {\r
1019 expect(Ext.isArray("foo")).toBe(false);\r
1020 });\r
1021\r
1022 it("should return false with empty string", function() {\r
1023 expect(Ext.isArray("")).toBe(false);\r
1024 });\r
1025\r
1026 it("should return false with number", function() {\r
1027 expect(Ext.isArray(1)).toBe(false);\r
1028 });\r
1029\r
1030 it("should return false with null", function() {\r
1031 expect(Ext.isArray(null)).toBe(false);\r
1032 });\r
1033\r
1034 it("should return false with undefined", function() {\r
1035 expect(Ext.isArray(undefined)).toBe(false);\r
1036 });\r
1037\r
1038 it("should return false with date", function() {\r
1039 expect(Ext.isArray(new Date())).toBe(false);\r
1040 });\r
1041\r
1042 it("should return false with empty object", function() {\r
1043 expect(Ext.isArray({})).toBe(false);\r
1044 });\r
1045\r
1046 it("should return false with node list", function() {\r
1047 expect(Ext.isArray(document.getElementsByTagName('body'))).toBe(false);\r
1048 });\r
1049\r
1050 it("should return false with custom class that has a length property", function() {\r
1051 var C = Ext.extend(Object, {\r
1052 length: 1\r
1053 });\r
1054 expect(Ext.isArray(new C())).toBe(false);\r
1055 });\r
1056\r
1057 it("should return false with element", function() {\r
1058 expect(Ext.isArray(document.body)).toBe(false);\r
1059 });\r
1060 });\r
1061\r
1062 describe("Ext.isBoolean", function() {\r
1063 it("should return false with empty array", function() {\r
1064 expect(Ext.isBoolean([])).toBe(false);\r
1065 });\r
1066\r
1067 it("should return false with filled array", function() {\r
1068 expect(Ext.isBoolean([1, 2, 3, 4])).toBe(false);\r
1069 });\r
1070\r
1071 it("should return true with boolean true", function() {\r
1072 expect(Ext.isBoolean(true)).toBe(true);\r
1073 });\r
1074\r
1075 it("should return true with boolean false", function() {\r
1076 expect(Ext.isBoolean(false)).toBe(true);\r
1077 });\r
1078\r
1079 it("should return false with string", function() {\r
1080 expect(Ext.isBoolean("foo")).toBe(false);\r
1081 });\r
1082\r
1083 it("should return false with empty string", function() {\r
1084 expect(Ext.isBoolean("")).toBe(false);\r
1085 });\r
1086\r
1087 it("should return false with number", function() {\r
1088 expect(Ext.isBoolean(1)).toBe(false);\r
1089 });\r
1090\r
1091 it("should return false with null", function() {\r
1092 expect(Ext.isBoolean(null)).toBe(false);\r
1093 });\r
1094\r
1095 it("should return false with undefined", function() {\r
1096 expect(Ext.isBoolean(undefined)).toBe(false);\r
1097 });\r
1098\r
1099 it("should return false with date", function() {\r
1100 expect(Ext.isBoolean(new Date())).toBe(false);\r
1101 });\r
1102\r
1103 it("should return false with empty object", function() {\r
1104 expect(Ext.isBoolean({})).toBe(false);\r
1105 });\r
1106\r
1107 it("should return false with node list", function() {\r
1108 expect(Ext.isBoolean(document.getElementsByTagName('body'))).toBe(false);\r
1109 });\r
1110\r
1111 it("should return false with element", function() {\r
1112 expect(Ext.isArray(document.body)).toBe(false);\r
1113 });\r
1114 });\r
1115\r
1116 describe("Ext.isDate", function() {\r
1117 it("should return false with empty array", function() {\r
1118 expect(Ext.isDate([])).toBe(false);\r
1119 });\r
1120\r
1121 it("should return false with filled array", function() {\r
1122 expect(Ext.isDate([1, 2, 3, 4])).toBe(false);\r
1123 });\r
1124\r
1125 it("should return false with boolean true", function() {\r
1126 expect(Ext.isDate(true)).toBe(false);\r
1127 });\r
1128\r
1129 it("should return false with boolean false", function() {\r
1130 expect(Ext.isDate(false)).toBe(false);\r
1131 });\r
1132\r
1133 it("should return false with string", function() {\r
1134 expect(Ext.isDate("foo")).toBe(false);\r
1135 });\r
1136\r
1137 it("should return false with empty string", function() {\r
1138 expect(Ext.isDate("")).toBe(false);\r
1139 });\r
1140\r
1141 it("should return false with number", function() {\r
1142 expect(Ext.isDate(1)).toBe(false);\r
1143 });\r
1144\r
1145 it("should return false with null", function() {\r
1146 expect(Ext.isDate(null)).toBe(false);\r
1147 });\r
1148\r
1149 it("should return false with undefined", function() {\r
1150 expect(Ext.isDate(undefined)).toBe(false);\r
1151 });\r
1152\r
1153 it("should return true with date", function() {\r
1154 expect(Ext.isDate(new Date())).toBe(true);\r
1155 });\r
1156\r
1157 it("should return false with empty object", function() {\r
1158 expect(Ext.isDate({})).toBe(false);\r
1159 });\r
1160\r
1161 it("should return false with node list", function() {\r
1162 expect(Ext.isDate(document.getElementsByTagName('body'))).toBe(false);\r
1163 });\r
1164\r
1165 it("should return false with element", function() {\r
1166 expect(Ext.isDate(document.body)).toBe(false);\r
1167 });\r
1168 });\r
1169\r
1170 describe("Ext.isDefined", function() {\r
1171 it("should return true with empty array", function() {\r
1172 expect(Ext.isDefined([])).toBe(true);\r
1173 });\r
1174\r
1175 it("should return true with filled array", function() {\r
1176 expect(Ext.isDefined([1, 2, 3, 4])).toBe(true);\r
1177 });\r
1178\r
1179 it("should return true with boolean true", function() {\r
1180 expect(Ext.isDefined(true)).toBe(true);\r
1181 });\r
1182\r
1183 it("should return true with boolean false", function() {\r
1184 expect(Ext.isDefined(false)).toBe(true);\r
1185 });\r
1186\r
1187 it("should return true with string", function() {\r
1188 expect(Ext.isDefined("foo")).toBe(true);\r
1189 });\r
1190\r
1191 it("should return true with empty string", function() {\r
1192 expect(Ext.isDefined("")).toBe(true);\r
1193 });\r
1194\r
1195 it("should return true with number", function() {\r
1196 expect(Ext.isDefined(1)).toBe(true);\r
1197 });\r
1198\r
1199 it("should return true with null", function() {\r
1200 expect(Ext.isDefined(null)).toBe(true);\r
1201 });\r
1202\r
1203 it("should return false with undefined", function() {\r
1204 expect(Ext.isDefined(undefined)).toBe(false);\r
1205 });\r
1206\r
1207 it("should return true with date", function() {\r
1208 expect(Ext.isDefined(new Date())).toBe(true);\r
1209 });\r
1210\r
1211 it("should return true with empty object", function() {\r
1212 expect(Ext.isDefined({})).toBe(true);\r
1213 });\r
1214\r
1215 it("should return true with node list", function() {\r
1216 expect(Ext.isDefined(document.getElementsByTagName('body'))).toBe(true);\r
1217 });\r
1218\r
1219 it("should return true with element", function() {\r
1220 expect(Ext.isDefined(document.body)).toBe(true);\r
1221 });\r
1222 });\r
1223\r
1224 describe("Ext.isElement", function() {\r
1225 it("should return false with empty array", function() {\r
1226 expect(Ext.isElement([])).toBe(false);\r
1227 });\r
1228\r
1229 it("should return false with filled array", function() {\r
1230 expect(Ext.isElement([1, 2, 3, 4])).toBe(false);\r
1231 });\r
1232\r
1233 it("should return false with boolean true", function() {\r
1234 expect(Ext.isElement(true)).toBe(false);\r
1235 });\r
1236\r
1237 it("should return false with boolean false", function() {\r
1238 expect(Ext.isElement(false)).toBe(false);\r
1239 });\r
1240\r
1241 it("should return false with string", function() {\r
1242 expect(Ext.isElement("foo")).toBe(false);\r
1243 });\r
1244\r
1245 it("should return false with empty string", function() {\r
1246 expect(Ext.isElement("")).toBe(false);\r
1247 });\r
1248\r
1249 it("should return false with number", function() {\r
1250 expect(Ext.isElement(1)).toBe(false);\r
1251 });\r
1252\r
1253 it("should return false with null", function() {\r
1254 expect(Ext.isElement(null)).toBe(false);\r
1255 });\r
1256\r
1257 it("should return false with undefined", function() {\r
1258 expect(Ext.isElement(undefined)).toBe(false);\r
1259 });\r
1260\r
1261 it("should return false with date", function() {\r
1262 expect(Ext.isElement(new Date())).toBe(false);\r
1263 });\r
1264\r
1265 it("should return false with empty object", function() {\r
1266 expect(Ext.isElement({})).toBe(false);\r
1267 });\r
1268\r
1269 it("should return false with node list", function() {\r
1270 expect(Ext.isElement(document.getElementsByTagName('body'))).toBe(false);\r
1271 });\r
1272\r
1273 it("should return true with element", function() {\r
1274 expect(Ext.isElement(document.body)).toBe(true);\r
1275 });\r
1276\r
1277 it("should return false with TextNode", function() {\r
1278 var textNode = document.createTextNode('foobar');\r
1279 document.body.appendChild(textNode);\r
1280 expect(Ext.isElement(textNode)).toBe(false);\r
1281 document.body.removeChild(textNode);\r
1282 });\r
1283 });\r
1284\r
1285 describe("Ext.isEmpty", function() {\r
1286 it("should return true with empty array", function() {\r
1287 expect(Ext.isEmpty([])).toBe(true);\r
1288 });\r
1289\r
1290 it("should return false with filled array", function() {\r
1291 expect(Ext.isEmpty([1, 2, 3, 4])).toBe(false);\r
1292 });\r
1293\r
1294 it("should return false with boolean true", function() {\r
1295 expect(Ext.isEmpty(true)).toBe(false);\r
1296 });\r
1297\r
1298 it("should return false with boolean false", function() {\r
1299 expect(Ext.isEmpty(false)).toBe(false);\r
1300 });\r
1301\r
1302 it("should return false with string", function() {\r
1303 expect(Ext.isEmpty("foo")).toBe(false);\r
1304 });\r
1305\r
1306 it("should return true with empty string", function() {\r
1307 expect(Ext.isEmpty("")).toBe(true);\r
1308 });\r
1309\r
1310 it("should return true with empty string with allowBlank", function() {\r
1311 expect(Ext.isEmpty("", true)).toBe(false);\r
1312 });\r
1313\r
1314 it("should return false with number", function() {\r
1315 expect(Ext.isEmpty(1)).toBe(false);\r
1316 });\r
1317\r
1318 it("should return true with null", function() {\r
1319 expect(Ext.isEmpty(null)).toBe(true);\r
1320 });\r
1321\r
1322 it("should return true with undefined", function() {\r
1323 expect(Ext.isEmpty(undefined)).toBe(true);\r
1324 });\r
1325\r
1326 it("should return false with date", function() {\r
1327 expect(Ext.isEmpty(new Date())).toBe(false);\r
1328 });\r
1329\r
1330 it("should return false with empty object", function() {\r
1331 expect(Ext.isEmpty({})).toBe(false);\r
1332 });\r
1333 });\r
1334\r
1335 describe("Ext.isFunction", function() {\r
1336 it("should return true with anonymous function", function() {\r
1337 expect(Ext.isFunction(function(){})).toBe(true);\r
1338 });\r
1339\r
1340 it("should return true with new Function syntax", function() {\r
1341 expect(Ext.isFunction(Ext.functionFactory('return "";'))).toBe(true);\r
1342 });\r
1343\r
1344 it("should return true with static function", function() {\r
1345 expect(Ext.isFunction(Ext.emptyFn)).toBe(true);\r
1346 });\r
1347\r
1348 it("should return true with instance function", function() {\r
1349 var stupidClass = function() {},\r
1350 testObject;\r
1351 stupidClass.prototype.testMe = function() {};\r
1352 testObject = new stupidClass();\r
1353\r
1354 expect(Ext.isFunction(testObject.testMe)).toBe(true);\r
1355 });\r
1356\r
1357 it("should return true with function on object", function() {\r
1358 var o = {\r
1359 fn: function() {\r
1360 }\r
1361 };\r
1362\r
1363 expect(Ext.isFunction(o.fn)).toBe(true);\r
1364 });\r
1365\r
1366 it("should return false with empty array", function() {\r
1367 expect(Ext.isFunction([])).toBe(false);\r
1368 });\r
1369\r
1370 it("should return false with filled array", function() {\r
1371 expect(Ext.isFunction([1, 2, 3, 4])).toBe(false);\r
1372 });\r
1373\r
1374 it("should return false with boolean true", function() {\r
1375 expect(Ext.isFunction(true)).toBe(false);\r
1376 });\r
1377\r
1378 it("should return false with boolean false", function() {\r
1379 expect(Ext.isFunction(false)).toBe(false);\r
1380 });\r
1381\r
1382 it("should return false with string", function() {\r
1383 expect(Ext.isFunction("foo")).toBe(false);\r
1384 });\r
1385\r
1386 it("should return false with empty string", function() {\r
1387 expect(Ext.isFunction("")).toBe(false);\r
1388 });\r
1389\r
1390 it("should return false with number", function() {\r
1391 expect(Ext.isFunction(1)).toBe(false);\r
1392 });\r
1393\r
1394 it("should return false with null", function() {\r
1395 expect(Ext.isFunction(null)).toBe(false);\r
1396 });\r
1397\r
1398 it("should return false with undefined", function() {\r
1399 expect(Ext.isFunction(undefined)).toBe(false);\r
1400 });\r
1401\r
1402 it("should return false with date", function() {\r
1403 expect(Ext.isFunction(new Date())).toBe(false);\r
1404 });\r
1405\r
1406 it("should return false with empty object", function() {\r
1407 expect(Ext.isFunction({})).toBe(false);\r
1408 });\r
1409\r
1410 it("should return false with node list", function() {\r
1411 expect(Ext.isFunction(document.getElementsByTagName('body'))).toBe(false);\r
1412 });\r
1413 \r
1414 it("should return true with a function from a document where Ext isn't loaded", function() {\r
1415 var iframe = document.createElement('iframe'),\r
1416 win, doc;\r
1417\r
1418 iframe.src = 'about:blank';\r
1419 document.body.appendChild(iframe);\r
1420 \r
1421 doc = iframe.contentDocument ? iframe.contentDocument : (iframe.contentWindow.document || iframe.document);\r
1422 win = iframe.contentWindow || iframe.window;\r
1423 \r
1424 doc.open();\r
1425 doc.write('<html><head><script type="text/javascript">function customFn() {}</script></head><body></body></html>');\r
1426 doc.close();\r
1427 \r
1428 expect(Ext.isFunction(win.customFn)).toBe(true);\r
1429 document.body.removeChild(iframe);\r
1430 iframe = doc = win = null;\r
1431 });\r
1432 });\r
1433\r
1434 describe("Ext.isNumber", function() {\r
1435 it("should return true with zero", function() {\r
1436 expect(Ext.isNumber(0)).toBe(true);\r
1437 });\r
1438\r
1439 it("should return true with non zero", function() {\r
1440 expect(Ext.isNumber(4)).toBe(true);\r
1441 });\r
1442\r
1443 it("should return true with negative integer", function() {\r
1444 expect(Ext.isNumber(-3)).toBe(true);\r
1445 });\r
1446\r
1447 it("should return true with float", function() {\r
1448 expect(Ext.isNumber(1.75)).toBe(true);\r
1449 });\r
1450\r
1451 it("should return true with negative float", function() {\r
1452 expect(Ext.isNumber(-4.75)).toBe(true);\r
1453 });\r
1454\r
1455 it("should return true with Number.MAX_VALUE", function() {\r
1456 expect(Ext.isNumber(Number.MAX_VALUE)).toBe(true);\r
1457 });\r
1458\r
1459 it("should return true with Number.MIN_VALUE", function() {\r
1460 expect(Ext.isNumber(Number.MIN_VALUE)).toBe(true);\r
1461 });\r
1462\r
1463 it("should return true with Math.PI", function() {\r
1464 expect(Ext.isNumber(Math.PI)).toBe(true);\r
1465 });\r
1466\r
1467 it("should return true with Number() contructor", function() {\r
1468 expect(Ext.isNumber(Number('3.1'))).toBe(true);\r
1469 });\r
1470\r
1471 it("should return false with NaN", function() {\r
1472 expect(Ext.isNumber(Number.NaN)).toBe(false);\r
1473 });\r
1474\r
1475 it("should return false with Number.POSITIVE_INFINITY", function() {\r
1476 expect(Ext.isNumber(Number.POSITIVE_INFINITY)).toBe(false);\r
1477 });\r
1478\r
1479 it("should return false with Number.NEGATIVE_INFINITY", function() {\r
1480 expect(Ext.isNumber(Number.NEGATIVE_INFINITY)).toBe(false);\r
1481 });\r
1482\r
1483 it("should return false with empty array", function() {\r
1484 expect(Ext.isNumber([])).toBe(false);\r
1485 });\r
1486\r
1487 it("should return false with filled array", function() {\r
1488 expect(Ext.isNumber([1, 2, 3, 4])).toBe(false);\r
1489 });\r
1490\r
1491 it("should return false with boolean true", function() {\r
1492 expect(Ext.isNumber(true)).toBe(false);\r
1493 });\r
1494\r
1495 it("should return false with boolean false", function() {\r
1496 expect(Ext.isNumber(false)).toBe(false);\r
1497 });\r
1498\r
1499 it("should return false with string", function() {\r
1500 expect(Ext.isNumber("foo")).toBe(false);\r
1501 });\r
1502\r
1503 it("should return false with empty string", function() {\r
1504 expect(Ext.isNumber("")).toBe(false);\r
1505 });\r
1506\r
1507 it("should return false with string containing a number", function() {\r
1508 expect(Ext.isNumber("1.0")).toBe(false);\r
1509 });\r
1510\r
1511 it("should return false with undefined", function() {\r
1512 expect(Ext.isNumber(undefined)).toBe(false);\r
1513 });\r
1514\r
1515 it("should return false with date", function() {\r
1516 expect(Ext.isNumber(new Date())).toBe(false);\r
1517 });\r
1518\r
1519 it("should return false with empty object", function() {\r
1520 expect(Ext.isNumber({})).toBe(false);\r
1521 });\r
1522\r
1523 it("should return false with node list", function() {\r
1524 expect(Ext.isNumber(document.getElementsByTagName('body'))).toBe(false);\r
1525 });\r
1526 });\r
1527\r
1528 describe("Ext.isNumeric", function() {\r
1529 it("should return true with zero", function() {\r
1530 expect(Ext.isNumeric(0)).toBe(true);\r
1531 });\r
1532\r
1533 it("should return true with non zero", function() {\r
1534 expect(Ext.isNumeric(4)).toBe(true);\r
1535 });\r
1536\r
1537 it("should return true with negative integer", function() {\r
1538 expect(Ext.isNumeric(-3)).toBe(true);\r
1539 });\r
1540\r
1541 it("should return true with float", function() {\r
1542 expect(Ext.isNumeric(1.75)).toBe(true);\r
1543 });\r
1544\r
1545 it("should return true with negative float", function() {\r
1546 expect(Ext.isNumeric(-4.75)).toBe(true);\r
1547 });\r
1548\r
1549 it("should return true with Number.MAX_VALUE", function() {\r
1550 expect(Ext.isNumeric(Number.MAX_VALUE)).toBe(true);\r
1551 });\r
1552\r
1553 it("should return true with Number.MIN_VALUE", function() {\r
1554 expect(Ext.isNumeric(Number.MIN_VALUE)).toBe(true);\r
1555 });\r
1556\r
1557 it("should return true with Math.PI", function() {\r
1558 expect(Ext.isNumeric(Math.PI)).toBe(true);\r
1559 });\r
1560\r
1561 it("should return true with Number() contructor", function() {\r
1562 expect(Ext.isNumeric(Number('3.1'))).toBe(true);\r
1563 });\r
1564\r
1565 it("should return false with NaN", function() {\r
1566 expect(Ext.isNumeric(Number.NaN)).toBe(false);\r
1567 });\r
1568\r
1569 it("should return false with Number.POSITIVE_INFINITY", function() {\r
1570 expect(Ext.isNumeric(Number.POSITIVE_INFINITY)).toBe(false);\r
1571 });\r
1572\r
1573 it("should return false with Number.NEGATIVE_INFINITY", function() {\r
1574 expect(Ext.isNumeric(Number.NEGATIVE_INFINITY)).toBe(false);\r
1575 });\r
1576\r
1577 it("should return false with empty array", function() {\r
1578 expect(Ext.isNumeric([])).toBe(false);\r
1579 });\r
1580\r
1581 it("should return false with filled array", function() {\r
1582 expect(Ext.isNumeric([1, 2, 3, 4])).toBe(false);\r
1583 });\r
1584\r
1585 it("should return false with boolean true", function() {\r
1586 expect(Ext.isNumeric(true)).toBe(false);\r
1587 });\r
1588\r
1589 it("should return false with boolean false", function() {\r
1590 expect(Ext.isNumeric(false)).toBe(false);\r
1591 });\r
1592\r
1593 it("should return false with string", function() {\r
1594 expect(Ext.isNumeric("foo")).toBe(false);\r
1595 });\r
1596\r
1597 it("should return false with empty string", function() {\r
1598 expect(Ext.isNumeric("")).toBe(false);\r
1599 });\r
1600\r
1601 it("should return true with string containing a number", function() {\r
1602 expect(Ext.isNumeric("1.0")).toBe(true);\r
1603 });\r
1604\r
1605 it("should return false with undefined", function() {\r
1606 expect(Ext.isNumeric(undefined)).toBe(false);\r
1607 });\r
1608\r
1609 it("should return false with date", function() {\r
1610 expect(Ext.isNumeric(new Date())).toBe(false);\r
1611 });\r
1612\r
1613 it("should return false with empty object", function() {\r
1614 expect(Ext.isNumeric({})).toBe(false);\r
1615 });\r
1616\r
1617 it("should return false with node list", function() {\r
1618 expect(Ext.isNumeric(document.getElementsByTagName('body'))).toBe(false);\r
1619 });\r
1620 });\r
1621\r
1622 describe("Ext.isObject", function() {\r
1623 it("should return false with empty array", function() {\r
1624 expect(Ext.isObject([])).toBe(false);\r
1625 });\r
1626\r
1627 it("should return false with filled array", function() {\r
1628 expect(Ext.isObject([1, 2, 3, 4])).toBe(false);\r
1629 });\r
1630\r
1631 it("should return false with boolean true", function() {\r
1632 expect(Ext.isObject(true)).toBe(false);\r
1633 });\r
1634\r
1635 it("should return false with boolean false", function() {\r
1636 expect(Ext.isObject(false)).toBe(false);\r
1637 });\r
1638\r
1639 it("should return false with string", function() {\r
1640 expect(Ext.isObject("foo")).toBe(false);\r
1641 });\r
1642\r
1643 it("should return false with empty string", function() {\r
1644 expect(Ext.isObject("")).toBe(false);\r
1645 });\r
1646\r
1647 it("should return false with number", function() {\r
1648 expect(Ext.isObject(1)).toBe(false);\r
1649 });\r
1650\r
1651 it("should return false with null", function() {\r
1652 expect(Ext.isObject(null)).toBe(false);\r
1653 });\r
1654\r
1655 it("should return false with undefined", function() {\r
1656 expect(Ext.isObject(undefined)).toBe(false);\r
1657 });\r
1658\r
1659 it("should return false with date", function() {\r
1660 expect(Ext.isObject(new Date())).toBe(false);\r
1661 });\r
1662\r
1663 it("should return true with empty object", function() {\r
1664 expect(Ext.isObject({})).toBe(true);\r
1665 });\r
1666\r
1667 it("should return false with a DOM node", function() {\r
1668 expect(Ext.isObject(document.body)).toBe(false);\r
1669 });\r
1670\r
1671 it("should return false with a Text node", function() {\r
1672 expect(Ext.isObject(document.createTextNode('test'))).toBe(false);\r
1673 });\r
1674\r
1675 it("should return true with object with properties", function() {\r
1676 expect(Ext.isObject({\r
1677 foo: 1\r
1678 })).toBe(true);\r
1679 });\r
1680\r
1681 it("should return true with object instance", function() {\r
1682 var stupidClass = function() {};\r
1683\r
1684 expect(Ext.isObject(new stupidClass())).toBe(true);\r
1685 });\r
1686\r
1687 it("should return true with new Object syntax", function() {\r
1688 expect(Ext.isObject(new Object())).toBe(true);\r
1689 });\r
1690\r
1691 it("should return false with dom element", function() {\r
1692 expect(Ext.isObject(document.body)).toBe(false);\r
1693 });\r
1694 });\r
1695\r
1696 describe("Ext.isPrimitive", function() {\r
1697 it("should return true with integer", function() {\r
1698 expect(Ext.isPrimitive(1)).toBe(true);\r
1699 });\r
1700\r
1701 it("should return true with negative integer", function() {\r
1702 expect(Ext.isPrimitive(-21)).toBe(true);\r
1703 });\r
1704\r
1705 it("should return true with float", function() {\r
1706 expect(Ext.isPrimitive(2.1)).toBe(true);\r
1707 });\r
1708\r
1709 it("should return true with negative float", function() {\r
1710 expect(Ext.isPrimitive(-12.1)).toBe(true);\r
1711 });\r
1712\r
1713 it("should return true with Number.MAX_VALUE", function() {\r
1714 expect(Ext.isPrimitive(Number.MAX_VALUE)).toBe(true);\r
1715 });\r
1716\r
1717 it("should return true with Math.PI", function() {\r
1718 expect(Ext.isPrimitive(Math.PI)).toBe(true);\r
1719 });\r
1720\r
1721 it("should return true with empty string", function() {\r
1722 expect(Ext.isPrimitive("")).toBe(true);\r
1723 });\r
1724\r
1725 it("should return true with non empty string", function() {\r
1726 expect(Ext.isPrimitive("foo")).toBe(true);\r
1727 });\r
1728\r
1729 it("should return true with boolean true", function() {\r
1730 expect(Ext.isPrimitive(true)).toBe(true);\r
1731 });\r
1732\r
1733 it("should return true with boolean false", function() {\r
1734 expect(Ext.isPrimitive(false)).toBe(true);\r
1735 });\r
1736\r
1737 it("should return false with null", function() {\r
1738 expect(Ext.isPrimitive(null)).toBe(false);\r
1739 });\r
1740\r
1741 it("should return false with undefined", function() {\r
1742 expect(Ext.isPrimitive(undefined)).toBe(false);\r
1743 });\r
1744\r
1745 it("should return false with object", function() {\r
1746 expect(Ext.isPrimitive({})).toBe(false);\r
1747 });\r
1748\r
1749 it("should return false with object instance", function() {\r
1750 var stupidClass = function() {};\r
1751 expect(Ext.isPrimitive(new stupidClass())).toBe(false);\r
1752 });\r
1753\r
1754 it("should return false with array", function() {\r
1755 expect(Ext.isPrimitive([])).toBe(false);\r
1756 });\r
1757 });\r
1758\r
1759 describe("Ext.isString", function() {\r
1760 it("should return true with empty string", function() {\r
1761 expect(Ext.isString("")).toBe(true);\r
1762 });\r
1763\r
1764 it("should return true with non empty string", function() {\r
1765 expect(Ext.isString("foo")).toBe(true);\r
1766 });\r
1767\r
1768 it("should return true with String() syntax", function() {\r
1769 expect(Ext.isString(String(""))).toBe(true);\r
1770 });\r
1771\r
1772 it("should return false with new String() syntax", function() { //should return an object that wraps the primitive\r
1773 expect(Ext.isString(new String(""))).toBe(false);\r
1774 });\r
1775\r
1776 it("should return false with number", function() {\r
1777 expect(Ext.isString(1)).toBe(false);\r
1778 });\r
1779\r
1780 it("should return false with boolean", function() {\r
1781 expect(Ext.isString(true)).toBe(false);\r
1782 });\r
1783\r
1784 it("should return false with null", function() {\r
1785 expect(Ext.isString(null)).toBe(false);\r
1786 });\r
1787\r
1788 it("should return false with undefined", function() {\r
1789 expect(Ext.isString(undefined)).toBe(false);\r
1790 });\r
1791\r
1792 it("should return false with array", function() {\r
1793 expect(Ext.isString([])).toBe(false);\r
1794 });\r
1795\r
1796 it("should return false with object", function() {\r
1797 expect(Ext.isString({})).toBe(false);\r
1798 });\r
1799 });\r
1800\r
1801 describe("Ext.isTextNode", function() {\r
1802 it("should return false with empty array", function() {\r
1803 expect(Ext.isTextNode([])).toBe(false);\r
1804 });\r
1805\r
1806 it("should return false with filled array", function() {\r
1807 expect(Ext.isTextNode([1, 2, 3, 4])).toBe(false);\r
1808 });\r
1809\r
1810 it("should return false with boolean true", function() {\r
1811 expect(Ext.isTextNode(true)).toBe(false);\r
1812 });\r
1813\r
1814 it("should return false with boolean false", function() {\r
1815 expect(Ext.isTextNode(false)).toBe(false);\r
1816 });\r
1817\r
1818 it("should return false with string", function() {\r
1819 expect(Ext.isTextNode("foo")).toBe(false);\r
1820 });\r
1821\r
1822 it("should return false with empty string", function() {\r
1823 expect(Ext.isTextNode("")).toBe(false);\r
1824 });\r
1825\r
1826 it("should return false with number", function() {\r
1827 expect(Ext.isTextNode(1)).toBe(false);\r
1828 });\r
1829\r
1830 it("should return false with null", function() {\r
1831 expect(Ext.isTextNode(null)).toBe(false);\r
1832 });\r
1833\r
1834 it("should return false with undefined", function() {\r
1835 expect(Ext.isTextNode(undefined)).toBe(false);\r
1836 });\r
1837\r
1838 it("should return false with date", function() {\r
1839 expect(Ext.isTextNode(new Date())).toBe(false);\r
1840 });\r
1841\r
1842 it("should return false with empty object", function() {\r
1843 expect(Ext.isTextNode({})).toBe(false);\r
1844 });\r
1845\r
1846 it("should return false with node list", function() {\r
1847 expect(Ext.isTextNode(document.getElementsByTagName('body'))).toBe(false);\r
1848 });\r
1849\r
1850 it("should return false with element", function() {\r
1851 expect(Ext.isTextNode(document.body)).toBe(false);\r
1852 });\r
1853\r
1854 it("should return true with TextNode", function() {\r
1855 var textNode = document.createTextNode('foobar');\r
1856 document.body.appendChild(textNode);\r
1857 expect(Ext.isTextNode(textNode)).toBe(true);\r
1858 document.body.removeChild(textNode);\r
1859 });\r
1860 });\r
1861\r
1862 describe("Ext.clone", function() {\r
1863 var clone;\r
1864\r
1865 afterEach(function() {\r
1866 clone = null;\r
1867 });\r
1868\r
1869 it("should clone an array", function() {\r
1870 var array = [2,'5',[1,3,4]];\r
1871 clone = Ext.clone(array);\r
1872 expect(clone).toEqual(array);\r
1873 expect(clone).not.toBe(array);\r
1874 });\r
1875\r
1876 it("should clone an object", function() {\r
1877 var object = {\r
1878 fn: function() {\r
1879 return 1;\r
1880 },\r
1881 b: 2\r
1882 };\r
1883 clone = Ext.clone(object);\r
1884 expect(clone).toEqual(object);\r
1885 expect(clone).not.toBe(object);\r
1886 });\r
1887\r
1888 it("should clone a date", function(){\r
1889 var date = new Date();\r
1890 clone = Ext.clone(date);\r
1891 expect(clone).toEqual(date);\r
1892 expect(clone).not.toBe(date);\r
1893 });\r
1894\r
1895 it("should clone a dom node", function(){\r
1896 var node = document.createElement('DIV');\r
1897 document.body.appendChild(node);\r
1898 clone = Ext.clone(node);\r
1899 expect(clone.tagName).toEqual(clone.tagName);\r
1900 expect(clone.innerHTML).toEqual(clone.innerHTML);\r
1901 expect(clone).not.toBe(node);\r
1902 document.body.removeChild(node);\r
1903 });\r
1904 \r
1905 it("should return null for null items", function() {\r
1906 expect(Ext.clone(null)).toBeNull();\r
1907 });\r
1908 \r
1909 it("should return undefined for undefined items", function() {\r
1910 expect(Ext.clone(undefined)).toBeUndefined();\r
1911 });\r
1912\r
1913 it("should not copy Ext.enumerable properties onto cloned object", function() {\r
1914 expect(Ext.clone({}).hasOwnProperty('toString')).toBe(false);\r
1915 });\r
1916\r
1917 it("should copy same-named Ext.enumerable property onto cloned object", function() {\r
1918 expect(Ext.clone({toString: true}).hasOwnProperty('toString')).toBe(true);\r
1919 expect(Ext.clone({toString: true}).hasOwnProperty('valueOf')).toBe(false);\r
1920 });\r
1921 });\r
1922\r
1923 describe('getUniqueGlobalNamespace', function() {\r
1924 it("should return an unique global namespace", function() {\r
1925 expect(Ext.getUniqueGlobalNamespace()).toBe("ExtBox1");\r
1926 try {\r
1927 delete window.ExtBox1;\r
1928 } catch(e) {\r
1929 window.ExtBox1 = undefined;\r
1930 }\r
1931 });\r
1932 });\r
1933\r
1934 describe("elevateFunction", function() {\r
1935 // Note that there could be other timers called by the framework that could call the\r
1936 // Ext.elevateFunction wrapper. As such, we need to be sure that our function has been\r
1937 // called and not worry about any other timers that could have been queued up. We use\r
1938 // the local `elevated` var for this purpose.\r
1939 var elevated = false;\r
1940\r
1941 beforeEach(function() {\r
1942 Ext.elevateFunction = function(fn, scope, args) {\r
1943 var ret;\r
1944\r
1945 elevated = true;\r
1946 ret = fn.apply(scope, args || []);\r
1947 elevated = false;\r
1948 return ret;\r
1949 };\r
1950 });\r
1951\r
1952 afterEach(function() {\r
1953 Ext.elevateFunction = null;\r
1954 elevated = false;\r
1955 });\r
1956\r
1957 it("should call the elevateFunction when the onReadyEvent fires", function() {\r
1958 var Ready = Ext.env.Ready,\r
1959 fakeEvent = { type: 'load' },\r
1960 args;\r
1961\r
1962 spyOn(Ext, 'elevateFunction');\r
1963 Ready.onReadyEvent(fakeEvent);\r
1964 expect(Ext.elevateFunction.callCount).toBe(1);\r
1965 args = Ext.elevateFunction.mostRecentCall.args;\r
1966 expect(args[0]).toBe(Ready.doReadyEvent);\r
1967 expect(args[1]).toBe(Ready);\r
1968 expect(args[2].length).toBe(1);\r
1969 expect(args[2][0]).toBe(fakeEvent);\r
1970 });\r
1971\r
1972 it("should call the elevateFunction when a delegated dom event is fired", function() {\r
1973 var domPublisher = Ext.event.publisher.Dom.instance,\r
1974 fakeEvent = { type: 'click' },\r
1975 args;\r
1976\r
1977 spyOn(Ext, 'elevateFunction');\r
1978 domPublisher.onDelegatedEvent(fakeEvent);\r
1979 expect(Ext.elevateFunction.callCount).toBe(1);\r
1980 args = Ext.elevateFunction.mostRecentCall.args;\r
1981 expect(args[0]).toBe(domPublisher.self.prototype.doDelegatedEvent);\r
1982 expect(args[1]).toBe(domPublisher);\r
1983 expect(args[2].length).toBe(1);\r
1984 expect(args[2][0]).toBe(fakeEvent);\r
1985 });\r
1986\r
1987 it("should call the elevateFunction when a direct dom event is fired", function() {\r
1988 var domPublisher = Ext.event.publisher.Dom.instance,\r
1989 fakeEvent = { type: 'click' },\r
1990 args;\r
1991\r
1992 spyOn(Ext, 'elevateFunction');\r
1993 domPublisher.onDirectEvent(fakeEvent);\r
1994 expect(Ext.elevateFunction.callCount).toBe(1);\r
1995 args = Ext.elevateFunction.mostRecentCall.args;\r
1996 expect(args[0]).toBe(domPublisher.self.prototype.doDirectEvent);\r
1997 expect(args[1]).toBe(domPublisher);\r
1998 expect(args[2].length).toBe(2);\r
1999 expect(args[2][0]).toBe(fakeEvent);\r
2000 expect(args[2][1]).toBe(false);\r
2001 });\r
2002\r
2003 it("should call the elevateFunction when a direct capture dom event is fired", function() {\r
2004 var domPublisher = Ext.event.publisher.Dom.instance,\r
2005 fakeEvent = { type: 'click' },\r
2006 args;\r
2007\r
2008 spyOn(Ext, 'elevateFunction');\r
2009 domPublisher.onDirectCaptureEvent(fakeEvent);\r
2010 expect(Ext.elevateFunction.callCount).toBe(1);\r
2011 args = Ext.elevateFunction.mostRecentCall.args;\r
2012 expect(args[0]).toBe(domPublisher.self.prototype.doDirectEvent);\r
2013 expect(args[1]).toBe(domPublisher);\r
2014 expect(args[2].length).toBe(2);\r
2015 expect(args[2][0]).toBe(fakeEvent);\r
2016 expect(args[2][1]).toBe(true);\r
2017 });\r
2018\r
2019 it("should call the elevateFunction when Gesture#onTargetTouchMove is called", function() {\r
2020 var gesturePublisher = Ext.event.publisher.Gesture.instance,\r
2021 fakeEvent = { type: 'click' },\r
2022 args;\r
2023\r
2024 spyOn(Ext, 'elevateFunction');\r
2025 gesturePublisher.onTargetTouchMove(fakeEvent);\r
2026 expect(Ext.elevateFunction.callCount).toBe(1);\r
2027 args = Ext.elevateFunction.mostRecentCall.args;\r
2028 expect(args[0]).toBe(gesturePublisher.self.prototype.doTargetTouchMove);\r
2029 expect(args[1]).toBe(gesturePublisher);\r
2030 expect(args[2].length).toBe(1);\r
2031 expect(args[2][0]).toBe(fakeEvent);\r
2032 });\r
2033\r
2034 it("should call the elevateFunction when Gesture#onTargetTouchEnd is called", function() {\r
2035 var gesturePublisher = Ext.event.publisher.Gesture.instance,\r
2036 fakeEvent = { type: 'click' },\r
2037 args;\r
2038\r
2039 spyOn(Ext, 'elevateFunction');\r
2040 gesturePublisher.onTargetTouchEnd(fakeEvent);\r
2041 expect(Ext.elevateFunction.callCount).toBe(1);\r
2042 args = Ext.elevateFunction.mostRecentCall.args;\r
2043 expect(args[0]).toBe(gesturePublisher.self.prototype.doTargetTouchEnd);\r
2044 expect(args[1]).toBe(gesturePublisher);\r
2045 expect(args[2].length).toBe(1);\r
2046 expect(args[2][0]).toBe(fakeEvent);\r
2047 });\r
2048\r
2049 describe('timer callbacks', function () {\r
2050 var called = false,\r
2051 elevatedCalled = false,\r
2052 fn;\r
2053\r
2054 beforeEach(function () {\r
2055 fn = function () {\r
2056 elevatedCalled = elevated;\r
2057 called = true;\r
2058 expect(elevated).toBe(true);\r
2059 };\r
2060 });\r
2061\r
2062 afterEach(function () {\r
2063 fn = null;\r
2064 called = elevatedCalled = false;\r
2065 });\r
2066\r
2067 it("should call the elevateFunction when a buffered function is called", function() {\r
2068 var bufferedFn, args;\r
2069\r
2070 runs(function() {\r
2071 bufferedFn = Ext.Function.createBuffered(fn, 1, fakeScope, ['foo', 'bar']);\r
2072 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2073 bufferedFn();\r
2074 });\r
2075\r
2076 waitsFor(function() {\r
2077 return called;\r
2078 });\r
2079\r
2080 runs(function() {\r
2081 expect(elevatedCalled).toBe(true);\r
2082 expect(elevated).toBe(false);\r
2083 args = Ext.elevateFunction.mostRecentCall.args;\r
2084 expect(args[0]).toBe(fn);\r
2085 expect(args[1]).toBe(fakeScope);\r
2086 expect(args[2]).toEqual(['foo', 'bar']);\r
2087 });\r
2088 });\r
2089\r
2090 it("should call the elevateFunction when a delayed function is called", function() {\r
2091 var delayedFn, args;\r
2092\r
2093 runs(function() {\r
2094 delayedFn = Ext.Function.createDelayed(fn, 1);\r
2095 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2096 delayedFn('foo', 'bar');\r
2097 });\r
2098\r
2099 waitsFor(function() {\r
2100 return called;\r
2101 });\r
2102\r
2103 runs(function() {\r
2104 expect(elevatedCalled).toBe(true);\r
2105 expect(elevated).toBe(false);\r
2106 args = Ext.elevateFunction.mostRecentCall.args;\r
2107 // not the original function - createDelayed uses a bound fn\r
2108 expect(args[0] instanceof Function).toBe(true);\r
2109 expect(args[1]).toBe(window);\r
2110 expect(args[2]).toEqual(['foo', 'bar']);\r
2111 });\r
2112 });\r
2113\r
2114 it("should call the elevateFunction when a throttled function is called", function() {\r
2115 var throttledFn, args;\r
2116\r
2117 runs(function() {\r
2118 throttledFn = Ext.Function.createThrottled(fn, 1, fakeScope);\r
2119 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2120 throttledFn('foo', 'bar');\r
2121 });\r
2122\r
2123 waitsFor(function() {\r
2124 return called;\r
2125 });\r
2126\r
2127 runs(function() {\r
2128 expect(elevatedCalled).toBe(true);\r
2129 expect(elevated).toBe(false);\r
2130 args = Ext.elevateFunction.mostRecentCall.args;\r
2131 // not the original function - createDelayed uses a bound fn\r
2132 expect(args[0]).toBe(fn);\r
2133 expect(args[1]).toBe(fakeScope);\r
2134 expect(args[2]).toEqual(['foo', 'bar']);\r
2135 });\r
2136 });\r
2137\r
2138 it("should call the elevateFunction when Ext.defer() is called", function() {\r
2139 var args;\r
2140\r
2141 runs(function() {\r
2142 Ext.defer(fn, 1, fakeScope, ['foo', 'bar']);\r
2143 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2144 });\r
2145\r
2146 waitsFor(function() {\r
2147 return called;\r
2148 });\r
2149\r
2150 runs(function() {\r
2151 expect(elevatedCalled).toBe(true);\r
2152 expect(elevated).toBe(false);\r
2153 args = Ext.elevateFunction.mostRecentCall.args;\r
2154 // not the original function - defer uses a bound fn\r
2155 expect(args[0] instanceof Function).toBe(true);\r
2156 expect(args[1]).toBeUndefined();\r
2157 expect(args[2]).toBeUndefined();\r
2158 });\r
2159 });\r
2160\r
2161 it("should call the elevateFunction when Ext.interval() is called", function() {\r
2162 var args, interval;\r
2163\r
2164 fn = Ext.Function.createSequence(fn, function () {\r
2165 clearInterval(interval);\r
2166 });\r
2167\r
2168 runs(function() {\r
2169 interval = Ext.interval(fn, 100, fakeScope, ['foo', 'bar']);\r
2170 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2171 });\r
2172\r
2173 waitsFor(function() {\r
2174 return called;\r
2175 });\r
2176\r
2177 runs(function() {\r
2178 expect(elevatedCalled).toBe(true);\r
2179 expect(elevated).toBe(false);\r
2180 args = Ext.elevateFunction.mostRecentCall.args;\r
2181 // not the original function - interval uses a bound fn\r
2182 expect(args[0] instanceof Function).toBe(true);\r
2183 expect(args[1]).toBeUndefined();\r
2184 expect(args[2]).toBeUndefined();\r
2185 });\r
2186 });\r
2187\r
2188 it("should call the elevateFunction when a requestAnimationFrame callback is called", function() {\r
2189 runs(function() {\r
2190 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2191 Ext.Function.requestAnimationFrame(fn);\r
2192 });\r
2193\r
2194 waitsFor(function() {\r
2195 return called;\r
2196 });\r
2197\r
2198 runs(function() {\r
2199 expect(called).toBe(true);\r
2200 expect(elevatedCalled).toBe(true);\r
2201 expect(elevated).toBe(false);\r
2202 });\r
2203 });\r
2204\r
2205 it("should call the elevateFunction when a createAnimationFrame callback is called", function() {\r
2206 var animFn, args;\r
2207\r
2208 runs(function() {\r
2209 animFn = Ext.Function.createAnimationFrame(fn, fakeScope);\r
2210 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2211 animFn('foo', 'bar');\r
2212 });\r
2213\r
2214 waitsFor(function() {\r
2215 return called;\r
2216 });\r
2217\r
2218 runs(function() {\r
2219 expect(elevatedCalled).toBe(true);\r
2220 expect(elevated).toBe(false);\r
2221 args = Ext.elevateFunction.mostRecentCall.args;\r
2222 // createAnimationFrame calls through to requestAnimationFrame, so the\r
2223 // original fn/scope/args are not the ones passed to elevateFunction\r
2224 expect(args[0] instanceof Function).toBe(true);\r
2225 expect(args[1]).toBeUndefined();\r
2226 expect(args[2]).toBeUndefined();\r
2227 });\r
2228 });\r
2229 });\r
2230\r
2231 it("should call the elevate function when an Ext.callback function is called", function() {\r
2232 var called = false,\r
2233 animFn, args;\r
2234\r
2235 function fn() {\r
2236 called = true;\r
2237 }\r
2238\r
2239 runs(function() {\r
2240 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2241 Ext.callback(fn, fakeScope);\r
2242 });\r
2243\r
2244 waitsFor(function() {\r
2245 return called;\r
2246 });\r
2247\r
2248 runs(function() {\r
2249 expect(Ext.elevateFunction.callCount).toBe(1);\r
2250 args = Ext.elevateFunction.mostRecentCall.args;\r
2251 expect(args[0]).toBe(fn);\r
2252 expect(args[1]).toBe(fakeScope);\r
2253 });\r
2254 });\r
2255\r
2256 it("should call the elevate function when an Ext.callback function is called with args", function() {\r
2257 var called = false,\r
2258 animFn, args;\r
2259\r
2260 function fn() {\r
2261 called = true;\r
2262 }\r
2263\r
2264 runs(function() {\r
2265 spyOn(Ext, 'elevateFunction').andCallThrough();\r
2266 Ext.callback(fn, fakeScope, ['foo', 'bar']);\r
2267 });\r
2268\r
2269 waitsFor(function() {\r
2270 return called;\r
2271 });\r
2272\r
2273 runs(function() {\r
2274 expect(Ext.elevateFunction.callCount).toBe(1);\r
2275 args = Ext.elevateFunction.mostRecentCall.args;\r
2276 expect(args[0]).toBe(fn);\r
2277 expect(args[1]).toBe(fakeScope);\r
2278 expect(args[2]).toEqual(['foo', 'bar']);\r
2279 });\r
2280 });\r
2281 });\r
2282});\r