bootstrap-tooltip.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. $(function () {
  2. module("bootstrap-tooltip")
  3. test("should be defined on jquery object", function () {
  4. var div = $("<div></div>")
  5. ok(div.tooltip, 'popover method is defined')
  6. })
  7. test("should return element", function () {
  8. var div = $("<div></div>")
  9. ok(div.tooltip() == div, 'document.body returned')
  10. })
  11. test("should expose default settings", function () {
  12. ok(!!$.fn.tooltip.defaults, 'defaults is defined')
  13. })
  14. test("should remove title attribute", function () {
  15. var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
  16. ok(!tooltip.attr('title'), 'title tag was removed')
  17. })
  18. test("should add data attribute for referencing original title", function () {
  19. var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
  20. equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
  21. })
  22. test("should place tooltips relative to placement option", function () {
  23. $.support.transition = false
  24. var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
  25. .appendTo('#qunit-fixture')
  26. .tooltip({placement: 'bottom'})
  27. .tooltip('show')
  28. ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied')
  29. tooltip.tooltip('hide')
  30. })
  31. test("should always allow html entities", function () {
  32. $.support.transition = false
  33. var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>')
  34. .appendTo('#qunit-fixture')
  35. .tooltip('show')
  36. ok($('.tooltip b').length, 'b tag was inserted')
  37. tooltip.tooltip('hide')
  38. ok(!$(".tooltip").length, 'tooltip removed')
  39. })
  40. test("should respect custom classes", function () {
  41. var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
  42. .appendTo('#qunit-fixture')
  43. .tooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'})
  44. .tooltip('show')
  45. ok($('.tooltip').hasClass('some-class'), 'custom class is present')
  46. tooltip.tooltip('hide')
  47. ok(!$(".tooltip").length, 'tooltip removed')
  48. })
  49. })