bootstrap-popover.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. $(function () {
  2. module("bootstrap-popover")
  3. test("should provide no conflict", function () {
  4. var popover = $.fn.popover.noConflict()
  5. ok(!$.fn.popover, 'popover was set back to undefined (org value)')
  6. $.fn.popover = popover
  7. })
  8. test("should be defined on jquery object", function () {
  9. var div = $('<div></div>')
  10. ok(div.popover, 'popover method is defined')
  11. })
  12. test("should return element", function () {
  13. var div = $('<div></div>')
  14. ok(div.popover() == div, 'document.body returned')
  15. })
  16. test("should render popover element", function () {
  17. $.support.transition = false
  18. var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
  19. .appendTo('#qunit-fixture')
  20. .popover('show')
  21. ok($('.popover').length, 'popover was inserted')
  22. popover.popover('hide')
  23. ok(!$(".popover").length, 'popover removed')
  24. })
  25. test("should store popover instance in popover data object", function () {
  26. $.support.transition = false
  27. var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
  28. .popover()
  29. ok(!!popover.data('popover'), 'popover instance exists')
  30. })
  31. test("should get title and content from options", function () {
  32. $.support.transition = false
  33. var popover = $('<a href="#">@fat</a>')
  34. .appendTo('#qunit-fixture')
  35. .popover({
  36. title: function () {
  37. return '@fat'
  38. }
  39. , content: function () {
  40. return 'loves writing tests (╯°□°)╯︵ ┻━┻'
  41. }
  42. })
  43. popover.popover('show')
  44. ok($('.popover').length, 'popover was inserted')
  45. equals($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
  46. equals($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
  47. popover.popover('hide')
  48. ok(!$('.popover').length, 'popover was removed')
  49. $('#qunit-fixture').empty()
  50. })
  51. test("should get title and content from attributes", function () {
  52. $.support.transition = false
  53. var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
  54. .appendTo('#qunit-fixture')
  55. .popover()
  56. .popover('show')
  57. ok($('.popover').length, 'popover was inserted')
  58. equals($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
  59. equals($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
  60. popover.popover('hide')
  61. ok(!$('.popover').length, 'popover was removed')
  62. $('#qunit-fixture').empty()
  63. })
  64. test("should respect custom classes", function() {
  65. $.support.transition = false
  66. var popover = $('<a href="#">@fat</a>')
  67. .appendTo('#qunit-fixture')
  68. .popover({
  69. title: 'Test'
  70. , content: 'Test'
  71. , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'
  72. })
  73. popover.popover('show')
  74. ok($('.popover').length, 'popover was inserted')
  75. ok($('.popover').hasClass('foobar'), 'custom class is present')
  76. popover.popover('hide')
  77. ok(!$('.popover').length, 'popover was removed')
  78. $('#qunit-fixture').empty()
  79. })
  80. test("should destroy popover", function () {
  81. var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function(){})
  82. ok(popover.data('popover'), 'popover has data')
  83. ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event')
  84. ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover has extra click.foo event')
  85. popover.popover('show')
  86. popover.popover('destroy')
  87. ok(!popover.hasClass('in'), 'popover is hidden')
  88. ok(!popover.data('popover'), 'popover does not have data')
  89. ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo')
  90. ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events')
  91. })
  92. })