Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / core / test / unit / spec / class / ClassManager.js
index 070efb4..f6179bb 100644 (file)
@@ -1,3 +1,17 @@
+/*
+
+This file is part of Ext JS 4
+
+Copyright (c) 2011 Sencha Inc
+
+Contact:  http://www.sencha.com/contact
+
+GNU General Public License Usage
+This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
+
+If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
+
+*/
 describe("Ext.ClassManager", function() {
     var manager = Ext.ClassManager,
         cls, emptyFn = function(){};
@@ -461,4 +475,107 @@ describe("Ext.ClassManager", function() {
             });
         });
     });
+    
+    describe("createNamespaces", function() {
+        var w = window;
+
+        it("should have an alias Ext.namespace", function() {
+            spyOn(Ext.ClassManager, 'createNamespaces');
+            Ext.namespace('a', 'b', 'c');
+            expect(Ext.ClassManager.createNamespaces).toHaveBeenCalledWith('a', 'b', 'c');
+        });
+
+        it("should create a single top level namespace", function() {
+            Ext.ClassManager.createNamespaces('FooTest1');
+
+            expect(w.FooTest1).toBeDefined();
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest1 = undefined;
+            } else {
+                delete w.FooTest1;
+            }
+        });
+
+        it("should create multiple top level namespace", function() {
+            Ext.ClassManager.createNamespaces('FooTest2', 'FooTest3', 'FooTest4');
+
+            expect(w.FooTest2).toBeDefined();
+            expect(w.FooTest3).toBeDefined();
+            expect(w.FooTest4).toBeDefined();
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest2 = undefined;
+                w.FooTest3 = undefined;
+                w.FooTest4 = undefined;
+            } else {
+                delete w.FooTest2;
+                delete w.FooTest3;
+                delete w.FooTest4;
+            }
+        });
+
+        it("should create a chain of namespaces, starting from a top level", function() {
+            Ext.ClassManager.createNamespaces('FooTest5', 'FooTest5.ns1', 'FooTest5.ns1.ns2', 'FooTest5.ns1.ns2.ns3');
+
+            expect(w.FooTest5).toBeDefined();
+            expect(w.FooTest5.ns1).toBeDefined();
+            expect(w.FooTest5.ns1.ns2).toBeDefined();
+            expect(w.FooTest5.ns1.ns2.ns3).toBeDefined();
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest5 = undefined;
+            } else {
+                delete w.FooTest5;
+            }
+        });
+
+        it("should create lower level namespaces without first defining the top level", function() {
+            Ext.ClassManager.createNamespaces('FooTest6.ns1', 'FooTest7.ns2');
+
+            expect(w.FooTest6).toBeDefined();
+            expect(w.FooTest6.ns1).toBeDefined();
+            expect(w.FooTest7).toBeDefined();
+            expect(w.FooTest7.ns2).toBeDefined();
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest6 = undefined;
+                w.FooTest7 = undefined;
+            } else {
+                delete w.FooTest6;
+                delete w.FooTest7;
+            }
+        });
+
+        it("should create a lower level namespace without defining the middle level", function() {
+            Ext.ClassManager.createNamespaces('FooTest8', 'FooTest8.ns1.ns2');
+
+            expect(w.FooTest8).toBeDefined();
+            expect(w.FooTest8.ns1).toBeDefined();
+            expect(w.FooTest8.ns1.ns2).toBeDefined();
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest8 = undefined;
+            } else {
+                delete w.FooTest8;
+            }
+        });
+
+        it ("should not overwritte existing namespace", function() {
+            Ext.ClassManager.createNamespaces('FooTest9');
+
+            FooTest9.prop1 = 'foo';
+
+            Ext.ClassManager.createNamespaces('FooTest9');
+
+            expect(FooTest9.prop1).toEqual("foo");
+
+            if (jasmine.browser.isIE6 || jasmine.browser.isIE7 || jasmine.browser.isIE8) {
+                w.FooTest9 = undefined;
+            } else {
+                delete w.FooTest9;
+            }
+        });
+    });
 });
+