]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.tip.ToolTip", function() {\r |
2 | \r | |
3 | var tip,\r | |
4 | target;\r | |
5 | \r | |
6 | function createTip(config) {\r | |
7 | config = Ext.apply({}, config, {target: target, width: 50, height: 50, html: 'X'});\r | |
8 | tip = new Ext.tip.ToolTip(config);\r | |
9 | return tip;\r | |
10 | }\r | |
11 | \r | |
12 | beforeEach(function() {\r | |
13 | // force scroll to top, to avoid issues with positions getting calculted incorrectly as the scroll jumps around\r | |
14 | // window.scrollTo(0, 0);\r | |
15 | \r | |
16 | target = Ext.getBody().insertHtml(\r | |
17 | 'beforeEnd',\r | |
18 | '<a href="#" id="tipTarget" style="position:absolute; left:100px; top:100px; width: 50px; height: 50px;">x</a>',\r | |
19 | true\r | |
20 | );\r | |
21 | \r | |
22 | });\r | |
23 | \r | |
24 | afterEach(function() {\r | |
25 | if (tip) {\r | |
26 | tip.destroy();\r | |
27 | tip = null;\r | |
28 | }\r | |
29 | target.destroy();\r | |
30 | });\r | |
31 | \r | |
32 | function mouseOverTarget() {\r | |
33 | jasmine.fireMouseEvent(target, 'mouseover', target.getX(), target.getY());\r | |
34 | }\r | |
35 | \r | |
36 | describe("basic", function() {\r | |
37 | it("should extend Ext.tip.Tip", function() {\r | |
38 | expect(createTip() instanceof Ext.tip.Tip).toBeTruthy();\r | |
39 | });\r | |
40 | \r | |
41 | it("should accept an id for the 'target' config", function() {\r | |
42 | createTip({target: 'tipTarget'});\r | |
43 | expect(tip.target.dom).toBe(target.dom);\r | |
44 | });\r | |
45 | \r | |
46 | it("should accept an Ext.Element for the 'target' config", function() {\r | |
47 | createTip({target: target});\r | |
48 | expect(tip.target.dom).toBe(target.dom);\r | |
49 | });\r | |
50 | \r | |
51 | it("should accept an HTMLElement for the 'target' config", function() {\r | |
52 | createTip({target: target.dom});\r | |
53 | expect(tip.target.dom).toBe(target.dom);\r | |
54 | });\r | |
55 | });\r | |
56 | \r | |
57 | describe("disable", function() {\r | |
58 | it("should not show when not using a delay", function() {\r | |
59 | createTip({\r | |
60 | target: 'tipTarget',\r | |
61 | showDelay: 0\r | |
62 | });\r | |
63 | tip.disable();\r | |
64 | mouseOverTarget();\r | |
65 | expect(tip.isVisible()).toBe(false);\r | |
66 | });\r | |
67 | \r | |
68 | it("should not show when disabled during a delay and not rendered", function() {\r | |
69 | createTip({\r | |
70 | target: 'tipTarget',\r | |
71 | showDelay: 1000\r | |
72 | });\r | |
73 | mouseOverTarget();\r | |
74 | tip.disable();\r | |
75 | var spy = jasmine.createSpy();\r | |
76 | tip.on('show', spy);\r | |
77 | waits(1500);\r | |
78 | runs(function() {\r | |
79 | expect(spy).not.toHaveBeenCalled();\r | |
80 | });\r | |
81 | });\r | |
82 | \r | |
83 | it("should not show when disabled during a delay and already rendered", function() {\r | |
84 | createTip({\r | |
85 | target: 'tipTarget',\r | |
86 | showDelay: 1000,\r | |
87 | renderTo: Ext.getBody()\r | |
88 | });\r | |
89 | tip.hide();\r | |
90 | mouseOverTarget();\r | |
91 | tip.disable();\r | |
92 | var spy = jasmine.createSpy();\r | |
93 | tip.on('show', spy);\r | |
94 | waits(1500);\r | |
95 | runs(function() {\r | |
96 | expect(spy).not.toHaveBeenCalled();\r | |
97 | });\r | |
98 | });\r | |
99 | });\r | |
100 | \r | |
101 | describe("show/hide", function() {\r | |
102 | it("should show the tooltip after mousing over the target element", function() {\r | |
103 | runs(function() {\r | |
104 | createTip({showDelay: 1});\r | |
105 | var delaySpy = spyOn(tip, 'delayShow').andCallThrough();\r | |
106 | expect(tip.isVisible()).toBeFalsy();\r | |
107 | mouseOverTarget();\r | |
108 | expect(delaySpy).toHaveBeenCalled();\r | |
109 | });\r | |
110 | waitsFor(function() {\r | |
111 | return tip.isVisible();\r | |
112 | }, "ToolTip was never shown");\r | |
113 | });\r | |
114 | \r | |
115 | it("should hide the tooltip after mousing out of the target element", function() {\r | |
116 | runs(function() {\r | |
117 | createTip({showDelay: 1, hideDelay: 15});\r | |
118 | mouseOverTarget();\r | |
119 | });\r | |
120 | waitsFor(function() {\r | |
121 | return tip.isVisible();\r | |
122 | }, "ToolTip was never shown");\r | |
123 | runs(function() {\r | |
124 | jasmine.fireMouseEvent(target, 'mouseout', target.getX(), target.getY());\r | |
125 | });\r | |
126 | waitsFor(function() {\r | |
127 | return !tip.isVisible();\r | |
128 | }, "ToolTip was never hidden");\r | |
129 | });\r | |
130 | \r | |
131 | it("should hide the tooltip after a delay", function() {\r | |
132 | runs(function() {\r | |
133 | createTip({showDelay: 1, dismissDelay: 15});\r | |
134 | mouseOverTarget();\r | |
135 | });\r | |
136 | waitsFor(function() {\r | |
137 | return tip.isVisible();\r | |
138 | }, "ToolTip was never shown");\r | |
139 | waitsFor(function() {\r | |
140 | return !tip.isVisible();\r | |
141 | }, "ToolTip was never hidden");\r | |
142 | });\r | |
143 | \r | |
144 | it("should prevent the tooltip from automatically hiding if autoHide is false", function() {\r | |
145 | runs(function() {\r | |
146 | createTip({showDelay: 1, autoHide: false});\r | |
147 | this.spy = spyOn(tip, 'hide');\r | |
148 | mouseOverTarget();\r | |
149 | });\r | |
150 | waitsFor(function() {\r | |
151 | return tip.isVisible();\r | |
152 | }, "ToolTip was never shown");\r | |
153 | waits(100);\r | |
154 | runs(function() {\r | |
155 | expect(this.spy).not.toHaveBeenCalled();\r | |
156 | });\r | |
157 | });\r | |
158 | \r | |
159 | it("should allow clicking outside the tip to close it if autoHide is false", function() {\r | |
160 | runs(function() {\r | |
161 | createTip({showDelay: 1, autoHide: false});\r | |
162 | mouseOverTarget();\r | |
163 | });\r | |
164 | waitsFor(function() {\r | |
165 | return tip.isVisible();\r | |
166 | }, "ToolTip was never shown");\r | |
167 | runs(function() {\r | |
168 | this.spy = spyOn(tip, 'hide').andCallThrough();\r | |
169 | jasmine.fireMouseEvent(Ext.getBody(), 'mousedown', 0, 0);\r | |
170 | expect(this.spy).toHaveBeenCalled();\r | |
171 | });\r | |
172 | });\r | |
173 | });\r | |
174 | \r | |
175 | describe("mouseOffset", function() {\r | |
176 | it("should display the tooltip [15,18] from the mouse pointer by default", function() {\r | |
177 | runs(function() {\r | |
178 | createTip({showDelay: 1});\r | |
179 | mouseOverTarget();\r | |
180 | });\r | |
181 | waitsFor(function() {\r | |
182 | return tip.isVisible();\r | |
183 | }, "ToolTip was never shown");\r | |
184 | runs(function() {\r | |
185 | expect(tip.el).toBePositionedAt(target.getX() + 15, target.getY() + 18);\r | |
186 | });\r | |
187 | });\r | |
188 | \r | |
189 | it("should allow configuring the mouseOffset", function() {\r | |
190 | runs(function() {\r | |
191 | createTip({showDelay: 1, mouseOffset: [20, 30]});\r | |
192 | mouseOverTarget();\r | |
193 | });\r | |
194 | waitsFor(function() {\r | |
195 | return tip.isVisible();\r | |
196 | }, "ToolTip was never shown");\r | |
197 | runs(function() {\r | |
198 | expect(tip.el).toBePositionedAt(target.getX() + 35, target.getY() + 48);\r | |
199 | });\r | |
200 | });\r | |
201 | });\r | |
202 | \r | |
203 | describe("showAt", function(){\r | |
204 | it("should at the specified position", function(){\r | |
205 | createTip();\r | |
206 | tip.showAt([100, 100]);\r | |
207 | expect(tip.el).toBePositionedAt(100, 100); \r | |
208 | }); \r | |
209 | });\r | |
210 | \r | |
211 | describe("trackMouse", function() {\r | |
212 | it("should move the tooltip along with the mouse if 'trackMouse' is true", function() {\r | |
213 | var x = target.getX(),\r | |
214 | y = target.getY();\r | |
215 | runs(function() {\r | |
216 | createTip({showDelay: 1, trackMouse: true});\r | |
217 | jasmine.fireMouseEvent(target, 'mouseover', x, y);\r | |
218 | });\r | |
219 | waitsFor(function() {\r | |
220 | return tip.isVisible();\r | |
221 | }, "ToolTip was never shown");\r | |
222 | runs(function() {\r | |
223 | expect(tip.el).toBePositionedAt(x + 15, y + 18);\r | |
224 | for(var i = 0; i < 5; i++) {\r | |
225 | jasmine.fireMouseEvent(target, 'mousemove', ++x, ++y);\r | |
226 | expect(tip.el).toBePositionedAt(x + 15, y + 18);\r | |
227 | }\r | |
228 | });\r | |
229 | });\r | |
230 | \r | |
231 | describe('caching coords', function () {\r | |
232 | // See EXTJSIV-11292.\r | |
233 | // NOTE: The first time that the target is moused over the tooltip's layer (it's el)\r | |
234 | // won't have been created yet, so it's necessary to mouseover twice to test the API.\r | |
235 | //\r | |
236 | // When trackMouse = false, the XY coords will be cached by Tooltip.delayShow() and passed along\r | |
237 | // as an argument to Tooltip.show(). This is why we're checking the arguments passed to it.\r | |
238 | var x, y, n = 0;\r | |
239 | \r | |
240 | beforeEach(function () {\r | |
241 | x = target.getX();\r | |
242 | y = target.getY();\r | |
243 | \r | |
244 | runs(function() {\r | |
245 | // Since there are only two tests in this suite let's use the variable n to flip trackMouse.\r | |
246 | createTip({showDelay: 1, trackMouse: n ? true : false});\r | |
247 | spyOn(tip, 'show').andCallThrough();\r | |
248 | jasmine.fireMouseEvent(target, 'mouseover', x, y);\r | |
249 | n++;\r | |
250 | });\r | |
251 | \r | |
252 | waitsFor(function() {\r | |
253 | return tip.isVisible();\r | |
254 | }, 'ToolTip was never shown');\r | |
255 | });\r | |
256 | \r | |
257 | it('should cache xy coords when trackMouse=false', function () {\r | |
258 | runs(function () {\r | |
259 | expect(tip.show.mostRecentCall.args[0]).toBe(undefined);\r | |
260 | });\r | |
261 | \r | |
262 | waits(10);\r | |
263 | \r | |
264 | runs(function () {\r | |
265 | jasmine.fireMouseEvent(target, 'mouseover', x, y);\r | |
266 | expect(tip.show.mostRecentCall.args[0]).toEqual([115, 118]);\r | |
267 | });\r | |
268 | });\r | |
269 | \r | |
270 | it('should not cache xy coords when trackMouse=true', function () {\r | |
271 | runs(function () {\r | |
272 | expect(tip.show.mostRecentCall.args[0]).toBeFalsy();\r | |
273 | });\r | |
274 | \r | |
275 | waits(10);\r | |
276 | \r | |
277 | runs(function () {\r | |
278 | jasmine.fireMouseEvent(target, 'mouseover', x, y);\r | |
279 | expect(tip.show.mostRecentCall.args[0]).toBeFalsy();\r | |
280 | });\r | |
281 | });\r | |
282 | });\r | |
283 | });\r | |
284 | \r | |
285 | describe("anchor", function() {\r | |
286 | it("should allow anchoring the top of the tooltip to the target", function() {\r | |
287 | createTip({anchor: 'top'});\r | |
288 | tip.show();\r | |
289 | var tgtXY = target.getXY();\r | |
290 | expect(tip.el).toBePositionedAt(tgtXY[0], tgtXY[1] + target.getHeight() + 9);\r | |
291 | });\r | |
292 | \r | |
293 | it("should allow anchoring the right of the tooltip to the target", function() {\r | |
294 | createTip({anchor: 'right'});\r | |
295 | tip.show();\r | |
296 | var tgtXY = target.getXY();\r | |
297 | expect(tip.el).toBePositionedAt(tgtXY[0] - tip.el.getWidth() - 13, tgtXY[1]);\r | |
298 | });\r | |
299 | \r | |
300 | it("should allow anchoring the bottom of the tooltip to the target", function() {\r | |
301 | createTip({anchor: 'bottom'});\r | |
302 | tip.show();\r | |
303 | var tgtXY = target.getXY();\r | |
304 | expect(tip.el).toBePositionedAt(tgtXY[0], tgtXY[1] - tip.el.getHeight() - 13);\r | |
305 | });\r | |
306 | \r | |
307 | it("should allow anchoring the left of the tooltip to the target", function() {\r | |
308 | createTip({anchor: 'left'});\r | |
309 | tip.show();\r | |
310 | var tgtXY = target.getXY();\r | |
311 | expect(tip.el).toBePositionedAt(tgtXY[0] + target.getWidth() + 9, tgtXY[1]);\r | |
312 | });\r | |
313 | \r | |
314 | it("should flip from top to bottom if not enough space below the target", function() {\r | |
315 | target.setY(Ext.Element.getViewportHeight() - 75);\r | |
316 | createTip({anchor: 'top', constrainPosition: true});\r | |
317 | tip.show();\r | |
318 | var tgtXY = target.getXY();\r | |
319 | expect(tip.el).toBePositionedAt(tgtXY[0], tgtXY[1] - tip.el.getHeight() - 13);\r | |
320 | });\r | |
321 | \r | |
322 | it("should flip from bottom to top if not enough space above the target", function() {\r | |
323 | target.setY(25);\r | |
324 | createTip({anchor: 'bottom', constrainPosition: true});\r | |
325 | tip.show();\r | |
326 | var tgtXY = target.getXY();\r | |
327 | expect(tip.el).toBePositionedAt(tgtXY[0], tgtXY[1] + target.getHeight() + 9);\r | |
328 | });\r | |
329 | \r | |
330 | it("should flip from right to left if not enough space to the left of the target", function() {\r | |
331 | target.setX(25);\r | |
332 | createTip({anchor: 'right', constrainPosition: true});\r | |
333 | tip.show();\r | |
334 | var tgtXY = target.getXY();\r | |
335 | expect(tip.el).toBePositionedAt(tgtXY[0] + target.getWidth() + 9, tgtXY[1]);\r | |
336 | });\r | |
337 | \r | |
338 | it("should flip from left to right if not enough space to the right of the target", function() {\r | |
339 | target.setX(Ext.Element.getViewportWidth() - 75);\r | |
340 | createTip({anchor: 'left', constrainPosition: true});\r | |
341 | tip.show();\r | |
342 | var tgtXY = target.getXY();\r | |
343 | expect(tip.el).toBePositionedAt(tgtXY[0] - tip.el.getWidth() - 13, tgtXY[1]);\r | |
344 | });\r | |
345 | });\r | |
346 | \r | |
347 | describe("anchorToTarget=false", function() {\r | |
348 | it("should allow anchoring the top of the tooltip to the mouse pointer", function() {\r | |
349 | var xy = target.getXY();\r | |
350 | runs(function() {\r | |
351 | createTip({showDelay: 1, anchorToTarget: false, anchor: 'top'});\r | |
352 | jasmine.fireMouseEvent(target, 'mouseover', xy[0], xy[1]);\r | |
353 | });\r | |
354 | waitsFor(function() {\r | |
355 | return tip.isVisible();\r | |
356 | }, "ToolTip was never shown");\r | |
357 | runs(function() {\r | |
358 | expect(tip.el).toBePositionedAt(xy[0] - 15, xy[1] + 30);\r | |
359 | });\r | |
360 | });\r | |
361 | \r | |
362 | it("should allow anchoring the right of the tooltip to the mouse pointer", function() {\r | |
363 | var xy = target.getXY();\r | |
364 | runs(function() {\r | |
365 | createTip({showDelay: 1, anchorToTarget: false, anchor: 'right'});\r | |
366 | jasmine.fireMouseEvent(target, 'mouseover', xy[0], xy[1]);\r | |
367 | });\r | |
368 | waitsFor(function() {\r | |
369 | return tip.isVisible();\r | |
370 | }, "ToolTip was never shown");\r | |
371 | runs(function() {\r | |
372 | expect(tip.el).toBePositionedAt(xy[0] - tip.el.getWidth() - 15, xy[1] - 13);\r | |
373 | });\r | |
374 | });\r | |
375 | \r | |
376 | it("should allow anchoring the bottom of the tooltip to the mouse pointer", function() {\r | |
377 | var xy = target.getXY();\r | |
378 | runs(function() {\r | |
379 | createTip({showDelay: 1, anchorToTarget: false, anchor: 'bottom'});\r | |
380 | jasmine.fireMouseEvent(target, 'mouseover', xy[0], xy[1]);\r | |
381 | });\r | |
382 | waitsFor(function() {\r | |
383 | return tip.isVisible();\r | |
384 | }, "ToolTip was never shown");\r | |
385 | runs(function() {\r | |
386 | expect(tip.el).toBePositionedAt(xy[0] - 19, xy[1] - tip.el.getHeight() - 13);\r | |
387 | });\r | |
388 | });\r | |
389 | \r | |
390 | it("should allow anchoring the left of the tooltip to the mouse pointer", function() {\r | |
391 | var xy = target.getXY();\r | |
392 | runs(function() {\r | |
393 | createTip({showDelay: 1, anchorToTarget: false, anchor: 'left'});\r | |
394 | jasmine.fireMouseEvent(target, 'mouseover', xy[0], xy[1]);\r | |
395 | });\r | |
396 | waitsFor(function() {\r | |
397 | return tip.isVisible();\r | |
398 | }, "ToolTip was never shown");\r | |
399 | runs(function() {\r | |
400 | expect(tip.el).toBePositionedAt(xy[0] + 25, xy[1] - 13);\r | |
401 | });\r | |
402 | });\r | |
403 | });\r | |
404 | \r | |
405 | describe("anchorOffset", function() {\r | |
406 | it("should move the anchor arrow horizontally when anchor is top", function() {\r | |
407 | createTip({anchor: 'top', anchorOffset: 25});\r | |
408 | tip.show();\r | |
409 | var tipXY = tip.el.getXY(),\r | |
410 | anchorXY = tip.anchorEl.getXY();\r | |
411 | expect(anchorXY[0]).toEqual(tipXY[0] + 15 + 25);\r | |
412 | });\r | |
413 | \r | |
414 | it("should move the anchor arrow horizontally when anchor is bottom", function() {\r | |
415 | createTip({anchor: 'bottom', anchorOffset: 25});\r | |
416 | tip.show();\r | |
417 | var tipXY = tip.el.getXY(),\r | |
418 | anchorXY = tip.anchorEl.getXY();\r | |
419 | expect(anchorXY[0]).toEqual(tipXY[0] + 15 + 25);\r | |
420 | });\r | |
421 | \r | |
422 | it("should move the anchor arrow vertically when anchor is left", function() {\r | |
423 | createTip({anchor: 'left', anchorOffset: 25});\r | |
424 | tip.show();\r | |
425 | var tipXY = tip.el.getXY(),\r | |
426 | anchorXY = tip.anchorEl.getXY();\r | |
427 | expect(anchorXY[1]).toEqual(tipXY[1] + 7 + 25);\r | |
428 | });\r | |
429 | \r | |
430 | it("should move the anchor arrow vertically when anchor is right", function() {\r | |
431 | createTip({anchor: 'right', anchorOffset: 25});\r | |
432 | tip.show();\r | |
433 | var tipXY = tip.el.getXY(),\r | |
434 | anchorXY = tip.anchorEl.getXY();\r | |
435 | expect(anchorXY[1]).toEqual(tipXY[1] + 7 + 25);\r | |
436 | });\r | |
437 | });\r | |
438 | \r | |
439 | describe("delegate", function() {\r | |
440 | var delegatedTarget;\r | |
441 | \r | |
442 | beforeEach(function() {\r | |
443 | target.insertHtml('beforeEnd', '<span class="hasTip" id="delegatedTarget">x</span><span class="noTip">x</span>');\r | |
444 | delegatedTarget = Ext.get('delegatedTarget');\r | |
445 | });\r | |
446 | \r | |
447 | afterEach(function() {\r | |
448 | delegatedTarget.destroy();\r | |
449 | });\r | |
450 | \r | |
451 | it("should show the tooltip for descendants matching the selector", function() {\r | |
452 | createTip({delegate: '.hasTip'});\r | |
453 | var spy = spyOn(tip, 'delayShow');\r | |
454 | jasmine.fireMouseEvent(delegatedTarget, 'mouseover', delegatedTarget.getX(), delegatedTarget.getY());\r | |
455 | expect(spy).toHaveBeenCalled();\r | |
456 | });\r | |
457 | \r | |
458 | it("should not show the tooltip for descendants that do not match the selector", function() {\r | |
459 | createTip({delegate: '.hasTip'});\r | |
460 | var spy = spyOn(tip, 'delayShow');\r | |
461 | mouseOverTarget();\r | |
462 | expect(spy).not.toHaveBeenCalled();\r | |
463 | });\r | |
464 | \r | |
465 | it("should set the triggerElement property to the active descendant element when shown", function() {\r | |
466 | createTip({delegate: '.hasTip'});\r | |
467 | jasmine.fireMouseEvent(delegatedTarget, 'mouseover', delegatedTarget.getX(), delegatedTarget.getY());\r | |
468 | expect(tip.triggerElement).toBe(delegatedTarget.dom);\r | |
469 | });\r | |
470 | \r | |
471 | it("should unset the triggerElement property when hiding", function() {\r | |
472 | createTip({delegate: '.hasTip'});\r | |
473 | jasmine.fireMouseEvent(delegatedTarget, 'mouseover', delegatedTarget.getX(), delegatedTarget.getY());\r | |
474 | tip.hide();\r | |
475 | expect(tip.triggerElement).not.toBeDefined();\r | |
476 | });\r | |
477 | });\r | |
478 | \r | |
479 | });\r |