]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/test/specs/tab/Tab.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / test / specs / tab / Tab.js
CommitLineData
6527f429
DM
1describe("Ext.tab.Tab", function() {\r
2 var tab, card;\r
3 \r
4 function createTab(config) {\r
5 if (tab) {\r
6 tab.destroy();\r
7 tab = null;\r
8 }\r
9 \r
10 tab = new Ext.tab.Tab(Ext.apply({}, config));\r
11 \r
12 return tab;\r
13 }\r
14 \r
15 beforeEach(function() {\r
16 card = {\r
17 title: 'Some title',\r
18 iconCls: 'some-iconCls'\r
19 };\r
20 });\r
21 \r
22 afterEach(function() {\r
23 Ext.destroy(tab, card);\r
24 tab = card = null;\r
25 });\r
26 \r
27 describe("if a card is specified", function() {\r
28 beforeEach(function() {\r
29 spyOn(Ext.tab.Tab.prototype, 'setCard').andCallThrough();\r
30 });\r
31 \r
32 it("should call setCard during initialization", function() {\r
33 createTab({\r
34 card: card\r
35 });\r
36 \r
37 expect(Ext.tab.Tab.prototype.setCard).toHaveBeenCalledWith(card);\r
38 });\r
39 });\r
40 \r
41 describe("setting a card", function() {\r
42 beforeEach(function() {\r
43 tab = createTab();\r
44 \r
45 spyOn(tab, 'setText').andReturn(true);\r
46 spyOn(tab, 'setIconCls').andReturn(true);\r
47 \r
48 tab.setCard(card);\r
49 });\r
50 \r
51 it("should set the title text", function() {\r
52 expect(tab.setText).toHaveBeenCalledWith(card.title);\r
53 });\r
54 \r
55 it("should set the icon class", function() {\r
56 expect(tab.setIconCls).toHaveBeenCalledWith(card.iconCls);\r
57 });\r
58 \r
59 describe("setting the title text", function() {\r
60 describe("if the tab has a specific title", function() {\r
61 beforeEach(function() {\r
62 tab = createTab({\r
63 title: 'Specific title'\r
64 });\r
65 \r
66 spyOn(tab, 'setText').andReturn(true);\r
67 });\r
68 \r
69 it("should retain that title", function() {\r
70 tab.setCard(card);\r
71 \r
72 expect(tab.setText).toHaveBeenCalledWith('Specific title');\r
73 });\r
74 });\r
75\r
76 describe("if the tab does not have a specific title", function() {\r
77 it("should use the title of the new card", function() {\r
78 tab.setCard(card);\r
79 \r
80 expect(tab.setText).toHaveBeenCalledWith(card.title);\r
81 });\r
82 });\r
83 });\r
84\r
85 describe("setting the icon class", function() {\r
86 describe("if the tab has a specific title", function() {\r
87 beforeEach(function() {\r
88 tab = createTab({\r
89 iconCls: 'specificCls'\r
90 });\r
91 \r
92 spyOn(tab, 'setIconCls').andReturn(true);\r
93 });\r
94 \r
95 it("should retain that title", function() {\r
96 tab.setCard(card);\r
97 \r
98 expect(tab.setIconCls).toHaveBeenCalledWith('specificCls');\r
99 });\r
100 });\r
101\r
102 describe("if the tab does not have a specific title", function() {\r
103 it("should use the title of the new card", function() {\r
104 tab.setCard(card);\r
105 \r
106 expect(tab.setIconCls).toHaveBeenCalledWith(card.iconCls);\r
107 });\r
108 });\r
109 });\r
110 });\r
111 \r
112 describe("activating", function() {\r
113 beforeEach(function() {\r
114 tab = createTab();\r
115 });\r
116 \r
117 it("should set active to true", function() {\r
118 tab.activate();\r
119 expect(tab.active).toBe(true);\r
120 });\r
121 \r
122 it("should fire the activate event with a reference to the tab", function() {\r
123 var args;\r
124 \r
125 tab.on('activate', function() {\r
126 args = arguments;\r
127 }, this);\r
128 \r
129 tab.activate();\r
130 \r
131 expect(args[0]).toEqual(tab);\r
132 });\r
133 });\r
134 \r
135 describe("deactivating", function() {\r
136 beforeEach(function() {\r
137 tab = createTab();\r
138 });\r
139 \r
140 it("should set active to false", function() {\r
141 tab.deactivate();\r
142 \r
143 expect(tab.active).toBe(false);\r
144 });\r
145 \r
146 xit("should remove the activeCls from the element", function() {\r
147 tab.deactivate();\r
148 \r
149 expect(tab.additionalCls).not.toContain(tab.activeCls);\r
150 });\r
151 \r
152 it("should fire the deactivate event with a reference to the tab", function() {\r
153 var args;\r
154 \r
155 tab.on('deactivate', function() {\r
156 args = arguments;\r
157 }, this);\r
158 \r
159 tab.deactivate();\r
160 \r
161 expect(args[0]).toEqual(tab);\r
162 });\r
163 });\r
164 \r
165 describe("setting closable", function() {\r
166 beforeEach(function() {\r
167 tab = createTab();\r
168 });\r
169 \r
170 it("should set closable to true", function() {\r
171 delete tab.closable;\r
172 \r
173 tab.setClosable(true);\r
174 \r
175 expect(tab.closable).toBe(true);\r
176 });\r
177 });\r
178 \r
179 describe("setting not closable", function() {\r
180 beforeEach(function() {\r
181 tab = createTab();\r
182 });\r
183 \r
184 it("should set closable to false", function() {\r
185 delete tab.closable;\r
186 \r
187 tab.setClosable(false);\r
188 \r
189 expect(tab.closable).toBe(false);\r
190 });\r
191 \r
192 xit("should remove the closable class from the tab", function() {\r
193 tab.setClosable(false);\r
194 \r
195 expect(tab.additionalCls).not.toContain(tab.closableCls);\r
196 });\r
197 });\r
198 \r
199 describe("when the close button is clicked", function() {\r
200 beforeEach(function() {\r
201 tab = createTab();\r
202 });\r
203 \r
204 it("should fire the beforeclose event", function() {\r
205 var called = false;\r
206 \r
207 tab.on('beforeclose', function() {\r
208 called = true;\r
209 }, this);\r
210 \r
211 tab.onCloseClick();\r
212 \r
213 expect(called).toBe(true);\r
214 });\r
215 \r
216 it("should fire a close event", function() {\r
217 var called = false;\r
218 \r
219 tab.on('close', function() {\r
220 called = true;\r
221 }, this);\r
222 \r
223 tab.onCloseClick();\r
224 \r
225 expect(called).toBe(true);\r
226 });\r
227 \r
228 describe("if a listener returned false to beforeclose", function() {\r
229 beforeEach(function() {\r
230 tab.on('beforeclose', function() {\r
231 return false;\r
232 }, this);\r
233 });\r
234 \r
235 it("should not fire a close event", function() {\r
236 var called = false;\r
237\r
238 tab.on('close', function() {\r
239 called = true;\r
240 }, this);\r
241\r
242 tab.onCloseClick();\r
243\r
244 expect(called).toBe(false);\r
245 });\r
246 });\r
247 \r
248 describe("if there is a configured tabBar", function() {\r
249 var tabBar;\r
250 \r
251 beforeEach(function() {\r
252 tabBar = {\r
253 closeTab: jasmine.createSpy()\r
254 };\r
255 \r
256 tab = createTab({\r
257 tabBar: tabBar\r
258 });\r
259 });\r
260 \r
261 it("should call the tabBar's closeTab function", function() {\r
262 tab.onCloseClick();\r
263 \r
264 expect(tabBar.closeTab).toHaveBeenCalledWith(tab);\r
265 });\r
266 });\r
267 });\r
268 \r
269 describe("keyboard interaction", function() {\r
270 var enterSpy, deleteSpy, closeSpy, clickSpy;\r
271 \r
272 beforeEach(function() {\r
273 createTab({\r
274 renderTo: undefined\r
275 });\r
276 \r
277 enterSpy = spyOn(tab, 'onEnterKey').andCallThrough();\r
278 deleteSpy = spyOn(tab, 'onDeleteKey').andCallThrough();\r
279 closeSpy = spyOn(tab, 'onCloseClick').andCallThrough();\r
280 clickSpy = jasmine.createSpy('onClick');\r
281 \r
282 tab.tabBar = {\r
283 onClick: clickSpy,\r
284 closeTab: Ext.emptyFn\r
285 };\r
286 \r
287 tab.render(Ext.getBody());\r
288 });\r
289 \r
290 afterEach(function() {\r
291 tab.tabBar = null;\r
292 enterSpy = deleteSpy = closeSpy = clickSpy = null;\r
293 });\r
294 \r
295 describe("Space key", function() {\r
296 beforeEach(function() {\r
297 jasmine.pressKey(tab.el, 'space');\r
298 \r
299 waitForSpy(enterSpy);\r
300 });\r
301 \r
302 it("should call tabBar.onClick", function() {\r
303 expect(clickSpy).toHaveBeenCalled();\r
304 });\r
305 \r
306 it("should stop the keydown event", function() {\r
307 var args = enterSpy.mostRecentCall.args;\r
308 \r
309 expect(args[0].isStopped).toBe(true);\r
310 });\r
311 \r
312 it("should return false to stop Event propagation loop", function() {\r
313 expect(enterSpy.mostRecentCall.result).toBe(false);\r
314 });\r
315 });\r
316 \r
317 describe("Enter key", function() {\r
318 beforeEach(function() {\r
319 jasmine.pressKey(tab.el, 'enter');\r
320 \r
321 waitForSpy(enterSpy);\r
322 });\r
323 \r
324 it("should call tabBar.onClick", function() {\r
325 expect(clickSpy).toHaveBeenCalled();\r
326 });\r
327 \r
328 it("should stop the keydown event", function() {\r
329 var args = enterSpy.mostRecentCall.args;\r
330 \r
331 expect(args[0].isStopped).toBe(true);\r
332 });\r
333 \r
334 it("should return false to stop Event propagation loop", function() {\r
335 expect(enterSpy.mostRecentCall.result).toBe(false);\r
336 });\r
337 });\r
338 \r
339 describe("Delete key", function() {\r
340 beforeEach(function() {\r
341 jasmine.pressKey(tab.el, 'delete');\r
342 \r
343 waitForSpy(deleteSpy);\r
344 });\r
345 \r
346 it("should call onCloseClick", function() {\r
347 expect(closeSpy).toHaveBeenCalled();\r
348 });\r
349 \r
350 it("should stop the keydown event", function() {\r
351 var args = deleteSpy.mostRecentCall.args;\r
352 \r
353 expect(args[0].isStopped).toBe(true);\r
354 });\r
355 \r
356 it("should return false to stop Event propagation loop", function() {\r
357 expect(deleteSpy.mostRecentCall.result).toBe(false);\r
358 });\r
359 });\r
360 });\r
361});\r