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 describe("Ext.id", function(){
18 describe("if element passed as first argument is different of document or window", function() {
19 beforeEach(function() {
20 el = document.createElement("div");
21 document.body.appendChild(el);
25 Ext.getBody().dom.removeChild(el);
28 it("should generate an unique id for the element with default prefix ext-gen", function() {
29 expect(Ext.id(el)).toEqual("ext-gen" + Ext.idSeed);
32 it("should generate an unique id for the element with custom prefix", function() {
33 var prefix = "nico-yhwh";
34 expect(Ext.id(el, prefix)).toEqual(prefix + Ext.idSeed);
37 it("should not override existing id", function() {
40 expect(Ext.id(el)).toEqual(id);
44 describe("if element passed as first argument is document", function() {
45 it("should return Ext.documentId", function() {
46 expect(Ext.id(document)).toEqual(Ext.documentId);
50 describe("if element passed as first argument is window", function() {
51 it("should return Ext.windowId", function() {
52 expect(Ext.id(window)).toEqual(Ext.windowId);
57 describe("Ext.getBody", function() {
58 it("should return current document body as an Ext.core.Element", function() {
59 expect(Ext.getBody()).toEqual(Ext.get(document.body));
63 describe("Ext.getHead", function() {
64 it("should return current document head as an Ext.core.Element", function() {
65 expect(Ext.getHead()).toEqual(Ext.get(document.getElementsByTagName("head")[0]));
69 describe("Ext.getDoc", function() {
70 it("should return the current HTML document object as an Ext.element", function() {
71 expect(Ext.getDoc()).toEqual(Ext.get(document));
75 describe("Ext.getCmp", function() {
76 it("should return a component", function() {
77 var cmp = new Ext.Component({id: 'foobar'});
78 expect(Ext.getCmp('foobar')).toBe(cmp);
82 if (!Ext.isWindows && !Ext.isMac && !Ext.isLinux) {
83 describe("Ext.getOrientation", function() {
84 it("should return the current orientation of the mobile device", function() {
85 if (window.innerHeight <= window.innerWidth) {
86 expect(Ext.getOrientation()).toEqual("landscape");
88 expect(Ext.getOrientation()).toEqual("portrait");
94 describe("Ext.callback", function() {
97 beforeEach(function() {
98 cfn = jasmine.createSpy();
101 afterEach(function() {
105 it("should execute the passed function in the specified scope", function() {
106 Ext.callback(cfn, fakeScope);
107 expect(cfn.calls[0].object).toBe(fakeScope);
110 it("should pass arguments to the callback function", function() {
111 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6]);
112 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4,6);
115 it("should be able to defer function call", function() {
117 Ext.callback(cfn, fakeScope, [1, 2, 3, 4, 6], 1);
118 expect(cfn).not.toHaveBeenCalled();
122 expect(cfn).toHaveBeenCalledWith(1, 2, 3, 4, 6);
123 expect(cfn.calls[0].object).toBe(fakeScope);
129 describe("Ext.destroy", function() {
132 beforeEach(function() {
133 o1 = jasmine.createSpyObj("o1", ["destroy"]);
135 o2 = jasmine.createSpyObj("o2", ["destroy"]);
137 o3 = jasmine.createSpyObj("o3", ["dest"]);
141 it("should destroy an object", function() {
144 expect(o1.destroy).toHaveBeenCalled();
147 it("should no destroy an object without a destroy method", function() {
150 expect(o3.dest).not.toHaveBeenCalled();
153 it("should destroy an array of objects", function() {
154 Ext.destroy([o1, o2, o3]);
156 expect(o1.destroy).toHaveBeenCalled();
157 expect(o2.destroy).toHaveBeenCalled();
158 expect(o3.dest).not.toHaveBeenCalled();
161 it("should destroy multiple objects", function() {
162 Ext.destroy(o1, o2, o3);
164 expect(o1.destroy).toHaveBeenCalled();
165 expect(o2.destroy).toHaveBeenCalled();
166 expect(o3.dest).not.toHaveBeenCalled();
169 it("should remove dom if object is an Ext.element", function() {
170 var el = Ext.getBody().createChild({id: "to_destroy"});
174 expect(Ext.fly("to_destroy")).toBeNull();
178 describe("Ext.htmlEncode", function() {
179 var htmlEncode = Ext.String.htmlEncode,
182 it("should replace ampersands", function() {
183 str = "Fish & Chips";
185 expect(htmlEncode(str)).toEqual("Fish & Chips");
188 it("should replace less than", function() {
189 str = "Fish > Chips";
191 expect(htmlEncode(str)).toEqual("Fish > Chips");
194 it("should replace greater than", function() {
195 str = "Fish < Chips";
197 expect(htmlEncode(str)).toEqual("Fish < Chips");
200 it("should replace double quote", function() {
201 str = 'Fish " Chips';
203 expect(htmlEncode(str)).toEqual("Fish " Chips");
207 describe("Ext.htmlEncode", function() {
208 var htmlDecode = Ext.String.htmlDecode,
211 it("should replace ampersands", function() {
212 str = "Fish & Chips";
214 expect(htmlDecode(str)).toEqual("Fish & Chips");
217 it("should replace less than", function() {
218 str = "Fish > Chips";
220 expect(htmlDecode(str)).toEqual("Fish > Chips");
223 it("should replace greater than", function() {
224 str = "Fish < Chips";
226 expect(htmlDecode(str)).toEqual("Fish < Chips");
229 it("should replace double quote", function() {
230 str = 'Fish " Chips';
232 expect(htmlDecode(str)).toEqual('Fish " Chips');
236 describe("Ext.urlAppend", function() {
237 var url = "http://example.com/";
239 it("should manage question mark", function() {
240 expect(Ext.urlAppend(url, "test=1")).toEqual("http://example.com/?test=1");
243 it("should manage ampersand", function() {
244 expect(Ext.urlAppend(url + "?test=1","foo=2")).toEqual("http://example.com/?test=1&foo=2");
247 it("should return directly url if content is empty", function() {
248 expect(Ext.urlAppend(url)).toEqual(url);
252 describe("Ext.getDom", function() {
255 beforeEach(function() {
256 el1 = Ext.getBody().createChild({id: "elone"});
259 afterEach(function() {
263 it("should return a dom element if an Ext.element is passed as first argument", function() {
264 expect(Ext.getDom(el1)).toEqual(el1.dom);
267 it("should return a dom element if the string (id) passed as first argument", function() {
268 expect(Ext.getDom("elone")).toEqual(el1.dom);
272 describe("Ext.removeNode", function(){
273 describe("if passed element isn't body", function() {
275 beforeEach(function() {
276 el = Ext.getBody().createChild({
284 it("should remove a dom element from document", function(){
285 Ext.removeNode(el.dom);
286 expect(document.body.childNodes[0]).toBeUndefined();
289 it("should delete the cache reference", function() {
290 Ext.removeNode(el.dom);
291 expect(Ext.cache[id]).toBeUndefined();
293 if (!Ext.isIE6 && !Ext.isIE7) {
294 it("should remove all listeners from the dom element", function() {
295 var listener = jasmine.createSpy();
296 el.on('mouseup', listener);
297 Ext.removeNode(el.dom);
298 jasmine.fireMouseEvent(el.dom, 'mouseup');
299 expect(listener).not.toHaveBeenCalled();
305 describe("if passed element is body", function() {
306 it("should not delete the cache reference", function() {
307 Ext.removeNode(document.body);
308 expect(Ext.cache[Ext.getBody().id]).toBeDefined();
311 it("should not remove listeners from body", function() {
312 var listener = jasmine.createSpy();
313 Ext.getBody().on('mouseup', listener);
314 Ext.removeNode(document.body);
315 jasmine.fireMouseEvent(document.body, 'mouseup');
316 expect(listener).toHaveBeenCalled();
317 Ext.getBody().un('mouseup', listener);
321 if (!Ext.isIE6 && !Ext.isIE7) {
322 describe("if enableNestedListenerRemoval is true", function() {
325 beforeEach(function(){
326 Ext.enableNestedListenerRemoval = true;
327 el = Ext.getBody().createChild();
328 child = el.createChild();
331 afterEach(function(){
332 Ext.enableNestedListenerRemoval = false;
335 it("should 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).not.toHaveBeenCalled();
346 if (!Ext.isIE6 && !Ext.isIE7) {
347 describe("if enableNestedListenerRemoval is false (default)", function() {
350 beforeEach(function(){
351 el = Ext.getBody().createChild();
352 child = el.createChild();
355 it("should not remove listener on children", function() {
356 var listener = jasmine.createSpy();
357 child.on('mouseup', listener);
358 Ext.removeNode(el.dom);
359 jasmine.fireMouseEvent(child.dom, 'mouseup');
360 expect(listener).toHaveBeenCalled();
361 Ext.EventManager.purgeElement(child.dom);
367 describe("Ext.addBehaviors", function() {
368 var listener, span1, span2, div1;
370 beforeEach(function() {
371 span1 = Ext.getBody().createChild({
375 span2 = Ext.getBody().createChild({
379 div1 = Ext.getBody().createChild({
383 listener = jasmine.createSpy();
386 afterEach(function() {
392 it("should apply event listeners to elements by selectors", function() {
394 'span @mouseup': listener
397 jasmine.fireMouseEvent(span1.dom, 'mouseup');
398 jasmine.fireMouseEvent(span2.dom, 'mouseup');
399 jasmine.fireMouseEvent(div1.dom, 'mouseup');
401 expect(listener.calls.length).toEqual(2);
405 it("should manage multiple selectors", function() {
407 'span, div.foo @mouseup': listener
410 jasmine.fireMouseEvent(span1.dom, 'mouseup');
411 jasmine.fireMouseEvent(span2.dom, 'mouseup');
412 jasmine.fireMouseEvent(div1.dom, 'mouseup');
414 expect(listener.calls.length).toEqual(3);
419 describe("Ext.getScrollBarWidth", function() {
420 it("should return a number between 10 and 40 (we assume that document is loaded)", function() {
421 expect(Ext.getScrollBarWidth() > 10).toBe(true);
422 expect(Ext.getScrollBarWidth() < 40).toBe(true);
426 describe("Ext.copyTo", function(){
429 beforeEach(function() {
440 afterEach(function(){
445 describe("with an array of named properties", function() {
446 it("should copy a set of named properties fom the source object to the destination object.", function() {
447 Ext.copyTo(dest, src, ['a', 'b', 'e']);
449 expect(dest).toEqual({
456 describe("with a string list of named properties", function() {
457 it("should copy a set of named properties fom the source object to the destination object.", function() {
458 Ext.copyTo(dest, src, 'c,b,e');
459 expect(dest).toEqual({
467 describe("Ext.destroyMembers", function() {
468 var obj, destroyable;
470 beforeEach(function(){
472 destroy: jasmine.createSpy()
483 it("should remove named properties from a passed object", function() {
484 Ext.destroyMembers(obj, 'a', 'c', 'i');
485 expect(obj).toEqual({
492 it("should attempt to destroy passed properties", function() {
493 Ext.destroyMembers(obj, 'a', 'c', 'me');
495 expect(destroyable.destroy).toHaveBeenCalled();
499 describe("Ext.partition", function() {
500 describe("with an array of boolean", function() {
501 it("should partition the set into two sets: a true and a false set", function() {
502 expect(Ext.partition([true, true, false, false, true])).toEqual([[true,true,true], [false,false]]);
506 describe("with an array to partition and a function to determine truth", function() {
507 it("should partition the set into two sets: a true and a false set", function() {
514 expect(Ext.partition(array, function(item){
523 describe("with a NodeList to partition and a function to determine truth", function() {
524 it("should partition the set into two sets: a true and a false set", function() {
527 p[0] = Ext.getBody().createChild({
531 p[1] = Ext.getBody().createChild({
535 p[2] = Ext.getBody().createChild({
539 p[3] = Ext.getBody().createChild({
543 p[4] = Ext.getBody().createChild({
547 p[5] = Ext.getBody().createChild({
552 expect(Ext.partition(Ext.query("p"), function(val){
553 return val.className == "class1";
555 [p[0].dom, p[2].dom, p[5].dom],
556 [p[1].dom, p[3].dom, p[4].dom]
559 Ext.Array.each(p, function(el) {