1 describe("Ext-more", function() {
2 describe("Ext.id", function(){
4 describe("if element passed as first argument is different of document or window", function() {
5 beforeEach(function() {
6 el = document.createElement("div");
7 document.body.appendChild(el);
11 Ext.getBody().dom.removeChild(el);
14 it("should generate an unique id for the element with default prefix ext-gen", function() {
15 expect(Ext.id(el)).toEqual("ext-gen" + Ext.idSeed);
18 it("should generate an unique id for the element with custom prefix", function() {
19 var prefix = "nico-yhwh";
20 expect(Ext.id(el, prefix)).toEqual(prefix + Ext.idSeed);
23 it("should not override existing id", function() {
26 expect(Ext.id(el)).toEqual(id);
30 describe("if element passed as first argument is document", function() {
31 it("should return Ext.documentId", function() {
32 expect(Ext.id(document)).toEqual(Ext.documentId);
36 describe("if element passed as first argument is window", function() {
37 it("should return Ext.windowId", function() {
38 expect(Ext.id(window)).toEqual(Ext.windowId);
43 describe("Ext.getBody", function() {
44 it("should return current document body as an Ext.core.Element", function() {
45 expect(Ext.getBody()).toEqual(Ext.get(document.body));
49 describe("Ext.getHead", function() {
50 it("should return current document head as an Ext.core.Element", function() {
51 expect(Ext.getHead()).toEqual(Ext.get(document.getElementsByTagName("head")[0]));
55 describe("Ext.getDoc", function() {
56 it("should return the current HTML document object as an Ext.element", function() {
57 expect(Ext.getDoc()).toEqual(Ext.get(document));
61 describe("Ext.getCmp", function() {
62 it("should return a component", function() {
63 var cmp = new Ext.Component({id: 'foobar'});
64 expect(Ext.getCmp('foobar')).toBe(cmp);
69 describe("Ext.getOrientation", function() {
70 it("should return the current orientation of the mobile device", function() {
71 if (window.innerHeight <= window.innerWidth) {
72 expect(Ext.getOrientation()).toEqual("landscape");
74 expect(Ext.getOrientation()).toEqual("portrait");
79 describe("Ext.callback", function() {
82 beforeEach(function() {
83 cfn = jasmine.createSpy();
86 afterEach(function() {
90 it("should execute the passed function in the specified scope", function() {
91 Ext.callback(cfn, fakeScope);
92 expect(cfn.calls[0].object).toBe(fakeScope);
95 it("should pass arguments to the callback function", function() {
96 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6]);
97 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4,6);
100 it("should be able to defer function call", function() {
102 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6], 1);
103 expect(cfn).not.toHaveBeenCalled();
107 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4, 6);
108 expect(cfn.calls[0].object).toBe(fakeScope);
114 describe("Ext.destroy", function() {
117 beforeEach(function() {
118 o1 = jasmine.createSpyObj("o1", ["destroy"]);
120 o2 = jasmine.createSpyObj("o2", ["destroy"]);
122 o3 = jasmine.createSpyObj("o3", ["dest"]);
126 it("should destroy an object", function() {
129 expect(o1.destroy).toHaveBeenCalled();
132 it("should no destroy an object without a destroy method", function() {
135 expect(o3.dest).not.toHaveBeenCalled();
138 it("should destroy an array of objects", function() {
139 Ext.destroy([o1, o2, o3]);
141 expect(o1.destroy).toHaveBeenCalled();
142 expect(o2.destroy).toHaveBeenCalled();
143 expect(o3.dest).not.toHaveBeenCalled();
146 it("should destroy multiple objects", function() {
147 Ext.destroy(o1, o2, o3);
149 expect(o1.destroy).toHaveBeenCalled();
150 expect(o2.destroy).toHaveBeenCalled();
151 expect(o3.dest).not.toHaveBeenCalled();
154 it("should remove dom if object is an Ext.element", function() {
155 var el = Ext.getBody().createChild({id: "to_destroy"});
159 expect(Ext.fly("to_destroy")).toBeNull();
163 describe("Ext.htmlEncode", function() {
164 var htmlEncode = Ext.String.htmlEncode,
167 it("should replace ampersands", function() {
168 str = "Fish & Chips";
170 expect(htmlEncode(str)).toEqual("Fish & Chips");
173 it("should replace less than", function() {
174 str = "Fish > Chips";
176 expect(htmlEncode(str)).toEqual("Fish > Chips");
179 it("should replace greater than", function() {
180 str = "Fish < Chips";
182 expect(htmlEncode(str)).toEqual("Fish < Chips");
185 it("should replace double quote", function() {
186 str = 'Fish " Chips';
188 expect(htmlEncode(str)).toEqual("Fish " Chips");
192 describe("Ext.htmlEncode", function() {
193 var htmlDecode = Ext.String.htmlDecode,
196 it("should replace ampersands", function() {
197 str = "Fish & Chips";
199 expect(htmlDecode(str)).toEqual("Fish & Chips");
202 it("should replace less than", function() {
203 str = "Fish > Chips";
205 expect(htmlDecode(str)).toEqual("Fish > Chips");
208 it("should replace greater than", function() {
209 str = "Fish < Chips";
211 expect(htmlDecode(str)).toEqual("Fish < Chips");
214 it("should replace double quote", function() {
215 str = 'Fish " Chips';
217 expect(htmlDecode(str)).toEqual('Fish " Chips');
221 describe("Ext.urlAppend", function() {
222 var url = "http://example.com/";
224 it("should manage question mark", function() {
225 expect(Ext.urlAppend(url, "test=1")).toEqual("http://example.com/?test=1");
228 it("should manage ampersand", function() {
229 expect(Ext.urlAppend(url + "?test=1","foo=2")).toEqual("http://example.com/?test=1&foo=2");
232 it("should return directly url if content is empty", function() {
233 expect(Ext.urlAppend(url)).toEqual(url);
237 describe("Ext.getDom", function() {
240 beforeEach(function() {
241 el1 = Ext.getBody().createChild({id: "elone"});
244 afterEach(function() {
248 it("should return a dom element if an Ext.element is passed as first argument", function() {
249 expect(Ext.getDom(el1)).toEqual(el1.dom);
252 it("should return a dom element if the string (id) passed as first argument", function() {
253 expect(Ext.getDom("elone")).toEqual(el1.dom);
257 describe("Ext.removeNode", function(){
258 describe("if passed element isn't body", function() {
260 beforeEach(function() {
261 el = Ext.getBody().createChild({
269 it("should remove a dom element from document", function(){
270 Ext.removeNode(el.dom);
271 expect(document.body.childNodes[0]).toBeUndefined();
274 it("should delete the cache reference", function() {
275 Ext.removeNode(el.dom);
276 expect(Ext.cache[id]).toBeUndefined();
279 it("should remove all listeners from the dom element", function() {
280 var listener = jasmine.createSpy();
281 el.on('mouseup', listener);
282 Ext.removeNode(el.dom);
283 jasmine.fireMouseEvent(el.dom, 'mouseup');
284 expect(listener).not.toHaveBeenCalled();
288 describe("if passed element is body", function() {
289 it("should not delete the cache reference", function() {
290 Ext.removeNode(document.body);
291 expect(Ext.cache[Ext.getBody().id]).toBeDefined();
294 it("should not remove listeners from body", function() {
295 var listener = jasmine.createSpy();
296 Ext.getBody().on('mouseup', listener);
297 Ext.removeNode(document.body);
298 jasmine.fireMouseEvent(document.body, 'mouseup');
299 expect(listener).toHaveBeenCalled();
300 Ext.getBody().un('mouseup', listener);
304 describe("if enableNestedListenerRemoval is true", function() {
307 beforeEach(function(){
308 Ext.enableNestedListenerRemoval = true;
309 el = Ext.getBody().createChild();
310 child = el.createChild();
313 afterEach(function(){
314 Ext.enableNestedListenerRemoval = false;
317 it("should remove listener on children", function() {
318 var listener = jasmine.createSpy();
319 child.on('mouseup', listener);
320 Ext.removeNode(el.dom);
321 jasmine.fireMouseEvent(child.dom, 'mouseup');
322 expect(listener).not.toHaveBeenCalled();
327 describe("if enableNestedListenerRemoval is false (default)", function() {
330 beforeEach(function(){
331 el = Ext.getBody().createChild();
332 child = el.createChild();
335 it("should not remove listener on children", function() {
336 var listener = jasmine.createSpy();
337 child.on('mouseup', listener);
338 Ext.removeNode(el.dom);
339 jasmine.fireMouseEvent(child.dom, 'mouseup');
340 expect(listener).toHaveBeenCalled();
341 Ext.EventManager.purgeElement(child.dom);
346 describe("Ext.addBehaviors", function() {
347 var listener, span1, span2, div1;
349 beforeEach(function() {
350 span1 = Ext.getBody().createChild({
354 span2 = Ext.getBody().createChild({
358 div1 = Ext.getBody().createChild({
362 listener = jasmine.createSpy();
365 afterEach(function() {
371 it("should apply event listeners to elements by selectors", function() {
373 'span @mouseup': listener
376 jasmine.fireMouseEvent(span1.dom, 'mouseup');
377 jasmine.fireMouseEvent(span2.dom, 'mouseup');
378 jasmine.fireMouseEvent(div1.dom, 'mouseup');
380 expect(listener.calls.length).toEqual(2);
384 it("should manage multiple selectors", function() {
386 'span, div.foo @mouseup': listener
389 jasmine.fireMouseEvent(span1.dom, 'mouseup');
390 jasmine.fireMouseEvent(span2.dom, 'mouseup');
391 jasmine.fireMouseEvent(div1.dom, 'mouseup');
393 expect(listener.calls.length).toEqual(3);
398 describe("Ext.getScrollBarWidth", function() {
399 it("should return a number between 10 and 40 (we assume that document is loaded)", function() {
400 expect(Ext.getScrollBarWidth() > 10).toBe(true);
401 expect(Ext.getScrollBarWidth() < 40).toBe(true);
405 describe("Ext.copyTo", function(){
408 beforeEach(function() {
419 afterEach(function(){
424 describe("with an array of named properties", function() {
425 it("should copy a set of named properties fom the source object to the destination object.", function() {
426 Ext.copyTo(dest, src, ['a', 'b', 'e']);
428 expect(dest).toEqual({
435 describe("with a string list of named properties", function() {
436 it("should copy a set of named properties fom the source object to the destination object.", function() {
437 Ext.copyTo(dest, src, 'c,b,e');
438 expect(dest).toEqual({
446 describe("Ext.destroyMembers", function() {
447 var obj, destroyable;
449 beforeEach(function(){
451 destroy: jasmine.createSpy()
462 it("should remove named properties from a passed object", function() {
463 Ext.destroyMembers(obj, 'a', 'c', 'i');
464 expect(obj).toEqual({
471 it("should attempt to destroy passed properties", function() {
472 Ext.destroyMembers(obj, 'a', 'c', 'me');
474 expect(destroyable.destroy).toHaveBeenCalled();
478 describe("Ext.partition", function() {
479 describe("with an array of boolean", function() {
480 it("should partition the set into two sets: a true and a false set", function() {
481 expect(Ext.partition([true, true, false, false, true])).toEqual([[true,true,true], [false,false]]);
485 describe("with an array to partition and a function to determine truth", function() {
486 it("should partition the set into two sets: a true and a false set", function() {
493 expect(Ext.partition(array, function(item){
502 describe("with a NodeList to partition and a function to determine truth", function() {
503 it("should partition the set into two sets: a true and a false set", function() {
506 p[0] = Ext.getBody().createChild({
510 p[1] = Ext.getBody().createChild({
514 p[2] = Ext.getBody().createChild({
518 p[3] = Ext.getBody().createChild({
522 p[4] = Ext.getBody().createChild({
526 p[5] = Ext.getBody().createChild({
531 expect(Ext.partition(Ext.query("p"), function(val){
532 return val.className == "class1"
534 [p[0].dom, p[2].dom, p[5].dom],
535 [p[1].dom, p[3].dom, p[4].dom]
538 Ext.Array.each(p, function(el) {