3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 describe("Ext.Element.traversal", function() {
16 var proto = Ext.Element,
19 child1, child2, child3, child4, child5;
21 beforeEach(function() {
22 testEl = Ext.getBody().createChild({
23 id : 'ExtElementHelper',
25 style : 'position:absolute;',
27 {id: 'child1', style: 'position:absolute;'},
28 {id: 'child2', style: 'position:absolute;'},
29 {id: 'child3', style: 'position:absolute;'},
42 testInputEl = Ext.getBody().createChild({
43 id : 'ExtElementInputHelper',
48 el = new Ext.Element(Ext.getDom(testEl));
49 input = new Ext.Element(Ext.getDom(testInputEl));
51 child1 = Ext.get('child1');
52 child2 = Ext.get('child2');
53 child3 = Ext.get('child3');
54 child4 = Ext.get('child4');
55 child5 = Ext.get('child5');
58 afterEach(function() {
63 describe("findParentNode", function() {
64 it("should return null", function() {
65 expect(el.findParentNode('body')).toBeNull();
68 it("should return a dom", function() {
69 expect(child1.findParentNode('.wrapper')).toEqual(Ext.getDom(el));
72 it("should return an el", function() {
73 expect(child1.findParentNode('.wrapper', null, true)).toEqual(el);
76 describe("when maxDepth", function() {
77 describe("1", function() {
78 it("should not return the el", function() {
79 expect(child5.findParentNode('.wrapper', 1)).toBeNull();
83 describe("2", function() {
84 it("should not return the el", function() {
85 expect(child5.findParentNode('.wrapper', 2)).toEqual(Ext.getDom(el));
91 describe("up", function() {
92 it("should return null", function() {
93 expect(el.up('body')).toBeNull();
96 it("should return a el", function() {
97 expect(child1.up('.wrapper')).toEqual(el);
100 describe("when maxDepth", function() {
101 describe("1", function() {
102 it("should not return the el", function() {
103 expect(child5.up('.wrapper', 1)).toBeNull();
107 describe("2", function() {
108 it("should not return the el", function() {
109 expect(child5.up('.wrapper', 2)).toEqual(el);
115 describe("select", function() {
116 it("should return an Ext.CompositeELementLite", function() {
117 var result = el.select('div');
118 expect(result).toBeDefined();
119 expect(result.elements.length).toEqual(5);
120 expect(result instanceof Ext.CompositeElementLite).toBe(true);
124 describe("query", function() {
125 it("should return elements", function() {
126 var result = el.query('div');
128 expect(result).toBeDefined();
129 expect(result.length).toEqual(5);
130 expect(result.isComposite).toBeFalsy();
131 expect(Ext.isArray(result)).toBeTruthy();
135 describe("down", function() {
136 it("should return an el", function() {
137 var result = el.down('.findIt');
139 expect(result).toBeDefined();
140 expect(Ext.isElement(result)).toBeFalsy();
143 it("should return a dom", function() {
144 var result = el.down('.findIt', true);
146 expect(result).toBeDefined();
147 expect(Ext.isElement(result)).toBeTruthy();
151 describe("child", function() {
152 it("should return null", function() {
153 var result = el.child('.findIt');
155 expect(result).toBeNull();
158 it("should return an el", function() {
159 var result = child4.child('.findIt');
161 expect(result).toBeDefined();
162 expect(Ext.isElement(result)).toBeFalsy();
165 it("should return a dom", function() {
166 var result = child4.child('.findIt', true);
168 expect(result).toBeDefined();
169 expect(Ext.isElement(result)).toBeTruthy();
173 describe("parent", function() {
174 it("should return an el", function() {
175 var result = child1.parent();
177 expect(result).toBeDefined();
178 expect(result).toEqual(el);
179 expect(Ext.isElement(result)).toBeFalsy();
182 it("should return a dom", function() {
183 var result = child1.parent(null, true);
185 expect(result).toBeDefined();
186 expect(result).toEqual(Ext.getDom(el));
187 expect(Ext.isElement(result)).toBeTruthy();
191 describe("next", function() {
192 it("should return an el", function() {
193 var result = child1.next();
195 expect(result).toBeDefined();
196 expect(result).toEqual(child2);
197 expect(Ext.isElement(result)).toBeFalsy();
200 it("should return a dom", function() {
201 var result = child1.next(null, true);
203 expect(result).toBeDefined();
204 expect(result).toEqual(Ext.getDom(child2));
205 expect(Ext.isElement(result)).toBeTruthy();
209 describe("prev", function() {
210 it("should return an el", function() {
211 var result = child2.prev();
213 expect(result).toBeDefined();
214 expect(result).toEqual(child1);
215 expect(Ext.isElement(result)).toBeFalsy();
218 it("should return a dom", function() {
219 var result = child2.prev(null, true);
221 expect(result).toBeDefined();
222 expect(result).toEqual(Ext.getDom(child1));
223 expect(Ext.isElement(result)).toBeTruthy();
227 describe("first", function() {
228 it("should return an el", function() {
229 var result = el.first();
231 expect(result).toBeDefined();
232 expect(result).toEqual(child1);
233 expect(Ext.isElement(result)).toBeFalsy();
236 it("should return a dom", function() {
237 var result = el.first(null, true);
239 expect(result).toBeDefined();
240 expect(result).toEqual(Ext.getDom(child1));
241 expect(Ext.isElement(result)).toBeTruthy();
245 describe("last", function() {
246 it("should return an el", function() {
247 var result = el.last();
249 expect(result).toBeDefined();
250 expect(result).toEqual(child4);
251 expect(Ext.isElement(result)).toBeFalsy();
254 it("should return a dom", function() {
255 var result = el.last(null, true);
257 expect(result).toBeDefined();
258 expect(result).toEqual(Ext.getDom(child4));
259 expect(Ext.isElement(result)).toBeTruthy();
263 describe("findParent", function() {
264 it("should return null", function() {
265 expect(el.findParent('body')).toBeNull();
268 it("should return a dom", function() {
269 expect(child1.findParent('.wrapper')).toEqual(Ext.getDom(el));
272 it("should return an el", function() {
273 expect(child1.findParent('.wrapper', null, true)).toEqual(el);
276 describe("when maxDepth", function() {
277 describe("1", function() {
278 it("should not return the el", function() {
279 expect(child5.findParent('.wrapper', 1)).toBeNull();
283 describe("2", function() {
284 it("should not return the el", function() {
285 expect(child5.findParent('.wrapper', 2)).toBeNull();
289 describe("3", function() {
290 it("should return the el", function() {
291 expect(child5.findParent('.wrapper', 3)).toEqual(Ext.getDom(el));
295 describe("NaN", function() {
296 it("should use Number.MAX_VALUE", function() {
297 expect(child5.findParent('.wrapper', Ext.getBody())).toEqual(Ext.getDom(el));
302 }, "/src/dom/Element.traversal.js");