Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / core / test / unit / spec / dom / Element.static.js
1 describe("Ext.core.Element.static", function() {
2     var proto = Ext.core.Element,
3         el, testEl,
4         input, testInputEl,
5         child1, child2, child3;
6     
7     beforeEach(function() {
8         testEl = Ext.getBody().createChild({
9             id      : 'ExtElementHelper',
10             style   : 'position:absolute;',
11             children: [
12                 {id: 'child1', style: 'position:absolute;'},
13                 {id: 'child2', style: 'position:absolute;'},
14                 {id: 'child3', style: 'position:absolute;'}
15             ]
16         });
17         
18         testInputEl = Ext.getBody().createChild({
19             id  : 'ExtElementInputHelper',
20             tag : 'input',
21             type: 'text'
22         });
23         
24         el    = new Ext.core.Element(Ext.getDom(testEl));
25         input = new Ext.core.Element(Ext.getDom(testInputEl));
26         
27         child1 = Ext.get('child1');
28         child2 = Ext.get('child2');
29         child3 = Ext.get('child3');
30     });
31     
32     afterEach(function() {
33         testEl.remove();
34         testInputEl.remove();
35     });
36     
37     it("should have a defaultUnit", function() {
38         expect(proto.defaultUnit).toEqual('px');
39     });
40     
41     describe("addUnits", function() {
42         it("should add the defualt unit", function() {
43             expect(proto.addUnits(10)).toEqual('10px');
44         });
45         
46         it("should not add the defualt unit", function() {
47             expect(proto.addUnits('10px')).toEqual('10px');
48         });
49     });
50     
51     describe("parseBox", function() {
52         describe("number", function() {
53             describe("when 1 argument", function() {
54                 it("should return an object with correct values", function() {
55                     expect(proto.parseBox(10)).toEqual({
56                         top   : 10,
57                         right : 10,
58                         bottom: 10,
59                         left  : 10
60                     });
61                 });
62             });
63         });
64         
65         describe("string", function() {
66             describe("when 1 argument", function() {
67                 it("should return an object with correct values", function() {
68                     expect(proto.parseBox("10")).toEqual({
69                         top   : 10,
70                         right : 10,
71                         bottom: 10,
72                         left  : 10
73                     });
74                 });
75             });
76             
77             describe("when 2 arguments", function() {
78                 it("should return an object with correct values", function() {
79                     expect(proto.parseBox("10 5")).toEqual({
80                         top   : 10,
81                         right : 5,
82                         bottom: 10,
83                         left  : 5
84                     });
85                 });
86             });
87             
88             describe("when 3 arguments", function() {
89                 it("should return an object with correct values", function() {
90                     expect(proto.parseBox("10 5 10")).toEqual({
91                         top   : 10,
92                         right : 5,
93                         bottom: 10,
94                         left  : 5
95                     });
96                 });
97             });
98             
99             describe("when 4 arguments", function() {
100                 it("should return an object with correct values", function() {
101                     expect(proto.parseBox("10 5 15 0")).toEqual({
102                         top   : 10,
103                         right : 5,
104                         bottom: 15,
105                         left  : 0
106                     });
107                 });
108             });
109         });
110     });
111     
112     describe("unitizeBox", function() {
113         it("should return a string", function() {
114             expect(proto.unitizeBox('10 5 15 0')).toEqual('10px 5px 15px 0px');
115         });
116     });
117     
118     describe("normalize", function() {
119         it("should change border-radius > borderRadius", function() {
120             expect(proto.normalize('border-radius')).toEqual('borderRadius');
121         });
122     });
123     
124     describe("getDocumentHeight", function() {
125         it("should return the document height", function() {
126             var result = proto.getDocumentHeight();
127             
128             expect(result).toBeDefined();
129             expect(Ext.isNumber(result)).toBeTruthy();
130         });
131     });
132     
133     describe("getDocumentWidth", function() {
134         it("should return the document width", function() {
135             var result = proto.getDocumentWidth();
136             
137             expect(result).toBeDefined();
138             expect(Ext.isNumber(result)).toBeTruthy();
139         });
140     });
141     
142     describe("getViewportHeight", function() {
143         it("should return the window height", function() {
144             var result = proto.getViewportHeight();
145             
146             expect(result).toBeDefined();
147             expect(Ext.isNumber(result)).toBeTruthy();
148         });
149     });
150     
151     describe("getViewportWidth", function() {
152         it("should return the window width", function() {
153             var result = proto.getViewportWidth();
154             
155             expect(result).toBeDefined();
156             expect(Ext.isNumber(result)).toBeTruthy();
157         });
158     });
159     
160     describe("getViewSize", function() {
161         it("should return the window height and width", function() {
162             expect(proto.getViewSize()).toEqual({
163                 width : window.innerWidth,
164                 height: window.innerHeight
165             });
166         });
167     });
168     
169     describe("getOrientation", function() {
170         it("should return the correct orientation", function() {
171             expect(proto.getOrientation()).toEqual((window.innerHeight > window.innerWidth) ? 'portrait' : 'landscape');
172         });
173     });
174     
175     describe("fromPoint", function() {
176         it("should return nothing", function() {
177                 expect(proto.fromPoint(-550000, -550000)).toBeNull();
178         });
179     });
180 }, "/src/dom/Element.static.js");