hover_spec.coffee 2.2 KB

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