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