]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/app/domain/Controller.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / app / domain / Controller.js
CommitLineData
6527f429
DM
1describe("Ext.app.domain.Controller", function() {\r
2 var ctrlFoo, ctrlBar, ctrlTest, handlerFoo, handlerBar;\r
3 \r
4 beforeEach(function() {\r
5 Ext.define('spec.AliasController', {\r
6 extend: 'Ext.app.Controller',\r
7 alias: 'controller.test',\r
8 'namespace': 'spec'\r
9 });\r
10 \r
11 ctrlFoo = new Ext.app.Controller({ id: 'foo' });\r
12 ctrlBar = new Ext.app.Controller({ id: 'bar' });\r
13 ctrlTest = new spec.AliasController();\r
14 \r
15 handlerFoo = jasmine.createSpy('event handler foo');\r
16 handlerBar = jasmine.createSpy('event handler bar');\r
17 });\r
18 \r
19 afterEach(function() {\r
20 Ext.undefine('spec.AliasController');\r
21 ctrlTest = ctrlFoo = ctrlBar = handlerFoo = handlerBar = null;\r
22 });\r
23\r
24 it("should ignore case on event names", function() {\r
25 ctrlFoo.listen({\r
26 controller: {\r
27 '#bar': {\r
28 foo: handlerFoo\r
29 }\r
30 }\r
31 });\r
32 \r
33 ctrlBar.fireEvent('FOO');\r
34 \r
35 expect(handlerFoo).toHaveBeenCalled();\r
36 });\r
37 \r
38 describe("id selector", function() {\r
39 it("listens to other Controllers' events by #id", function() {\r
40 ctrlFoo.listen({\r
41 controller: {\r
42 '#bar': {\r
43 foo: handlerFoo\r
44 }\r
45 }\r
46 });\r
47 \r
48 ctrlBar.fireEvent('foo');\r
49 \r
50 expect(handlerFoo).toHaveBeenCalled();\r
51 });\r
52 \r
53 it("doesn't listen to other Controllers' events when selector doesn't match", function() {\r
54 ctrlFoo.listen({\r
55 controller: {\r
56 '#foo': {\r
57 bar: handlerFoo\r
58 },\r
59 '#bar': {\r
60 bar: handlerBar\r
61 }\r
62 }\r
63 });\r
64 \r
65 ctrlFoo.fireEvent('bar');\r
66 \r
67 expect(handlerFoo).toHaveBeenCalled();\r
68 // AND\r
69 expect(handlerBar).not.toHaveBeenCalled();\r
70 });\r
71 });\r
72 \r
73 describe("alias selector", function() {\r
74 it("should match based on alias", function() {\r
75 ctrlFoo.listen({\r
76 controller: {\r
77 'test': {\r
78 custom: handlerFoo\r
79 }\r
80 }\r
81 });\r
82 ctrlTest.fireEvent('custom');\r
83 expect(handlerFoo).toHaveBeenCalled(); \r
84 }); \r
85 \r
86 it("should not listen when the alias does not match", function() {\r
87 ctrlFoo.listen({\r
88 controller: {\r
89 'other': {\r
90 custom: handlerFoo\r
91 }\r
92 }\r
93 });\r
94 ctrlTest.fireEvent('custom');\r
95 expect(handlerFoo).not.toHaveBeenCalled(); \r
96 });\r
97 });\r
98 \r
99 describe("# selector", function() {\r
100 var app;\r
101 beforeEach(function() {\r
102 app = new Ext.app.Application({\r
103 name: 'ControllerDomainSpec'\r
104 });\r
105 });\r
106 \r
107 afterEach(function() {\r
108 app.destroy();\r
109 app = null;\r
110 try {\r
111 delete window.ControllerDomainSpec;\r
112 } catch (e) {\r
113 window.ControllerDomainSpec = undefined;\r
114 }\r
115 });\r
116 \r
117 it("should match an application", function() {\r
118 ctrlFoo.listen({\r
119 controller: {\r
120 '#': {\r
121 custom: handlerFoo\r
122 }\r
123 }\r
124 });\r
125 app.fireEvent('custom');\r
126 expect(handlerFoo).toHaveBeenCalled();\r
127 });\r
128 \r
129 it("should not match a controller", function() {\r
130 ctrlFoo.listen({\r
131 controller: {\r
132 '#': {\r
133 custom: handlerFoo\r
134 }\r
135 }\r
136 });\r
137 ctrlBar.fireEvent('custom');\r
138 expect(handlerFoo).not.toHaveBeenCalled();\r
139 });\r
140 });\r
141 \r
142 describe("* selector", function() {\r
143 it("listens to other Controllers' events when selector is '*'", function() {\r
144 ctrlFoo.listen({\r
145 controller: {\r
146 '*': {\r
147 baz: handlerFoo\r
148 }\r
149 }\r
150 });\r
151 \r
152 ctrlBar.fireEvent('baz');\r
153 \r
154 expect(handlerFoo).toHaveBeenCalled();\r
155 });\r
156 \r
157 it("listens to its own events when selector is '*'", function() {\r
158 ctrlFoo.listen({\r
159 controller: {\r
160 '*': {\r
161 qux: handlerFoo\r
162 }\r
163 }\r
164 });\r
165 \r
166 ctrlFoo.fireEvent('qux');\r
167 \r
168 expect(handlerFoo).toHaveBeenCalled();\r
169 });\r
170 \r
171 it("passes event arguments correctly", function() {\r
172 ctrlFoo.listen({\r
173 controller: {\r
174 '*': {\r
175 fred: handlerFoo\r
176 }\r
177 }\r
178 });\r
179 \r
180 ctrlBar.fireEvent('fred', 'foo', ['bar', 'baz']);\r
181 \r
182 expect(handlerFoo).toHaveBeenCalledWith('foo', ['bar', 'baz']);\r
183 });\r
184 });\r
185});\r