- describe("Ext.destroy", function() {
- var o1, o2, o3;
-
- beforeEach(function() {
- o1 = jasmine.createSpyObj("o1", ["destroy"]);
-
- o2 = jasmine.createSpyObj("o2", ["destroy"]);
-
- o3 = jasmine.createSpyObj("o3", ["dest"]);
-
- });
-
- it("should destroy an object", function() {
- Ext.destroy(o1);
-
- expect(o1.destroy).toHaveBeenCalled();
- });
-
- it("should no destroy an object without a destroy method", function() {
- Ext.destroy(o3);
-
- expect(o3.dest).not.toHaveBeenCalled();
- });
-
- it("should destroy an array of objects", function() {
- Ext.destroy([o1, o2, o3]);
-
- expect(o1.destroy).toHaveBeenCalled();
- expect(o2.destroy).toHaveBeenCalled();
- expect(o3.dest).not.toHaveBeenCalled();
- });
-
- it("should destroy multiple objects", function() {
- Ext.destroy(o1, o2, o3);
-
- expect(o1.destroy).toHaveBeenCalled();
- expect(o2.destroy).toHaveBeenCalled();
- expect(o3.dest).not.toHaveBeenCalled();
- });
-
- it("should remove dom if object is an Ext.element", function() {
- var el = Ext.getBody().createChild({id: "to_destroy"});
-
- Ext.destroy(el);
-
- expect(Ext.fly("to_destroy")).toBeNull();
- });
- });
-
- describe("Ext.each", function() {
- var itFn;
-
- beforeEach(function() {
- itFn = jasmine.createSpy("on itFn");
- });
-
- describe("each object", function() {
- var o;
-
- beforeEach(function() {
- o = {
- n1: 11,
- n2: 13,
- n3: 18
- };
- });
-
- describe("if itFn does not return false", function() {
- beforeEach(function() {
- Ext.each(o, itFn);
- });
-
- it("should call the each function 3 times", function () {
- expect(itFn.callCount).toEqual(3);
- });
-
- it("should call the each function with correct arguments", function () {
- expect(itFn.calls[0].args).toEqual(["n1", 11, o]);
- expect(itFn.calls[1].args).toEqual(["n2", 13, o]);
- expect(itFn.calls[2].args).toEqual(["n3", 18, o]);
- });
- });
-
- describe("if itFn return false", function() {
- beforeEach(function() {
- itFn.andReturn(false);
- Ext.each(o, itFn);
- });
-
- it("should stop iteration if function return false", function() {
- itFn.andReturn(false);
-
- expect(itFn.calls.length).toEqual(1);
- });
- });
- });
-
- describe("do nothing on an empty object", function() {
- var o;
-
- beforeEach(function() {
- o = {};
- Ext.each(o, itFn);
- });
-
- it("should not call the each function", function () {
- expect(itFn).not.toHaveBeenCalled();
- });
-
- });
-
- describe("each array", function() {
- var arr;
-
- beforeEach(function() {
- arr = [6, 7, 8, 9];
- });
-
- describe("if itFn does not return false", function() {
- beforeEach(function() {
- Ext.each(arr, itFn);
- });
-
- it("should call the each function 4 times", function () {
- expect(itFn.callCount).toEqual(4);
- });
-
- it("should call the each function with correct arguments", function () {
- expect(itFn.calls[0].args).toEqual([6, 0, arr]);
- expect(itFn.calls[1].args).toEqual([7, 1, arr]);
- expect(itFn.calls[2].args).toEqual([8, 2, arr]);
- expect(itFn.calls[3].args).toEqual([9, 3, arr]);
- });
- });
-
- describe("if itFn return false", function() {
- beforeEach(function() {
- itFn.andReturn(false);
- Ext.each(arr, itFn);
- });
-
- it("should stop iteration if function return false", function() {
- itFn.andReturn(false);
-
- expect(itFn.calls.length).toEqual(1);
- });
- });
- });
-
- describe("do nothing on an empty array", function() {
- var arr;
-
- beforeEach(function() {
- arr = [];
- Ext.each(arr, itFn);
- });
-
- it("should not call the each function", function () {
- expect(itFn).not.toHaveBeenCalled();
- });
-
- });
-
- describe("simple cases", function() {
- it("should work with an array of numbers", function() {
- var sum = 0;
-
- Ext.each([1, 2, 3, 4], function(val){
- sum += val;
- });
-
- expect(sum).toEqual(10);
- });
-
- it("should work with an array of strings", function() {
- var str = '';
-
- Ext.each(["S", "e", "n", "c", "h", "a"], function(s){
- str += s;
- });
-
- expect(str).toEqual("Sencha");
- });
-
- it("should pass index correctly", function() {
- var arr = [];
- Ext.each([1, 2, 3, 4, 5, 6], function(val, idx){
- arr.push(idx);
- });
- expect(arr).toEqual([0, 1, 2, 3, 4, 5]);
- });
-
- it("should work with a non array parameter", function() {
- var sum = 0;
-
- Ext.each(5, function(num){
- sum += num;
- });
-
- expect(sum).toEqual(5);
- });
- });
-
- describe("more complex cases that need a spy", function() {
- var eachFn;
-
- beforeEach(function() {
- eachFn = jasmine.createSpy();
- });
-
- it("should not run eachFn with an empty array", function() {
- Ext.each([], eachFn);
-
- expect(eachFn).not.toHaveBeenCalled();
- });
-
- it("should not run eachFn with null as first param", function() {
- Ext.each(null, eachFn);
-
- expect(eachFn).not.toHaveBeenCalled();
- });
-
- it("should iterate over NodeLists", function() {
- Ext.each(document.getElementsByTagName('body'), eachFn);
-
- expect(eachFn).toHaveBeenCalled();
- });
-
- it("should stop when function called with each item return false", function() {
- eachFn.andCallFake(function(v) {
- if (v === 5) {
- return false;
- }
- });
-
- Ext.each([1, 2, 3, 4, 5, 6], eachFn);
-
- expect(eachFn.callCount).toEqual(5);
- });
-
- it("should runfunction called with each item with correct scope", function() {
-
- Ext.each([1, 2], eachFn, fakeScope);
-
- expect(eachFn.calls[0].object).toBe(fakeScope);
- expect(eachFn.calls[1].object).toBe(fakeScope);
- });
- });
-
-
- });
-
- describe("Ext.iterate", function() {
- var itFn;
-
- beforeEach(function() {
- itFn = jasmine.createSpy();
- });
-
- describe("iterate object", function() {
- var o;
-
- beforeEach(function() {
- o = {
- n1: 11,
- n2: 13,
- n3: 18
- };
- });
-
- describe("if itFn does not return false", function() {
- beforeEach(function() {
- Ext.iterate(o, itFn);
- });
-
- it("should call the iterate function 3 times", function () {
- expect(itFn.callCount).toEqual(3);
- });
-
- it("should call the iterate function with correct arguments", function () {
- expect(itFn.calls[0].args).toEqual(["n1", 11, o]);
- expect(itFn.calls[1].args).toEqual(["n2", 13, o]);
- expect(itFn.calls[2].args).toEqual(["n3", 18, o]);
- });
- });