]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.Element.traversal", function() {\r |
2 | var el, input, child1, child2, child3, child4, child4_1, child4_1_1;\r | |
3 | \r | |
4 | beforeEach(function() {\r | |
5 | el = Ext.getBody().createChild({\r | |
6 | id : 'ExtElementHelper',\r | |
7 | cls : 'wrapper',\r | |
8 | style : 'position:absolute;',\r | |
9 | children: [\r | |
10 | {id: 'child1', style: 'position:absolute;'},\r | |
11 | {id: 'child2', style: 'position:absolute;'},\r | |
12 | {id: 'child3', style: 'position:absolute;'},\r | |
13 | {\r | |
14 | id: 'child4',\r | |
15 | children: [\r | |
16 | {\r | |
17 | id : 'child4_1',\r | |
18 | cls: 'findIt',\r | |
19 | children: [\r | |
20 | {\r | |
21 | id : 'child4_1_1'\r | |
22 | }\r | |
23 | ]\r | |
24 | }\r | |
25 | ]\r | |
26 | }\r | |
27 | ]\r | |
28 | });\r | |
29 | \r | |
30 | input = Ext.getBody().createChild({\r | |
31 | id : 'ExtElementInputHelper',\r | |
32 | tag : 'input',\r | |
33 | type: 'text'\r | |
34 | });\r | |
35 | \r | |
36 | child1 = Ext.get('child1');\r | |
37 | child2 = Ext.get('child2');\r | |
38 | child3 = Ext.get('child3');\r | |
39 | child4 = Ext.get('child4');\r | |
40 | child4_1 = Ext.get('child4_1');\r | |
41 | child4_1_1 = Ext.get('child4_1_1');\r | |
42 | });\r | |
43 | \r | |
44 | afterEach(function() {\r | |
45 | Ext.each(\r | |
46 | [el, input, child1, child2, child3, child4, child4_1, child4_1_1],\r | |
47 | function(el) {\r | |
48 | el.destroy();\r | |
49 | }\r | |
50 | );\r | |
51 | });\r | |
52 | \r | |
53 | describe("findParentNode", function() {\r | |
54 | it("should return document.body", function() {\r | |
55 | expect(el.findParentNode('body')).toEqual(document.body);\r | |
56 | });\r | |
57 | \r | |
58 | it("should return a dom", function() {\r | |
59 | expect(child1.findParentNode('.wrapper')).toEqual(Ext.getDom(el));\r | |
60 | });\r | |
61 | \r | |
62 | it("should return an el", function() {\r | |
63 | expect(child1.findParentNode('.wrapper', null, true)).toEqual(el);\r | |
64 | });\r | |
65 | \r | |
66 | describe("when maxDepth", function() {\r | |
67 | describe("1", function() {\r | |
68 | it("should not return the el", function() {\r | |
69 | expect(child4_1.findParentNode('.wrapper', 1)).toBeNull();\r | |
70 | });\r | |
71 | });\r | |
72 | \r | |
73 | describe("2", function() {\r | |
74 | it("should not return the el", function() {\r | |
75 | expect(child4_1.findParentNode('.wrapper', 2)).toEqual(Ext.getDom(el));\r | |
76 | });\r | |
77 | });\r | |
78 | });\r | |
79 | });\r | |
80 | \r | |
81 | describe("up", function() {\r | |
82 | it("should return Ext.getBody()", function() {\r | |
83 | expect(el.up('body')).toEqual(Ext.getBody());\r | |
84 | });\r | |
85 | \r | |
86 | it("should return a el", function() {\r | |
87 | expect(child1.up('.wrapper')).toEqual(el);\r | |
88 | });\r | |
89 | \r | |
90 | describe("when maxDepth", function() {\r | |
91 | describe("1", function() {\r | |
92 | it("should not return the el", function() {\r | |
93 | expect(child4_1.up('.wrapper', 1)).toBeNull();\r | |
94 | });\r | |
95 | });\r | |
96 | \r | |
97 | describe("2", function() {\r | |
98 | it("should not return the el", function() {\r | |
99 | expect(child4_1.up('.wrapper', 2)).toEqual(el);\r | |
100 | });\r | |
101 | });\r | |
102 | });\r | |
103 | });\r | |
104 | \r | |
105 | describe("select", function() {\r | |
106 | it("should return an Ext.CompositeELementLite", function() {\r | |
107 | var result = el.select('div');\r | |
108 | expect(result).toBeDefined();\r | |
109 | expect(result.elements.length).toEqual(6);\r | |
110 | expect(result instanceof Ext.CompositeElementLite).toBe(true);\r | |
111 | });\r | |
112 | });\r | |
113 | \r | |
114 | describe("query", function() {\r | |
115 | it("should return elements", function() {\r | |
116 | var result = el.query('div');\r | |
117 | \r | |
118 | expect(result).toBeDefined();\r | |
119 | expect(result.length).toEqual(6);\r | |
120 | expect(result.isComposite).toBeFalsy();\r | |
121 | expect(Ext.isArray(result)).toBeTruthy();\r | |
122 | });\r | |
123 | });\r | |
124 | \r | |
125 | describe("down", function() {\r | |
126 | it("should return an el", function() {\r | |
127 | var result = el.down('.findIt');\r | |
128 | \r | |
129 | expect(result).toBeDefined();\r | |
130 | expect(Ext.isElement(result)).toBeFalsy();\r | |
131 | });\r | |
132 | \r | |
133 | it("should return a dom", function() {\r | |
134 | var result = el.down('.findIt', true);\r | |
135 | \r | |
136 | expect(result).toBeDefined();\r | |
137 | expect(Ext.isElement(result)).toBeTruthy();\r | |
138 | });\r | |
139 | });\r | |
140 | \r | |
141 | describe("child", function() {\r | |
142 | it("should return null", function() {\r | |
143 | var result = el.child('.findIt');\r | |
144 | \r | |
145 | expect(result).toBeNull();\r | |
146 | });\r | |
147 | \r | |
148 | it("should return an el", function() {\r | |
149 | var result = child4.child('.findIt');\r | |
150 | \r | |
151 | expect(result).toBeDefined();\r | |
152 | expect(Ext.isElement(result)).toBeFalsy();\r | |
153 | });\r | |
154 | \r | |
155 | it("should return a dom", function() {\r | |
156 | var result = child4.child('.findIt', true);\r | |
157 | \r | |
158 | expect(result).toBeDefined();\r | |
159 | expect(Ext.isElement(result)).toBeTruthy();\r | |
160 | });\r | |
161 | });\r | |
162 | \r | |
163 | describe("parent", function() {\r | |
164 | it("should return an el", function() {\r | |
165 | var result = child1.parent();\r | |
166 | \r | |
167 | expect(result).toBeDefined();\r | |
168 | expect(result).toEqual(el);\r | |
169 | expect(Ext.isElement(result)).toBeFalsy();\r | |
170 | });\r | |
171 | \r | |
172 | it("should return a dom", function() {\r | |
173 | var result = child1.parent(null, true);\r | |
174 | \r | |
175 | expect(result).toBeDefined();\r | |
176 | expect(result).toEqual(Ext.getDom(el));\r | |
177 | expect(Ext.isElement(result)).toBeTruthy();\r | |
178 | });\r | |
179 | });\r | |
180 | \r | |
181 | describe("next", function() {\r | |
182 | it("should return an el", function() {\r | |
183 | var result = child1.next();\r | |
184 | \r | |
185 | expect(result).toBeDefined();\r | |
186 | expect(result).toEqual(child2);\r | |
187 | expect(Ext.isElement(result)).toBeFalsy();\r | |
188 | });\r | |
189 | \r | |
190 | it("should return a dom", function() {\r | |
191 | var result = child1.next(null, true);\r | |
192 | \r | |
193 | expect(result).toBeDefined();\r | |
194 | expect(result).toEqual(Ext.getDom(child2));\r | |
195 | expect(Ext.isElement(result)).toBeTruthy();\r | |
196 | });\r | |
197 | });\r | |
198 | \r | |
199 | describe("prev", function() {\r | |
200 | it("should return an el", function() {\r | |
201 | var result = child2.prev();\r | |
202 | \r | |
203 | expect(result).toBeDefined();\r | |
204 | expect(result).toEqual(child1);\r | |
205 | expect(Ext.isElement(result)).toBeFalsy();\r | |
206 | });\r | |
207 | \r | |
208 | it("should return a dom", function() {\r | |
209 | var result = child2.prev(null, true);\r | |
210 | \r | |
211 | expect(result).toBeDefined();\r | |
212 | expect(result).toEqual(Ext.getDom(child1));\r | |
213 | expect(Ext.isElement(result)).toBeTruthy();\r | |
214 | });\r | |
215 | });\r | |
216 | \r | |
217 | describe("first", function() {\r | |
218 | it("should return an el", function() {\r | |
219 | var result = el.first();\r | |
220 | \r | |
221 | expect(result).toBeDefined();\r | |
222 | expect(result).toEqual(child1);\r | |
223 | expect(Ext.isElement(result)).toBeFalsy();\r | |
224 | });\r | |
225 | \r | |
226 | it("should return a dom", function() {\r | |
227 | var result = el.first(null, true);\r | |
228 | \r | |
229 | expect(result).toBeDefined();\r | |
230 | expect(result).toEqual(Ext.getDom(child1));\r | |
231 | expect(Ext.isElement(result)).toBeTruthy();\r | |
232 | });\r | |
233 | });\r | |
234 | \r | |
235 | describe("last", function() {\r | |
236 | it("should return an el", function() {\r | |
237 | var result = el.last();\r | |
238 | \r | |
239 | expect(result).toBeDefined();\r | |
240 | expect(result).toEqual(child4);\r | |
241 | expect(Ext.isElement(result)).toBeFalsy();\r | |
242 | });\r | |
243 | \r | |
244 | it("should return a dom", function() {\r | |
245 | var result = el.last(null, true);\r | |
246 | \r | |
247 | expect(result).toBeDefined();\r | |
248 | expect(result).toEqual(Ext.getDom(child4));\r | |
249 | expect(Ext.isElement(result)).toBeTruthy();\r | |
250 | });\r | |
251 | });\r | |
252 | \r | |
253 | describe("findParent", function() {\r | |
254 | it("should return document.body", function() {\r | |
255 | expect(el.findParent('body')).toEqual(document.body);\r | |
256 | });\r | |
257 | \r | |
258 | it("should return a dom", function() {\r | |
259 | expect(child1.findParent('.wrapper')).toEqual(Ext.getDom(el));\r | |
260 | });\r | |
261 | \r | |
262 | it("should return an el", function() {\r | |
263 | expect(child1.findParent('.wrapper', null, true)).toEqual(el);\r | |
264 | });\r | |
265 | \r | |
266 | it("should include itself if it matches", function() {\r | |
267 | expect(child4_1_1.findParent('#child4_1_1', null, true)).toBe(child4_1_1);\r | |
268 | });\r | |
269 | \r | |
270 | it("should default the maxDepth to 50 or the document element", function() {\r | |
271 | var root = Ext.getBody().createChild({\r | |
272 | cls: 'findParentRoot'\r | |
273 | }),\r | |
274 | current = root,\r | |
275 | els = [root],\r | |
276 | i;\r | |
277 | \r | |
278 | for (i = 0; i < 49; ++i) {\r | |
279 | current = current.createChild();\r | |
280 | els.push(current);\r | |
281 | }\r | |
282 | \r | |
283 | expect(current.findParent('.findParentRoot', undefined, true)).toBe(root);\r | |
284 | current = current.createChild();\r | |
285 | els.push(current);\r | |
286 | expect(current.findParent('.findParentRoot', undefined, true)).toBeNull();\r | |
287 | \r | |
288 | expect(els[10].findParent('.doesntExist')).toBeNull();\r | |
289 | \r | |
290 | Ext.destroy(els);\r | |
291 | });\r | |
292 | \r | |
293 | describe("with maxDepth", function() {\r | |
294 | describe("as a number", function() {\r | |
295 | it("should include an element within the limit", function() {\r | |
296 | expect(child4_1_1.findParent('#child4', 3, true)).toBe(child4);\r | |
297 | });\r | |
298 | \r | |
299 | it("should exclude an element at the limit", function() {\r | |
300 | expect(child4_1_1.findParent('#child4', 2, true)).toBeNull();\r | |
301 | });\r | |
302 | \r | |
303 | it("should exclude an element above the limit", function() {\r | |
304 | expect(child4_1_1.findParent('#child4', 1, true)).toBeNull();\r | |
305 | });\r | |
306 | });\r | |
307 | \r | |
308 | describe("as an element", function() {\r | |
309 | it("should accept a string id", function() {\r | |
310 | expect(child4_1_1.findParent('.wrapper', 'child4_1')).toBeNull();\r | |
311 | });\r | |
312 | \r | |
313 | it("should accept a dom element", function() {\r | |
314 | expect(child4_1_1.findParent('.wrapper', child4_1.dom)).toBeNull();\r | |
315 | });\r | |
316 | \r | |
317 | it("should accept an Ext.dom.Element", function() {\r | |
318 | expect(child4_1_1.findParent('.wrapper', child4_1)).toBeNull();\r | |
319 | });\r | |
320 | \r | |
321 | it("should include an element within the limit", function() {\r | |
322 | expect(child4_1_1.findParent('.findIt', child4, true)).toBe(child4_1);\r | |
323 | });\r | |
324 | \r | |
325 | it("should exclude elements at the limit", function() {\r | |
326 | expect(child4_1_1.findParent('#child4', child4, true)).toBeNull();\r | |
327 | });\r | |
328 | \r | |
329 | it("should exclude an element above the limit", function() {\r | |
330 | expect(child4_1_1.findParent('.wrapper', child4, true)).toBeNull();\r | |
331 | });\r | |
332 | });\r | |
333 | });\r | |
334 | });\r | |
335 | \r | |
336 | describe("contains", function(){\r | |
337 | it('should return false for siblings', function(){\r | |
338 | expect(Ext.fly(child1).contains(child4_1_1)).toBe(false);\r | |
339 | expect(Ext.fly(child2).contains(child4_1_1)).toBe(false);\r | |
340 | });\r | |
341 | it('should return true for parents', function(){\r | |
342 | expect(Ext.fly(child4_1).contains(child4_1_1)).toBe(true);\r | |
343 | });\r | |
344 | it('should return true for grandparents', function(){\r | |
345 | expect(Ext.fly(child4).contains(child4_1_1)).toBe(true);\r | |
346 | });\r | |
347 | it('should return true for self', function(){\r | |
348 | expect(Ext.fly(child4_1_1).contains(child4_1_1)).toBe(true);\r | |
349 | });\r | |
350 | });\r | |
351 | }, "/src/dom/Element.traversal.js");\r |