1 describe("Ext.core.Element.insertion", function() {
2 var proto = Ext.core.Element.prototype,
5 child1, child2, child3;
7 beforeEach(function() {
8 testEl = Ext.getBody().createChild({
9 id: 'ExtElementHelper',
17 testSpanEl = Ext.getBody().createChild({
18 id : 'ExtElementSpanHelper',
22 el = new Ext.core.Element(Ext.getDom(testEl));
23 span = new Ext.core.Element(Ext.getDom(testSpanEl));
25 child1 = Ext.get('child1');
26 child2 = Ext.get('child2');
27 child3 = Ext.get('child3');
30 afterEach(function() {
34 describe("appendChild", function() {
35 it("should append the child", function() {
36 expect(el.contains(span)).toBeFalsy();
40 expect(el.contains(span)).toBeTruthy();
44 describe("appendTo", function() {
45 it("should append the el to the specified el", function() {
46 expect(span.contains(el)).toBeFalsy();
50 expect(span.contains(el)).toBeTruthy();
54 describe("insertBefore", function() {
55 it("should insert the el before the specified el", function() {
56 var nodes = Ext.getDom(child1).parentNode.childNodes,
57 array = Ext.toArray(nodes);
60 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(1);
62 child2.insertBefore(child1);
64 nodes = Ext.getDom(child1).parentNode.childNodes;
65 array = Ext.toArray(nodes);
67 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(0);
71 describe("insertAfter", function() {
72 it("should insert the el after the specified el", function() {
73 var nodes = Ext.getDom(child1).parentNode.childNodes,
74 array = Ext.toArray(nodes);
76 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(1);
78 child2.insertAfter(child3);
80 nodes = Ext.getDom(child1).parentNode.childNodes;
81 array = Ext.toArray(nodes);
83 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(2);
87 describe("insertFirst", function() {
88 it("should insert the el into the specified el", function() {
89 var nodes = Ext.getDom(child2).childNodes;
90 expect(nodes.length).toEqual(0);
92 child2.insertFirst(child1);
94 nodes = Ext.getDom(child2).childNodes;
95 expect(nodes.length).toEqual(1);
99 describe("insertSibling", function() {
100 describe("when array", function() {
101 describe("after", function() {
102 it("should create each of the elements and add them to the el parent", function() {
103 var nodes = Ext.getDom(el).childNodes;
104 expect(nodes.length).toEqual(3);
106 child1.insertSibling([
111 nodes = Ext.getDom(el).childNodes;
112 expect(nodes.length).toEqual(5);
116 describe("before", function() {
117 it("should create each of the elements and add them to the el parent", function() {
118 var nodes = Ext.getDom(el).childNodes;
119 expect(nodes.length).toEqual(3);
121 child1.insertSibling([
126 nodes = Ext.getDom(el).childNodes;
127 expect(nodes.length).toEqual(5);
132 describe("when Ext.core.Element", function() {
133 describe("after", function() {
134 it("should move the element next to the el", function() {
135 var nodes = Ext.getDom(el).childNodes;
136 expect(nodes.length).toEqual(3);
138 child1.insertSibling(span, 'after');
140 nodes = Ext.getDom(el).childNodes;
141 expect(nodes.length).toEqual(4);
145 describe("before", function() {
146 it("should move the element next to the el", function() {
147 var nodes = Ext.getDom(el).childNodes;
148 expect(nodes.length).toEqual(3);
150 child1.insertSibling(span, 'before');
152 nodes = Ext.getDom(el).childNodes;
153 expect(nodes.length).toEqual(4);
158 describe("other", function() {
159 describe("after", function() {
160 it("should move the element next to the el", function() {
161 var nodes = Ext.getDom(el).childNodes;
162 expect(nodes.length).toEqual(3);
164 child1.insertSibling({
168 nodes = Ext.getDom(el).childNodes;
169 expect(nodes.length).toEqual(4);
172 it("should move the element next to the el", function() {
173 var nodes = Ext.getDom(el).childNodes;
174 expect(nodes.length).toEqual(3);
176 child3.insertSibling({
180 nodes = Ext.getDom(el).childNodes;
181 expect(nodes.length).toEqual(4);
185 describe("before", function() {
186 it("should move the element next to the el", function() {
187 var nodes = Ext.getDom(el).childNodes;
188 expect(nodes.length).toEqual(3);
190 child1.insertSibling({
194 nodes = Ext.getDom(el).childNodes;
195 expect(nodes.length).toEqual(4);
198 describe("return dom", function() {
199 it("should move the element next to the el", function() {
200 var nodes = Ext.getDom(el).childNodes,
203 expect(nodes.length).toEqual(3);
205 dom = child1.insertSibling({
209 nodes = Ext.getDom(el).childNodes;
210 expect(nodes.length).toEqual(4);
211 expect(dom).toBeDefined();
218 describe("replace", function() {
219 it("should replace the passed element with this element", function() {
220 var nodes = Ext.getDom(el).childNodes;
221 expect(nodes.length).toEqual(3);
223 child1.replace(child2);
225 nodes = Ext.getDom(el).childNodes;
226 expect(nodes.length).toEqual(2);
230 describe("replaceWith", function() {
231 it("should replace this element with the passed element", function() {
232 var nodes = Ext.getDom(el).childNodes;
233 expect(nodes.length).toEqual(3);
235 child1.replaceWith({tag: "div", cls: "childtestdiv"});
237 expect(child1.hasCls("childtestdiv"));
239 nodes = Ext.getDom(el).childNodes;
240 expect(nodes.length).toEqual(3);
244 describe("createChild", function() {
245 it("should create a child", function() {
246 var nodes = Ext.getDom(el).childNodes;
247 expect(nodes.length).toEqual(3);
249 el.createChild({id: 'child4'});
251 nodes = Ext.getDom(el).childNodes;
252 expect(nodes.length).toEqual(4);
255 it("should create a child before an el", function() {
256 var nodes = Ext.getDom(el).childNodes,
257 array = Ext.toArray(nodes);
259 expect(nodes.length).toEqual(3);
260 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(1);
262 el.createChild({id: 'child4'}, child2);
264 nodes = Ext.getDom(el).childNodes;
265 array = Ext.toArray(nodes);
267 expect(nodes.length).toEqual(4);
268 expect(Ext.Array.indexOf(array, Ext.getDom(child2))).toEqual(2);
272 describe("wrap", function() {
273 it("should wrap the element", function() {
274 var parent = Ext.getDom(child1).parentNode;
280 expect(Ext.getDom(child1).parentNode.parentNode).toEqual(parent);
281 expect(Ext.getDom(child1).parentNode.className).toEqual('wrapper');
284 it("return the el", function() {
285 var node = child1.wrap({
289 expect(Ext.isElement(node)).toBeFalsy();
292 it("return the dom", function() {
293 var node = child1.wrap({
297 expect(Ext.isElement(node)).toBeTruthy();
301 describe("insertHtml", function() {
302 describe("beforeBegin", function() {
303 it("should insert the html", function() {
304 expect(Ext.getDom(el).childNodes.length).toEqual(3);
306 child1.insertHtml('beforeBegin', '<div></div>');
308 expect(Ext.getDom(el).childNodes.length).toEqual(4);
312 describe("afterBegin", function() {
313 it("should insert the html", function() {
314 expect(Ext.getDom(child1).childNodes.length).toEqual(0);
316 child1.insertHtml('afterBegin', '<div></div>');
318 expect(Ext.getDom(child1).childNodes.length).toEqual(1);
322 describe("beforeEnd", function() {
323 it("should insert the html", function() {
324 expect(Ext.getDom(child1).childNodes.length).toEqual(0);
326 child1.insertHtml('beforeEnd', '<div></div>');
328 expect(Ext.getDom(child1).childNodes.length).toEqual(1);
332 describe("afterEnd", function() {
333 it("should insert the html", function() {
334 expect(Ext.getDom(el).childNodes.length).toEqual(3);
336 child1.insertHtml('afterEnd', '<div></div>');
338 expect(Ext.getDom(el).childNodes.length).toEqual(4);
342 it("should return a dom", function() {
343 var node = child1.insertHtml('afterEnd', '<div></div>');
345 expect(Ext.isElement(node)).toBeTruthy();
348 it("should return an el", function() {
349 var node = child1.insertHtml('afterEnd', '<div></div>', true);
351 expect(Ext.isElement(node)).toBeFalsy();
354 }, "/src/dom/Element.insertion.js");