| 21627 |
kshitij.so |
1 |
describe "Morris.Hover", ->
|
|
|
2 |
|
|
|
3 |
describe "with dummy content", ->
|
|
|
4 |
|
|
|
5 |
beforeEach ->
|
|
|
6 |
parent = $('<div style="width:200px;height:180px"></div>')
|
|
|
7 |
.appendTo($('#test'))
|
|
|
8 |
@hover = new Morris.Hover(parent: parent)
|
|
|
9 |
@element = $('#test .morris-hover')
|
|
|
10 |
|
|
|
11 |
it "should initialise a hidden, empty popup", ->
|
|
|
12 |
@element.should.exist
|
|
|
13 |
@element.should.be.hidden
|
|
|
14 |
@element.should.be.empty
|
|
|
15 |
|
|
|
16 |
describe "#show", ->
|
|
|
17 |
it "should show the popup", ->
|
|
|
18 |
@hover.show()
|
|
|
19 |
@element.should.be.visible
|
|
|
20 |
|
|
|
21 |
describe "#hide", ->
|
|
|
22 |
it "should hide the popup", ->
|
|
|
23 |
@hover.show()
|
|
|
24 |
@hover.hide()
|
|
|
25 |
@element.should.be.hidden
|
|
|
26 |
|
|
|
27 |
describe "#html", ->
|
|
|
28 |
it "should replace the contents of the element", ->
|
|
|
29 |
@hover.html('<div>Foobarbaz</div>')
|
|
|
30 |
@element.should.have.html('<div>Foobarbaz</div>')
|
|
|
31 |
|
|
|
32 |
describe "#moveTo", ->
|
|
|
33 |
beforeEach ->
|
|
|
34 |
@hover.html('<div style="width:84px;height:84px"></div>')
|
|
|
35 |
|
|
|
36 |
it "should place the popup directly above the given point", ->
|
|
|
37 |
@hover.moveTo(100, 150)
|
|
|
38 |
@element.should.have.css('left', '50px')
|
|
|
39 |
@element.should.have.css('top', '40px')
|
|
|
40 |
|
|
|
41 |
it "should place the popup below the given point if it does not fit above", ->
|
|
|
42 |
@hover.moveTo(100, 50)
|
|
|
43 |
@element.should.have.css('left', '50px')
|
|
|
44 |
@element.should.have.css('top', '60px')
|
|
|
45 |
|
|
|
46 |
it "should center the popup vertically if it will not fit above or below", ->
|
|
|
47 |
@hover.moveTo(100, 100)
|
|
|
48 |
@element.should.have.css('left', '50px')
|
|
|
49 |
@element.should.have.css('top', '40px')
|
|
|
50 |
|
|
|
51 |
it "should center the popup vertically if no y value is supplied", ->
|
|
|
52 |
@hover.moveTo(100)
|
|
|
53 |
@element.should.have.css('left', '50px')
|
|
|
54 |
@element.should.have.css('top', '40px')
|
|
|
55 |
|
|
|
56 |
describe "#update", ->
|
|
|
57 |
it "should update content, show and reposition the popup", ->
|
|
|
58 |
hover = new Morris.Hover(parent: $('#test'))
|
|
|
59 |
html = "<div style='width:84px;height:84px'>Hello, Everyone!</div>"
|
|
|
60 |
hover.update(html, 150, 200)
|
|
|
61 |
el = $('#test .morris-hover')
|
|
|
62 |
el.should.have.css('left', '100px')
|
|
|
63 |
el.should.have.css('top', '90px')
|
|
|
64 |
el.should.have.text('Hello, Everyone!')
|