]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/core/test/specs/AbstractManager.js
1 describe("AbstractManager", function(){
6 manager
= new Ext
.AbstractManager();
13 describe("get/register/unregister", function(){
14 it("should return undefined for an item not in the collection", function(){
15 expect(manager
.get('notthere')).toBeUndefined();
18 it("should return the object if it exists in the collection", function(){
21 expect(manager
.get('item')).toBe(o
);
24 it("should register multiple items", function(){
25 var o1
= {id
: 'item1'},
31 expect(manager
.get('item1')).toBe(o1
);
32 expect(manager
.get('item2')).toBe(o2
);
35 it("should remove items when unregistered", function(){
36 var o1
= {id
: 'item1'},
42 manager
.unregister(o2
);
43 expect(manager
.get('item1')).toBe(o1
);
44 expect(manager
.get('item2')).toBeUndefined();
48 describe("registerType/isRegistered/create", function(){
51 delete Ext
.util
.Filter
.type
;
54 it("should copy the type name onto the prototype", function(){
55 manager
.registerType('filter', Ext
.util
.Filter
);
56 expect(Ext
.util
.Filter
.type
).toEqual('filter');
59 it("should return true when a type is registered", function(){
60 manager
.registerType('filter', Ext
.util
.Filter
);
61 expect(manager
.isRegistered('filter')).toBe(true);
64 it("should return false when a type is not registered", function(){
65 expect(manager
.isRegistered('notRegged')).toBe(false);
68 it("should thrown an exception when trying to create a type that doesn't exist", function(){
70 manager
.create('filter');
74 it("should return an instance of the type", function(){
75 manager
.registerType('filter', Ext
.util
.Filter
);
76 expect(manager
.create({
79 }) instanceof Ext
.util
.Filter
).toBe(true);
82 it("should fallback to the default type", function(){
83 manager
.registerType('filter', Ext
.util
.Filter
);
84 expect(manager
.create({
86 }, 'filter') instanceof Ext
.util
.Filter
).toBe(true);
89 it("should pass the config to the constructor", function(){
90 manager
.registerType('filter', Ext
.util
.Filter
);
91 var filter
= manager
.create({
97 expect(filter
.getProperty()).toBe('name');
101 describe("onAvailable", function(){
102 it("should never fire if no items are added", function(){
103 var spy
= jasmine
.createSpy('spy');
104 manager
.onAvailable('item', spy
);
105 expect(spy
.callCount
).toBe(0);
108 it("should never fire if items with no matching id are added", function(){
109 var spy
= jasmine
.createSpy('spy');
110 manager
.onAvailable('item', spy
);
114 expect(spy
.callCount
).toBe(0);
117 it("should fire the function if an item is added with a matching id", function(){
118 var spy
= jasmine
.createSpy('spy');
119 manager
.onAvailable('item', spy
);
123 expect(spy
.callCount
).toBe(1);
126 it("should fire the function if the onAvailable is bound when the item already exists", function(){
127 var spy
= jasmine
.createSpy('spy');
131 manager
.onAvailable('item', spy
);
132 expect(spy
.callCount
).toBe(1);
135 it("should pass the item as a parameter", function(){
136 var o
= {id
: 'item'},
142 manager
.onAvailable('item', fn
);
144 expect(actual
).toBe(o
);
147 it("should default the scope to the item if not specified", function(){
148 var o
= {id
: 'item'},
154 manager
.onAvailable('item', fn
);
156 expect(actual
).toBe(o
);
159 it("should use the passed scope", function(){
160 var o
= {id
: 'item'},
167 manager
.onAvailable('item', fn
, scope
);
169 expect(actual
).toBe(scope
);
172 it("should remove the listener once the component is created", function(){
173 var fn1 = function(){
183 manager
.onAvailable('item', fn1
);
185 manager
.unregister(o
);
186 manager
.onAvailable('item', fn2
);
189 expect(first
).toBe(1);
190 expect(second
).toBe(1);
194 describe("each", function(){
195 it("should not iterate if there are no items", function(){
196 var spy
= jasmine
.createSpy('spy');
198 expect(spy
.callCount
).toBe(0);
201 it("should loop over each item", function(){
202 var spy
= jasmine
.createSpy('spy'),
211 expect(spy
.callCount
).toBe(5);
214 it("should default the scope to the manager", function(){
215 var o
= {id
: 'item'},
223 expect(scope
).toBe(manager
);
226 it("should use the passed scope", function(){
227 var o
= {id
: 'item'},
235 manager
.each(fn
, scope
);
236 expect(actual
).toBe(scope
);
241 describe("getCount", function(){
242 it("should return 0 by default", function(){
243 expect(manager
.getCount()).toBe(0);
246 it("should return the correct count after adding items", function(){
250 expect(manager
.getCount()).toBe(1);
255 expect(manager
.getCount()).toBe(2);
258 it("should return the correct count after removing items", function(){
259 var o
= {id
: 'item'};
261 manager
.unregister(o
);
262 expect(manager
.getCount()).toBe(0);