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-more", function() {
16 beforeEach(function() {
19 describe("Ext.id", function(){
21 describe("if element passed as first argument is different of document or window", function() {
22 beforeEach(function() {
23 el = document.createElement("div");
24 document.body.appendChild(el);
28 Ext.getBody().dom.removeChild(el);
31 it("should generate an unique id for the element with default prefix ext-gen", function() {
32 expect(Ext.id(el)).toEqual("ext-gen" + Ext.idSeed);
35 it("should generate an unique id for the element with custom prefix", function() {
36 var prefix = "nico-yhwh";
37 expect(Ext.id(el, prefix)).toEqual(prefix + Ext.idSeed);
40 it("should not override existing id", function() {
43 expect(Ext.id(el)).toEqual(id);
47 describe("if element passed as first argument is document", function() {
48 it("should return Ext.documentId", function() {
49 expect(Ext.id(document)).toEqual(Ext.documentId);
53 describe("if element passed as first argument is window", function() {
54 it("should return Ext.windowId", function() {
55 expect(Ext.id(window)).toEqual(Ext.windowId);
60 describe("Ext.getBody", function() {
61 it("should return current document body as an Ext.Element", function() {
62 expect(Ext.getBody()).toEqual(Ext.get(document.body));
66 describe("Ext.getHead", function() {
67 it("should return current document head as an Ext.Element", function() {
68 expect(Ext.getHead()).toEqual(Ext.get(document.getElementsByTagName("head")[0]));
72 describe("Ext.getDoc", function() {
73 it("should return the current HTML document object as an Ext.element", function() {
74 expect(Ext.getDoc()).toEqual(Ext.get(document));
78 describe("Ext.getCmp", function() {
79 it("should return a component", function() {
80 var cmp = new Ext.Component({id: 'foobar'});
81 expect(Ext.getCmp('foobar')).toBe(cmp);
86 if (!Ext.isWindows && !Ext.isMac && !Ext.isLinux) {
87 describe("Ext.getOrientation", function() {
88 it("should return the current orientation of the mobile device", function() {
89 if (window.innerHeight <= window.innerWidth) {
90 expect(Ext.getOrientation()).toEqual("landscape");
92 expect(Ext.getOrientation()).toEqual("portrait");
98 describe("Ext.callback", function() {
101 beforeEach(function() {
102 cfn = jasmine.createSpy();
105 afterEach(function() {
109 it("should execute the passed function in the specified scope", function() {
110 Ext.callback(cfn, fakeScope);
111 expect(cfn.calls[0].object).toBe(fakeScope);
114 it("should pass arguments to the callback function", function() {
115 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6]);
116 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4,6);
119 it("should be able to defer function call", function() {
121 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6], 1);
122 expect(cfn).not.toHaveBeenCalled();
126 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4, 6);
127 expect(cfn.calls[0].object).toBe(fakeScope);
133 describe("Ext.destroy", function() {
136 beforeEach(function() {
137 o1 = jasmine.createSpyObj("o1", ["destroy"]);
139 o2 = jasmine.createSpyObj("o2", ["destroy"]);
141 o3 = jasmine.createSpyObj("o3", ["dest"]);
145 it("should destroy an object", function() {
148 expect(o1.destroy).toHaveBeenCalled();
151 it("should no destroy an object without a destroy method", function() {
154 expect(o3.dest).not.toHaveBeenCalled();
157 it("should destroy an array of objects", function() {
158 Ext.destroy([o1, o2, o3]);
160 expect(o1.destroy).toHaveBeenCalled();
161 expect(o2.destroy).toHaveBeenCalled();
162 expect(o3.dest).not.toHaveBeenCalled();
165 it("should destroy multiple objects", function() {
166 Ext.destroy(o1, o2, o3);
168 expect(o1.destroy).toHaveBeenCalled();
169 expect(o2.destroy).toHaveBeenCalled();
170 expect(o3.dest).not.toHaveBeenCalled();
173 it("should remove dom if object is an Ext.element", function() {
174 var el = Ext.getBody().createChild({id: "to_destroy"});
178 expect(Ext.fly("to_destroy")).toBeNull();
182 describe("Ext.htmlEncode", function() {
183 var htmlEncode = Ext.String.htmlEncode,
186 it("should replace ampersands", function() {
187 str = "Fish & Chips";
189 expect(htmlEncode(str)).toEqual("Fish & Chips");
192 it("should replace less than", function() {
193 str = "Fish > Chips";
195 expect(htmlEncode(str)).toEqual("Fish > Chips");
198 it("should replace greater than", function() {
199 str = "Fish < Chips";
201 expect(htmlEncode(str)).toEqual("Fish < Chips");
204 it("should replace double quote", function() {
205 str = 'Fish " Chips';
207 expect(htmlEncode(str)).toEqual("Fish " Chips");
211 describe("Ext.htmlEncode", function() {
212 var htmlDecode = Ext.String.htmlDecode,
215 it("should replace ampersands", function() {
216 str = "Fish & Chips";
218 expect(htmlDecode(str)).toEqual("Fish & Chips");
221 it("should replace less than", function() {
222 str = "Fish > Chips";
224 expect(htmlDecode(str)).toEqual("Fish > Chips");
227 it("should replace greater than", function() {
228 str = "Fish < Chips";
230 expect(htmlDecode(str)).toEqual("Fish < Chips");
233 it("should replace double quote", function() {
234 str = 'Fish " Chips';
236 expect(htmlDecode(str)).toEqual('Fish " Chips');
240 describe("Ext.urlAppend", function() {
241 var url = "http://example.com/";
243 it("should manage question mark", function() {
244 expect(Ext.urlAppend(url, "test=1")).toEqual("http://example.com/?test=1");
247 it("should manage ampersand", function() {
248 expect(Ext.urlAppend(url + "?test=1","foo=2")).toEqual("http://example.com/?test=1&foo=2");
251 it("should return directly url if content is empty", function() {
252 expect(Ext.urlAppend(url)).toEqual(url);
256 describe("Ext.getDom", function() {
259 beforeEach(function() {
260 el1 = Ext.getBody().createChild({id: "elone"});
263 afterEach(function() {
267 it("should return a dom element if an Ext.element is passed as first argument", function() {
268 expect(Ext.getDom(el1)).toEqual(el1.dom);
271 it("should return a dom element if the string (id) passed as first argument", function() {
272 expect(Ext.getDom("elone")).toEqual(el1.dom);
276 describe("Ext.removeNode", function(){
277 describe("if passed element isn't body", function() {
279 beforeEach(function() {
280 el = Ext.getBody().createChild({
287 it("should remove a dom element from document", function(){
288 Ext.removeNode(el.dom);
290 expect(el.dom.parentNode).toBe(null);
292 expect(el.dom.parentNode.innerHTML).toBe(undefined);
296 it("should delete the cache reference", function() {
297 Ext.removeNode(el.dom);
298 expect(Ext.cache[id]).toBeUndefined();
300 if (!Ext.isIE6 && !Ext.isIE7) {
301 it("should remove all listeners from the dom element", function() {
302 var listener = jasmine.createSpy();
303 el.on('mouseup', listener);
304 Ext.removeNode(el.dom);
305 jasmine.fireMouseEvent(el.dom, 'mouseup');
306 expect(listener).not.toHaveBeenCalled();
312 describe("if passed element is body", function() {
313 it("should not delete the cache reference", function() {
314 Ext.removeNode(document.body);
315 expect(Ext.cache[Ext.getBody().id]).toBeDefined();
318 it("should not remove listeners from body", function() {
319 var listener = jasmine.createSpy();
320 Ext.getBody().on('mouseup', listener);
321 Ext.removeNode(document.body);
322 jasmine.fireMouseEvent(document.body, 'mouseup');
323 expect(listener).toHaveBeenCalled();
324 Ext.getBody().un('mouseup', listener);
328 if (!Ext.isIE6 && !Ext.isIE7) {
329 describe("if enableNestedListenerRemoval is true", function() {
332 beforeEach(function(){
333 Ext.enableNestedListenerRemoval = true;
334 el = Ext.getBody().createChild();
335 child = el.createChild();
338 afterEach(function(){
339 Ext.enableNestedListenerRemoval = false;
342 it("should remove listener on children", function() {
343 var listener = jasmine.createSpy();
344 child.on('mouseup', listener);
345 Ext.removeNode(el.dom);
346 jasmine.fireMouseEvent(child.dom, 'mouseup');
347 expect(listener).not.toHaveBeenCalled();
353 if (!Ext.isIE6 && !Ext.isIE7) {
354 describe("if enableNestedListenerRemoval is false (default)", function() {
357 beforeEach(function(){
358 el = Ext.getBody().createChild();
359 child = el.createChild();
362 it("should not remove listener on children", function() {
363 var listener = jasmine.createSpy();
364 child.on('mouseup', listener);
365 Ext.removeNode(el.dom);
366 jasmine.fireMouseEvent(child.dom, 'mouseup');
367 expect(listener).toHaveBeenCalled();
368 Ext.EventManager.purgeElement(child.dom);
374 describe("Ext.addBehaviors", function() {
375 var listener, span1, span2, div1;
377 beforeEach(function() {
378 span1 = Ext.getBody().createChild({
382 span2 = Ext.getBody().createChild({
386 div1 = Ext.getBody().createChild({
390 listener = jasmine.createSpy();
393 afterEach(function() {
399 it("should apply event listeners to elements by selectors", function() {
401 'span @mouseup': listener
404 jasmine.fireMouseEvent(span1.dom, 'mouseup');
405 jasmine.fireMouseEvent(span2.dom, 'mouseup');
406 jasmine.fireMouseEvent(div1.dom, 'mouseup');
408 expect(listener.calls.length).toEqual(2);
412 it("should manage multiple selectors", function() {
414 'span, div.foo @mouseup': listener
417 jasmine.fireMouseEvent(span1.dom, 'mouseup');
418 jasmine.fireMouseEvent(span2.dom, 'mouseup');
419 jasmine.fireMouseEvent(div1.dom, 'mouseup');
421 expect(listener.calls.length).toEqual(3);
426 describe("Ext.getScrollBarWidth", function() {
427 it("should return a number between 10 and 40 (we assume that document is loaded)", function() {
428 expect(Ext.getScrollBarWidth() > 10).toBe(true);
429 expect(Ext.getScrollBarWidth() < 40).toBe(true);
433 describe("Ext.copyTo", function(){
436 beforeEach(function() {
447 afterEach(function(){
452 describe("with an array of named properties", function() {
453 it("should copy a set of named properties fom the source object to the destination object.", function() {
454 Ext.copyTo(dest, src, ['a', 'b', 'e']);
456 expect(dest).toEqual({
463 describe("with a string list of named properties", function() {
464 it("should copy a set of named properties fom the source object to the destination object.", function() {
465 Ext.copyTo(dest, src, 'c,b,e');
466 expect(dest).toEqual({
474 describe("Ext.destroyMembers", function() {
475 var obj, destroyable;
477 beforeEach(function(){
479 destroy: jasmine.createSpy()
490 it("should remove named properties from a passed object", function() {
491 Ext.destroyMembers(obj, 'a', 'c', 'i');
492 expect(obj).toEqual({
499 it("should attempt to destroy passed properties", function() {
500 Ext.destroyMembers(obj, 'a', 'c', 'me');
502 expect(destroyable.destroy).toHaveBeenCalled();
506 describe("Ext.partition", function() {
507 describe("with an array of boolean", function() {
508 it("should partition the set into two sets: a true and a false set", function() {
509 expect(Ext.partition([true, true, false, false, true])).toEqual([[true,true,true], [false,false]]);
513 describe("with an array to partition and a function to determine truth", function() {
514 it("should partition the set into two sets: a true and a false set", function() {
521 expect(Ext.partition(array, function(item){
530 describe("with a NodeList to partition and a function to determine truth", function() {
531 it("should partition the set into two sets: a true and a false set", function() {
534 p[0] = Ext.getBody().createChild({
538 p[1] = Ext.getBody().createChild({
542 p[2] = Ext.getBody().createChild({
546 p[3] = Ext.getBody().createChild({
550 p[4] = Ext.getBody().createChild({
554 p[5] = Ext.getBody().createChild({
559 expect(Ext.partition(Ext.query("p"), function(val){
560 return val.className == "class1";
562 [p[0].dom, p[2].dom, p[5].dom],
563 [p[1].dom, p[3].dom, p[4].dom]
566 Ext.Array.each(p, function(el) {