3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 Ext.test.session.addTest('Ext', {
16 test_apply: function(){
17 var o1 = Ext.apply({}, {
21 Y.ObjectAssert.hasKeys(o1, {
24 }, 'Test simple apply, with a return value');
31 Y.ObjectAssert.hasKeys(o2, {
34 }, 'Test that the reference is changed');
36 var o3 = Ext.apply({}, {
39 Y.Assert.isUndefined(o3.prop2, 'Test to ensure no extra properties are copied');
48 Y.ObjectAssert.hasKeys(o4, {
52 }, 'Ensure that properties get overwritten by defaults');
62 Y.ObjectAssert.hasKeys(o5, {
66 }, 'Test using defaults');
68 var o6 = Ext.apply({}, {
75 Y.ObjectAssert.hasKeys(o6, {
78 }, 'Test to ensure all defaults get overridden');
80 Y.Assert.isNull(Ext.apply(null, {}), 'Test null first argument');
84 test_applyIf: function(){
85 var o1 = Ext.applyIf({}, {
89 Y.ObjectAssert.hasKeys(o1, {
92 }, 'Test with an empty destination object');
94 var o2 = Ext.applyIf({
99 Y.ObjectAssert.hasKeys(o2, {
101 }, 'Ensure existing properties don\'t get overridden');
103 var o3 = Ext.applyIf({
110 Y.ObjectAssert.hasKeys(o3, {
114 }, 'Test mixing properties to be overridden');
122 Y.ObjectAssert.hasKeys(o4, {
124 }, 'Test that the reference of the object is changed');
126 Y.Assert.isNull(Ext.applyIf(null, {}), 'Test null first argument');
130 test_clean: function(){
131 Y.ArrayAssert.itemsAreEqual([true, true, true], Ext.clean([true, true, true]), 'Test with all true');
132 Y.ArrayAssert.isEmpty(Ext.clean([]), 'Test with empty');
133 Y.ArrayAssert.isEmpty(Ext.clean([false, false, false]), 'Test with all false');
134 Y.ArrayAssert.isEmpty(Ext.clean(null), 'Test with non array parameter');
135 Y.ArrayAssert.itemsAreEqual([1, 1], Ext.clean([1, 0, 1]), 'Test with non booleans');
136 Y.ArrayAssert.itemsAreEqual([1, 2, 3, 1], Ext.clean([1, 2, false, 0, 3, 1]), 'Ensure order is maintained properly');
140 test_copyTo: function(){
148 var o1 = Ext.copyTo({}, from, 'x,y');
149 Y.ObjectAssert.hasKeys(o1, {
152 }, 'Test simple copy with string');
154 var o2 = Ext.copyTo({}, from, '');
155 Y.Assert.isUndefined(o2.x, 'Test with empty string as properties');
156 Y.Assert.isUndefined(o2.y, 'Test with empty string as properties');
157 Y.Assert.isUndefined(o2.width, 'Test with empty string as properties');
158 Y.Assert.isUndefined(o2.height, 'Test with empty string as properties');
161 Ext.copyTo(o3, from, 'width');
162 Y.ObjectAssert.hasKeys(o3, {
164 }, 'Test copy ensuring that the original reference is changed');
166 var o4 = Ext.copyTo({
168 }, from, ['x', 'y']);
169 Y.ObjectAssert.hasKeys(o4, {
172 }, 'Test with array as properties, also with an existing value in the destination object');
179 test_destroy: function(){
180 var C1 = Ext.extend(Object, {
181 constructor: function(){
182 this.c1destroy = false;
185 this.c1destroy = true;
188 var C2 = Ext.extend(Object, {
189 constructor: function(){
190 this.c2destroy = false;
193 this.c2destroy = true;
196 var C3 = Ext.extend(Object, {
197 constructor: function(){
198 this.c3destroy = false;
201 this.c3destroy = true;
207 Y.Assert.isTrue(o1.c1destroy, 'Simple destroy test with a single object');
209 var arr1 = [new C1(), new C2(), new C2()];
211 Y.Assert.isTrue(arr1[0].c1destroy, 'Test with an array of items');
212 Y.Assert.isTrue(arr1[1].c2destroy, 'Test with an array of items');
213 Y.Assert.isTrue(arr1[2].c2destroy, 'Test with an array of items');
215 var o2 = new C1(), o3 = new C2(), o4 = new C1();
217 Ext.destroy(o2, o3, o4);
218 Y.Assert.isTrue(o2.c1destroy, 'Test with param array');
219 Y.Assert.isTrue(o3.c2destroy, 'Test with param array');
220 Y.Assert.isTrue(o4.c1destroy, 'Test with param array');
224 Y.Assert.isFalse(o5.c3destroy, 'Test item without a destroy method');
226 var arr2 = [new C1(), new C3(), new C2()];
228 Y.Assert.isTrue(arr2[0].c1destroy, 'Test with an array of items, mix of items with and without destroy');
229 Y.Assert.isFalse(arr2[1].c3destroy, 'Test with an array of items, mix of items with and without destroy');
230 Y.Assert.isTrue(arr2[2].c2destroy, 'Test with an array of items, mix of items with and without destroy');
232 var id1 = Ext.id(), el1 = Ext.getBody().createChild({
236 Y.Assert.isNull(document.getElementById(id1), 'Test with an Ext.Element');
238 var id2 = Ext.id(), el2 = Ext.getBody().createChild({
241 Ext.destroy(el2, o6);
242 Y.Assert.isNull(document.getElementById(id2), 'Test with a mix of elements and objects');
243 Y.Assert.isTrue(o6.c1destroy, 'Test with a mix of elements and objects');
247 test_destroyMembers: function(){
248 var C1 = Ext.extend(Object, {
249 constructor: function(){
261 var C2 = Ext.extend(Object, {
262 constructor: function(){
270 Ext.destroyMembers(o1, 'p1', 'p3');
271 Y.Assert.isUndefined(o1.p1, 'Simple test with a mix of properties');
272 Y.Assert.areEqual(2, o1.p2, 'Simple test with a mix of properties');
273 Y.Assert.isUndefined(o1.p3, 'Simple test with a mix of properties');
274 Y.Assert.areEqual(4, o1.p4, 'Simple test with a mix of properties');
277 Ext.destroyMembers(o2);
278 Y.Assert.isNotUndefined(o2.p1, 'Test with empty parameter list, ensure nothing is removed or destroyed');
279 Y.Assert.isNotUndefined(o2.p2, 'Test with empty parameter list, ensure nothing is removed or destroyed');
280 Y.Assert.areEqual(1, o2.p3, 'Test with empty parameter list, ensure nothing is removed or destroyed');
281 Y.Assert.isFalse(o2.p1.d, 'Test with empty parameter list, ensure nothing is removed or destroyed');
282 Y.Assert.isFalse(o2.p2.d, 'Test with empty parameter list, ensure nothing is removed or destroyed');
284 var o3 = new C2(), o4 = o3.p1, o5 = o3.p2;
285 Ext.destroyMembers(o3, 'p1', 'p2');
286 Y.Assert.isUndefined(o3.p1, 'Destroy objects, ensure they are destroyed and removed');
287 Y.Assert.isUndefined(o3.p2, 'Destroy objects, ensure they are destroyed and removed');
288 Y.Assert.areEqual(1, o3.p3, 'Destroy objects, ensure they are destroyed and removed');
289 Y.Assert.isTrue(o4.d, 'Destroy objects, ensure they are destroyed and removed');
290 Y.Assert.isTrue(o5.d, 'Destroy objects, ensure they are destroyed and removed');
294 test_each: function(){
296 Ext.each([1, 2, 3, 4], function(val){
299 Y.Assert.areEqual(10, sum, 'Simple each on an array of numbers');
302 Ext.each(['T', 'e', 's', 't', 'i', 'n', 'g'], function(c){
305 Y.Assert.areEqual('Testing', s, 'Simple each on array of strings');
308 Ext.each(5, function(num){
311 Y.Assert.areEqual(5, sum, 'Test with a non array parameter, number');
314 Ext.each([], function(){
317 Y.Assert.isFalse(hit, 'Test with empty array parameter');
320 Ext.each(null, function(){
323 Y.Assert.isFalse(hit, 'Test with null parameter');
326 Ext.each(document.getElementsByTagName('body'), function(){
329 Y.Assert.isTrue(hit, 'Test iteration over NodeLists');
332 Ext.each([1, 2, 3, 4, 5, 6], function(val, idx){
335 Y.ArrayAssert.itemsAreEqual([0, 1, 2, 3, 4, 5], arr, 'Test index is passed correctly');
338 Ext.each([1, 2, 3, 4, 5, 6], function(val){
344 Y.Assert.areEqual(10, sum, 'Test that returning false stops iteration');
347 var scope = {value: 3};
348 Ext.each([1, 2, 3], function(val){
349 sum += val * this.value;
351 Y.Assert.areEqual(18, sum, 'Test scope argument #1');
355 Ext.each([1, 2, 3], function(val){
356 sum += val * this.value; //value should be 5
358 Y.Assert.areEqual(30, sum, 'Test scope argument #2');
364 test_escapeRe: function(){
365 Y.Assert.areEqual('\\-', Ext.escapeRe('-'), 'Test with single char');
366 Y.Assert.areEqual('\\*\\.', Ext.escapeRe('*.'), 'Test with multiple characters next to each other');
367 Y.Assert.areEqual('foo', Ext.escapeRe('foo'), 'Test with no escapeable chars');
368 Y.Assert.areEqual('\\{baz\\}', Ext.escapeRe('{baz}'), 'Test with mixed set');
369 Y.Assert.areEqual('\\-\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\/\\\\', Ext.escapeRe('-.*+?^${}()|[]/\\'), 'Test with every character');
373 test_extend: function(){
374 var Dude = Ext.extend(Object, {
375 constructor: function(config){
376 Ext.apply(this, config);
377 this.isBadass = false;
380 var Aweysome = Ext.extend(Dude, {
381 constructor: function(){
382 Aweysome.superclass.constructor.apply(this, arguments);
383 this.isBadass = true;
387 var david = new Aweysome({
390 Y.Assert.areEqual('isAwesome', david.davis, 'Test if David is awesome');
391 Y.Assert.isTrue(david.isBadass, 'Test if David is badass');
392 Y.Assert.isFunction(david.override, 'Test if extend added the override method');
393 Y.ObjectAssert.areEqual({
396 }, david, 'Test if David is badass and awesome');
400 test_flatten: function(){
401 Y.ArrayAssert.isEmpty(Ext.flatten([]), 'Test with empty array');
402 Y.ArrayAssert.isEmpty(Ext.flatten([[], [], []]), 'Test with an array of empty arrays');
403 Y.ArrayAssert.isEmpty(Ext.flatten(null), 'Test with null');
404 Y.ArrayAssert.isEmpty(Ext.flatten(undefined), 'Test with undefined');
405 Y.ArrayAssert.itemsAreEqual([1, 7, 3, 4], Ext.flatten([1, 7, 3, 4]), 'Test with a simple flat array');
406 Y.ArrayAssert.itemsAreEqual([1, 2, 3], Ext.flatten([[1], [2], [3]]), 'Test with an array of arrays with a single item');
407 Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6], Ext.flatten([[1, 2], [3, 4], [5, 6]]), 'Test sub arrays with multiple items');
408 Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6, 7], Ext.flatten([1, 2, [3, 4], 5, [6, 7]]), 'Test a mix of sub arrays and non arrays');
409 Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], Ext.flatten([[[1, [2, 3], [4, 5]], [6, 7, [8, [9, 10]]]]]), 'Test with multiple levels of nesting');
413 test_fly: function(){
415 var div = document.createElement('div');
417 Ext.getBody().dom.appendChild(div);
419 var div2 = Ext.fly(id);
420 Y.Assert.areSame(div, div2.dom, 'Test if fly got the correct item');
425 test_get: function(){
427 var div = document.createElement('div');
429 Ext.getBody().dom.appendChild(div);
430 var div2 = Ext.get(id);
431 Y.Assert.areSame(div, div2.dom, 'Test if "get" got the correct item');
436 test_getBody: function(){
437 var body = Ext.getBody();
438 Y.Assert.isTrue(body.dom === document.body || body.dom === document.documentElement, 'Test if getBody returns the body');
444 test_getDoc: function(){
445 var doc = Ext.getDoc();
446 Y.Assert.areSame(document, doc.dom, 'Test if getDoc returns document');
450 test_getDom: function(){
452 var div = document.createElement('div');
454 Ext.getBody().dom.appendChild(div);
456 var div2 = Ext.getDom(id);
457 Y.Assert.areSame(div, div2, 'Test if getDom returns correct element');
458 div2.parentNode.removeChild(div2);
462 test_getScrollBarWidth: function(){
463 Y.Assert.isNumber(Ext.getScrollBarWidth(), 'Test if getScrollBarWith returns a number');
468 var id = Ext.id(document);
469 var id2 = Ext.id(document);
470 Y.Assert.areEqual(id, id2, 'Test if id returns same id for the same element');
474 test_invoke: function(){
476 var fn = function(a, b){
477 Y.Assert.areEqual('a', a, 'Testing invoke param');
478 Y.Assert.areEqual('b', b, 'Testing invoke param');
489 var results = Ext.invoke(arr, 'get', 'a', 'b');
491 Y.ArrayAssert.itemsAreEqual([1, 2, 3], results, 'Test invoke results');
492 Y.Assert.areEqual(n, results.length, 'Number of invocations');
496 test_isArray: function(){
497 var C = Ext.extend(Object, {
500 Y.Assert.isTrue(Ext.isArray([]), 'Test with empty array');
501 Y.Assert.isTrue(Ext.isArray([1, 2, 3, 4]), 'Test with filled array');
502 Y.Assert.isFalse(Ext.isArray(false), 'Test with boolean #1');
503 Y.Assert.isFalse(Ext.isArray(true), 'Test with boolean #2');
504 Y.Assert.isFalse(Ext.isArray('foo'), 'Test with string');
505 Y.Assert.isFalse(Ext.isArray(1), 'Test with number');
506 Y.Assert.isFalse(Ext.isArray(null), 'Test with null');
507 Y.Assert.isFalse(Ext.isArray(new Date()), 'Test with a date');
508 Y.Assert.isFalse(Ext.isArray({}), 'Test with empty object');
509 Y.Assert.isFalse(Ext.isArray(document.getElementsByTagName('body')), 'Test with node list');
510 Y.Assert.isFalse(Ext.isArray(Ext.getBody().dom), 'Test with element');
511 Y.Assert.isFalse(Ext.isArray(new C()), 'Test with custom class that has a length property');
515 test_isBoolean: function(){
516 Y.Assert.isTrue(Ext.isBoolean(true), 'Test with true');
517 Y.Assert.isTrue(Ext.isBoolean(false), 'Test with false');
518 Y.Assert.isFalse(Ext.isBoolean([]), 'Test with empty array');
519 Y.Assert.isFalse(Ext.isBoolean([1, 2, 3]), 'Test with filled array');
520 Y.Assert.isFalse(Ext.isBoolean(1), 'Test with number');
521 Y.Assert.isFalse(Ext.isBoolean(''), 'Test with empty string');
522 Y.Assert.isFalse(Ext.isBoolean('foo'), 'Test with non empty string');
523 Y.Assert.isFalse(Ext.isBoolean(Ext.getBody().dom), 'Test with element');
524 Y.Assert.isFalse(Ext.isBoolean(null), 'Test with null');
525 Y.Assert.isFalse(Ext.isBoolean({}), 'Test with object');
526 Y.Assert.isFalse(Ext.isBoolean(new Date()), 'Test with date');
530 test_isDate: function(){
531 Y.Assert.isTrue(Ext.isDate(new Date()), 'Test with simple date');
532 Y.Assert.isTrue(Ext.isDate(Date.parseDate('2000', 'Y')), 'Test with simple date');
533 Y.Assert.isFalse(Ext.isDate(true), 'Test with boolean');
534 Y.Assert.isFalse(Ext.isDate(1), 'Test with number');
535 Y.Assert.isFalse(Ext.isDate('foo'), 'Test with string');
536 Y.Assert.isFalse(Ext.isDate(null), 'Test with null');
537 Y.Assert.isFalse(Ext.isDate([]), 'Test with array');
538 Y.Assert.isFalse(Ext.isDate({}), 'Test with object');
539 Y.Assert.isFalse(Ext.isDate(Ext.getBody().dom), 'Test with element');
543 test_isDefined: function(){
544 Y.Assert.isFalse(Ext.isDefined(undefined), 'Test with undefined');
545 Y.Assert.isTrue(Ext.isDefined(null), 'Test with null');
546 Y.Assert.isTrue(Ext.isDefined({}), 'Test with object');
547 Y.Assert.isTrue(Ext.isDefined([]), 'Test with array');
548 Y.Assert.isTrue(Ext.isDefined(new Date()), 'Test with date');
549 Y.Assert.isTrue(Ext.isDefined(1), 'Test with number');
550 Y.Assert.isTrue(Ext.isDefined(false), 'Test with boolean');
551 Y.Assert.isTrue(Ext.isDefined(''), 'Test with empty string');
552 Y.Assert.isTrue(Ext.isDefined('foo'), 'Test with non-empty string');
553 Y.Assert.isTrue(Ext.isDefined(Ext.getBody().dom), 'Test with element');
557 test_isElement: function(){
558 Y.Assert.isTrue(Ext.isElement(Ext.getBody().dom), 'Test with element');
559 Y.Assert.isFalse(Ext.isElement(Ext.getBody()), 'Test with Ext.Element');
560 Y.Assert.isFalse(Ext.isElement(null), 'Test with null');
561 Y.Assert.isFalse(Ext.isElement(1), 'Test with number');
562 Y.Assert.isFalse(Ext.isElement('foo'), 'Test with string');
566 test_isEmpty: function(){
567 Y.Assert.isTrue(Ext.isEmpty(''), 'Test with empty string');
568 Y.Assert.isTrue(Ext.isEmpty(null), 'Test with null');
569 Y.Assert.isTrue(Ext.isEmpty(undefined), 'Test with undefined');
570 Y.Assert.isTrue(Ext.isEmpty([]), 'Test with empty array');
571 Y.Assert.isFalse(Ext.isEmpty('Foo'), 'Test with simple string');
572 Y.Assert.isFalse(Ext.isEmpty(false), 'Test with boolean false');
573 Y.Assert.isFalse(Ext.isEmpty(1), 'Test with numeric value');
574 Y.Assert.isFalse(Ext.isEmpty({}), 'Test with object with no properties');
575 Y.Assert.isFalse(Ext.isEmpty([1, 2, 3]), 'Test with filled array');
576 Y.Assert.isFalse(Ext.isEmpty('', true), 'Test empty string with allowBlank');
580 test_isFunction: function(){
581 var c = new Ext.util.Observable(), o = {
585 Y.Assert.isTrue(Ext.isFunction(function(){
586 }), 'Test with anonymous function');
587 Y.Assert.isTrue(Ext.isFunction(new Function('return "";')), 'Test with new Function syntax');
588 Y.Assert.isTrue(Ext.isFunction(Ext.emptyFn), 'Test with static function');
589 Y.Assert.isTrue(Ext.isFunction(c.fireEvent), 'Test with instance function');
590 Y.Assert.isTrue(Ext.isFunction(o.fn), 'Test with function on object');
591 Y.Assert.isFalse(Ext.isFunction(Ext.version), 'Test with class property');
592 Y.Assert.isFalse(Ext.isFunction(null), 'Test with null');
593 Y.Assert.isFalse(Ext.isFunction(1), 'Test with number');
594 Y.Assert.isFalse(Ext.isFunction(''), 'Test with string');
595 Y.Assert.isFalse(Ext.isFunction(new Date()), 'Test with date');
596 Y.Assert.isFalse(Ext.isFunction([]), 'Test with array');
597 Y.Assert.isFalse(Ext.isFunction({}), 'Test with object');
601 test_isNumber: function(){
602 Y.Assert.isTrue(Ext.isNumber(0), 'Test with 0');
603 Y.Assert.isTrue(Ext.isNumber(4), 'Test with non-zero integer');
604 Y.Assert.isTrue(Ext.isNumber(-3), 'Test with negative integer');
605 Y.Assert.isTrue(Ext.isNumber(7.9), 'Test with positive float');
606 Y.Assert.isTrue(Ext.isNumber(-4.3), 'Test with negative float');
607 Y.Assert.isTrue(Ext.isNumber(Number.MAX_VALUE), 'Test with MAX_VALUE');
608 Y.Assert.isTrue(Ext.isNumber(Number.MIN_VALUE), 'Test with MIN_VALUE');
609 Y.Assert.isTrue(Ext.isNumber(Math.PI), 'Test with Math.PI');
610 Y.Assert.isTrue(Ext.isNumber(Number('3.1')), 'Test with Number() constructor');
611 Y.Assert.isFalse(Ext.isNumber(Number.NaN), 'Test with NaN');
612 Y.Assert.isFalse(Ext.isNumber(Number.POSITIVE_INFINITY), 'Test with POSITIVE_INFINITY');
613 Y.Assert.isFalse(Ext.isNumber(Number.NEGATIVE_INFINITY), 'Test with NEGATIVE_INFINITY');
614 Y.Assert.isFalse(Ext.isNumber(true), 'Test with true');
615 Y.Assert.isFalse(Ext.isNumber(''), 'Test with empty string');
616 Y.Assert.isFalse(Ext.isNumber('1.0'), 'Test with string containing a number');
617 Y.Assert.isFalse(Ext.isNumber(null), 'Test with null');
618 Y.Assert.isFalse(Ext.isNumber(undefined), 'Test with undefined');
619 Y.Assert.isFalse(Ext.isNumber([]), 'Test with array');
620 Y.Assert.isFalse(Ext.isNumber({}), 'Test with object');
624 test_isObject: function(){
625 Y.Assert.isTrue(Ext.isObject({}), 'Test with empty object');
626 Y.Assert.isTrue(Ext.isObject({
628 }), 'Test with object with properties');
629 Y.Assert.isTrue(Ext.isObject(new Ext.util.Observable()), 'Test with object instance');
630 Y.Assert.isTrue(Ext.isObject(new Object()), 'Test with new Object( ) syntax');
631 Y.Assert.isFalse(Ext.isObject(new Date()), 'Test with a date object');
632 Y.Assert.isFalse(Ext.isObject([]), 'Test with array');
633 Y.Assert.isFalse(Ext.isObject(new Array()), 'Test with new Array( ) syntax');
634 Y.Assert.isFalse(Ext.isObject(1), 'Test with number');
635 Y.Assert.isFalse(Ext.isObject('foo'), 'Test with string');
636 Y.Assert.isFalse(Ext.isObject(false), 'Test with boolean');
637 Y.Assert.isFalse(Ext.isObject(new Number(3)), 'Test with new Number() syntax');
638 Y.Assert.isFalse(Ext.isObject(new String('foo')), 'Test with new String() syntax');
639 Y.Assert.isFalse(Ext.isObject(null), 'Test with null');
640 Y.Assert.isFalse(Ext.isObject(undefined), 'Test with undefined');
644 test_isPrimitive: function(){
645 Y.Assert.isTrue(Ext.isPrimitive(1), 'Test with integer');
646 Y.Assert.isTrue(Ext.isPrimitive(-3), 'Test with negative integer');
647 Y.Assert.isTrue(Ext.isPrimitive(1.4), 'Test with floating number');
648 Y.Assert.isTrue(Ext.isPrimitive(Number.MAX_VALUE), 'Test with Number.MAX_VALUE');
649 Y.Assert.isTrue(Ext.isPrimitive(Math.PI), 'Test with Math.PI');
650 Y.Assert.isTrue(Ext.isPrimitive(''), 'Test with empty string');
651 Y.Assert.isTrue(Ext.isPrimitive('foo'), 'Test with non empty string');
652 Y.Assert.isTrue(Ext.isPrimitive(true), 'Test with boolean true');
653 Y.Assert.isTrue(Ext.isPrimitive(false), 'Test with boolean false');
654 Y.Assert.isFalse(Ext.isPrimitive(null), 'Test with null');
655 Y.Assert.isFalse(Ext.isPrimitive(undefined), 'Test with undefined');
656 Y.Assert.isFalse(Ext.isPrimitive({}), 'Test with object');
657 Y.Assert.isFalse(Ext.isPrimitive([]), 'Test with array');
658 Y.Assert.isFalse(Ext.isPrimitive(new Ext.util.Observable()), 'Test with object instance');
662 test_isString: function(){
663 var s = new String('foo');
664 Y.Assert.isTrue(Ext.isString(''), 'Test with empty string');
665 Y.Assert.isTrue(Ext.isString('foo'), 'Test with non empty string');
666 Y.Assert.isTrue(Ext.isString(String('')), 'Test with String() syntax');
667 Y.Assert.isFalse(Ext.isString(new String('')), 'Test with new String() syntax'); //should return an object that wraps the primitive
668 Y.Assert.isFalse(Ext.isString(1), 'Test with number');
669 Y.Assert.isFalse(Ext.isString(true), 'Test with boolean');
670 Y.Assert.isFalse(Ext.isString(null), 'Test with null');
671 Y.Assert.isFalse(Ext.isString(undefined), 'Test with undefined');
672 Y.Assert.isFalse(Ext.isString([]), 'Test with array');
673 Y.Assert.isFalse(Ext.isString({}), 'Test with number');
677 test_iterate: function(){
683 }, function(k, v, o){
684 Y.Assert.isNumber(v);
687 Y.Assert.areEqual(42, n, 'Test if iterate has called the function the correct number of times (object)');
689 Ext.iterate([11, 13, 18], function(x){
690 Y.Assert.isNumber(x);
693 Y.Assert.areEqual(42, n, 'Test if iterate has called the function the correct number of times (array)');
697 test_max: function(){
698 Y.Assert.areEqual(14, Ext.max([14]), 'Test single item');
699 Y.Assert.areEqual(16, Ext.max([1, 4, 16, 3, 8]), 'Test with max in the middle');
700 Y.Assert.areEqual(9, Ext.max([9, 1, 5, 8]), 'Test with max at start');
701 Y.Assert.areEqual(12, Ext.max([1, 9, 0, 4, 12]), 'Test with max at end');
702 Y.Assert.isUndefined(Ext.max([]), 'Test with empty array');
703 Y.Assert.areEqual('j', Ext.max(['a', 'f', 'j', 'c', 'b']), 'Test with strings');
704 Y.Assert.areEqual(7, Ext.max([6, 7, 8], function(a, b){
705 return (a % 8 > b % 8) ? 1 : -1;
706 }), 'Test with custom comparator');
710 test_mean: function(){
711 Y.Assert.isUndefined(Ext.mean([]), 'Test with an empty list');
712 Y.Assert.areEqual(4, Ext.mean([4]), 'Test with a single item');
713 Y.Assert.areEqual(3, Ext.mean([1, 2, 3, 4, 5]), 'Test with multiple items');
714 Y.Assert.areEqual(1.3, Ext.mean([1.1, 1.2, 1.3, 1.4, 1.5]), 'Test with floats');
718 test_min: function(){
719 Y.Assert.areEqual(5, Ext.min([5]), 'Test single item');
720 Y.Assert.areEqual(2, Ext.min([3, 7, 2, 4, 8]), 'Test with min in the middle');
721 Y.Assert.areEqual(4, Ext.min([4, 12, 28, 100, 5]), 'Test with min at the start');
722 Y.Assert.areEqual(3, Ext.min([13, 4, 17, 83, 3]), 'Test with min at the end');
723 Y.Assert.isUndefined(Ext.min([]), 'Test with empty array');
724 Y.Assert.areEqual('b', Ext.min(['c', 'm', 'b', 'q', 's']), 'Test with strings');
725 Y.Assert.areEqual(8, Ext.min([6, 7, 8], function(a, b){
726 return (a % 8 > b % 8) ? 1 : -1;
727 }), 'Test with custom comparator');
731 test_namespace: function(){
734 Ext.namespace('FooTest1');
735 Y.Assert.isNotUndefined(w.FooTest1, 'Test creation with a single top-level namespace');
737 Ext.namespace('FooTest2', 'FooTest3', 'FooTest4');
738 Y.Assert.isNotUndefined(w.FooTest2, 'Test creation with multiple top level namespaces');
739 Y.Assert.isNotUndefined(w.FooTest3, 'Test creation with multiple top level namespaces');
740 Y.Assert.isNotUndefined(w.FooTest4, 'Test creation with multiple top level namespaces');
742 Ext.namespace('FooTest5', 'FooTest5.ns1', 'FooTest5.ns1.ns2', 'FooTest5.ns1.ns2.ns3');
743 Y.Assert.isNotUndefined(w.FooTest5, 'Test a chain of namespaces, starting from a top-level');
744 Y.Assert.isNotUndefined(w.FooTest5.ns1, 'Test a chain of namespaces, starting from a top-level');
745 Y.Assert.isNotUndefined(w.FooTest5.ns1.ns2, 'Test a chain of namespaces, starting from a top-level');
746 Y.Assert.isNotUndefined(w.FooTest5.ns1.ns2.ns3, 'Test a chain of namespaces, starting from a top-level');
748 Ext.namespace('FooTest6.ns1', 'FooTest7.ns1');
749 Y.Assert.isNotUndefined(w.FooTest6.ns1, 'Test creating lower level namespaces without first defining the top level');
750 Y.Assert.isNotUndefined(w.FooTest7.ns1, 'Test creating lower level namespaces without first defining the top level');
752 Ext.namespace('FooTest8', 'FooTest8.ns1.ns2');
753 Y.Assert.isNotUndefined(w.FooTest8, 'Test creating a lower level namespace without defining the middle level');
754 Y.Assert.isNotUndefined(w.FooTest8.ns1, 'Test creating a lower level namespace without defining the middle level');
755 Y.Assert.isNotUndefined(w.FooTest8.ns1.ns2, 'Test creating a lower level namespace without defining the middle level');
757 FooTest8.prop1 = 'foo';
758 Ext.namespace('FooTest8');
759 Y.Assert.areEqual('foo', FooTest8.prop1, 'Ensure existing namespaces are not overwritten');
762 // ns is alias of namespace
765 test_num: function(){
766 Y.Assert.areEqual(3, Ext.num(3), 'Test with an integer');
767 Y.Assert.areEqual(-7, Ext.num(-7), 'Test with a negative integer');
768 Y.Assert.areEqual(5.43, Ext.num(5.43), 'Test with a float');
769 Y.Assert.areEqual(-9.8, Ext.num(-9.8), 'Test with a negative float');
770 Y.Assert.areEqual(Math.PI, Ext.num(Math.PI), 'Test with Math.PI');
771 Y.Assert.isUndefined(Ext.num(null), 'Test with null, no default');
772 Y.Assert.areEqual(3, Ext.num(null, 3), 'Test with null, with default');
773 Y.Assert.isUndefined(Ext.num(undefined), 'Test with undefined, no default');
774 Y.Assert.areEqual(17, Ext.num(undefined, 17), 'Test with undefined, with default');
775 Y.Assert.isUndefined(Ext.num(true), 'Test with boolean, no default');
776 Y.Assert.areEqual(8, Ext.num(true, 8), 'Test with boolean, with default');
777 Y.Assert.isUndefined(Ext.num(''), 'Test with empty string');
778 Y.Assert.areEqual(453, Ext.num('453'), 'Test with a string argument in the form of a number');
779 Y.Assert.isUndefined(Ext.num(' '), 'Test with a string containing only spaces');
780 Y.Assert.isUndefined(Ext.num('foo'), 'Test with non empty string');
781 Y.Assert.isUndefined(Ext.num([]), 'Test with empty array');
782 Y.Assert.isUndefined(Ext.num([1, 2, 3]), 'Test with non empty array');
783 Y.Assert.isUndefined(Ext.num([1]), 'Test with array with a single item');
788 test_override: function(){
793 test_partition: function(){
794 var part = Ext.partition([true, false, true, true, false]);
795 Y.ArrayAssert.itemsAreEqual([true, true, true], part[0], 'Test if partitioned into true values');
796 Y.ArrayAssert.itemsAreEqual([false, false], part[1], 'Test if partitioned into false values');
797 var part2 = Ext.partition([12, 1, 11, 2, 3, 50, 5, 15], function(v){
800 Y.ArrayAssert.itemsAreEqual([12, 11, 50, 15], part2[0], 'Test if partitioned into a list of items less than 10');
801 Y.ArrayAssert.itemsAreEqual([1, 2, 3, 5], part2[1], 'Test if partitioned into a list of items greater than 10');
805 test_pluck: function(){
806 var results = Ext.pluck([{
813 Y.ArrayAssert.itemsAreEqual([11, 13, 18], results, 'Test pluck results');
823 test_sum: function(){
824 Y.Assert.areEqual(0, Ext.sum([]), 'Test with an empty list');
825 Y.Assert.areEqual(4, Ext.sum([4]), 'Test with a single item');
826 Y.Assert.areEqual(15, Ext.sum([1, 2, 3, 4, 5]), 'Test with multiple items');
827 Y.Assert.areEqual(6.5, Ext.sum([1.1, 1.2, 1.3, 1.4, 1.5]), 'Test with floats');
831 test_toArray: function(){
832 Y.Assert.isArray(Ext.toArray(document.getElementsByTagName('body')), 'Test with node list');
836 test_type: function(){
837 Y.Assert.areEqual('string', Ext.type('foo'), 'Test with string');
838 Y.Assert.areEqual('object', Ext.type(new String('foo')), 'Test with new String() syntax'); //for some reason, isn't a string
840 Y.Assert.areEqual('number', Ext.type(1), 'Test with number');
841 Y.Assert.areEqual('object', Ext.type(new Number(3)), 'Test with new Number() syntax'); //for some reason, isn't a number
843 Y.Assert.areEqual('boolean', Ext.type(false), 'Test with boolean');
844 Y.Assert.areEqual('object', Ext.type(new Boolean(false)), 'Test with new Boolean() syntax'); //for some reason, isn't a boolean
846 Y.Assert.areEqual('date', Ext.type(new Date()), 'Test with a date object');
847 Y.Assert.areEqual('date', Ext.type(Date.parseDate('2000', 'Y')), 'Test with simple date (parsed)');
849 Y.Assert.areEqual('function', Ext.type(function(){
850 }), 'Test with a function');
851 Y.Assert.areEqual('function', Ext.type(Ext.emptyFn), 'Test with Ext.emptyFn');
852 Y.Assert.areEqual('function', Ext.type(new Function()), 'Test with new Function() syntax');
854 Y.Assert.areEqual('object', Ext.type({}), 'Test with empty object');
855 Y.Assert.areEqual('object', Ext.type({
857 }), 'Test with object with properties');
858 Y.Assert.areEqual('object', Ext.type(new Ext.util.Observable()), 'Test with object instance');
859 Y.Assert.areEqual('object', Ext.type(new Object()), 'Test with new Object() syntax');
861 Y.Assert.areEqual('array', Ext.type([]), 'Test with array');
862 Y.Assert.areEqual('array', Ext.type(new Array()), 'Test with new Array() syntax');
864 Y.Assert.areEqual('regexp', Ext.type(/asdf/), 'Test with regexp');
865 Y.Assert.areEqual('regexp', Ext.type(new RegExp('asdf')), 'Test with new Regexp() syntax');
867 Y.Assert.areEqual('nodelist', Ext.type(document.getElementsByTagName('body')), 'Test with node list');
869 Y.Assert.areEqual('textnode', Ext.type(document.createTextNode('test')), 'Test with text node');
871 Y.Assert.areEqual('whitespace', Ext.type(document.createTextNode('')), 'Test with empty text node');
872 Y.Assert.areEqual('whitespace', Ext.type(document.createTextNode(' ')), 'Test with whitespace in text node');
874 Y.Assert.areEqual('', Ext.type(null), 'Test with null');
875 Y.Assert.areEqual(false, Ext.type(undefined), 'Test with undefined');
879 test_unique: function(){
881 }, obj = {}, arr = [], date = new Date();
882 Y.ArrayAssert.itemsAreEqual([true, false], Ext.unique([true, true, false, true, false, false]), 'Test with all booleans');
883 Y.ArrayAssert.itemsAreEqual([1, 2, 3], Ext.unique([1, 2, 3, 3, 2, 1]), 'Test with all numbers');
884 Y.ArrayAssert.itemsAreEqual([fn], Ext.unique([fn, fn, fn, fn]), 'Test with functions');
885 Y.ArrayAssert.itemsAreEqual([arr], Ext.unique([arr, arr, arr, arr]), 'Test with arrays');
886 Y.ArrayAssert.itemsAreEqual([obj], Ext.unique([obj, obj, obj, obj]), 'Test with objects');
887 Y.ArrayAssert.itemsAreEqual([date], Ext.unique([date, date, date, date]), 'Test with dates');
888 Y.ArrayAssert.itemsAreEqual([obj, fn, arr, date], Ext.unique([obj, obj, fn, obj, arr, obj, fn, arr, date, fn, arr, obj]), 'Test with objects, functions, arrays, and dates');
892 test_urlAppend: function(){
893 var url = "http://example.com/";
894 Y.Assert.areEqual('http://example.com/?test=1', Ext.urlAppend(url, 'test=1'), 'Test for question mark');
895 Y.Assert.areEqual('http://example.com/?test=1&foo=2', Ext.urlAppend(url + '?test=1', 'foo=2'), 'Test for ampersand');
899 test_urlDecode: function(){
900 Y.ObjectAssert.hasKeys({
903 }, Ext.urlDecode('foo=1&bar=2'), 'Decode 2 keys');
904 Y.ObjectAssert.hasKeys({
907 }, Ext.urlDecode('foo=1&bar=2&bar=3&bar=4', false), 'Decode 2 keys, one of them an array (overwrite off)');
908 Y.ObjectAssert.hasKeys({
911 }, Ext.urlDecode('foo=1&bar=2&bar=3&bar=4', true), 'Decode 2 keys, one of them an array (overwrite on)');
915 test_urlEncode: function(){
916 Y.Assert.areEqual('foo=1&bar=2', Ext.urlEncode({
919 }), 'Decode 2 keys');
920 Y.Assert.areEqual('foo=1&bar=2&bar=3&bar=4', Ext.urlEncode({
923 }), 'Decode 2 keys, one of them an array');
924 Y.Assert.areEqual('test=1&foo=1&bar=2&bar=3&bar=4', Ext.urlEncode({
927 }, 'test=1'), 'Decode 2 keys, one of them an array, with pre: test=1');
931 test_value: function(){
932 Y.Assert.areEqual('test1', Ext.value('test1', 'test2'), 'Testing "test1" string');
933 Y.Assert.areEqual('test2', Ext.value('', 'test2'), 'Testing blank string');
934 Y.Assert.areEqual('test2', Ext.value(undefined, 'test2'), 'Testing undefined value');
935 Y.Assert.areEqual('test2', Ext.value(null, 'test2'), 'Testing null value');
936 Y.Assert.areEqual('', Ext.value('', 'test2', true), 'Testing blank string with allowBlank: true');
937 // it does not consider undef and null as a blank string, so these are OK
938 Y.Assert.areEqual('test2', Ext.value(undefined, 'test2', true), 'Testing undefined value with allowBlank: true');
939 Y.Assert.areEqual('test2', Ext.value(null, 'test2', true), 'Testing null value with allowBlank: true');
943 test_zip: function(){
944 var arr = Ext.zip([1, 2, 3], [4, 5, 6]);
945 Y.ArrayAssert.itemsAreEqual([1, 4], arr[0], 'Zip two arrays');
946 Y.ArrayAssert.itemsAreEqual([2, 5], arr[1], 'Zip two arrays');
947 Y.ArrayAssert.itemsAreEqual([3, 6], arr[2], 'Zip two arrays');
948 Y.ArrayAssert.itemsAreEqual([['$+12.43'], ['$-10.15'], ['$+22.96']], Ext.zip(['+', '-', '+'], [12, 10, 22], [43, 15, 96], function(a, b, c){
949 return '$' + a + '' + b + '.' + c;
950 }), 'Zip using a function');