bootstrap-popover.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. $(function () {
  2. module("bootstrap-popover")
  3. test("should be defined on jquery object", function () {
  4. var div = $('<div></div>')
  5. ok(div.popover, 'popover method is defined')
  6. })
  7. test("should return element", function () {
  8. var div = $('<div></div>')
  9. ok(div.popover() == div, 'document.body returned')
  10. })
  11. test("should render popover element", function () {
  12. $.support.transition = false
  13. var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
  14. .appendTo('#qunit-fixture')
  15. .popover('show')
  16. ok($('.popover').length, 'popover was inserted')
  17. popover.popover('hide')
  18. ok(!$(".popover").length, 'popover removed')
  19. })
  20. test("should store popover instance in popover data object", function () {
  21. $.support.transition = false
  22. var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
  23. .popover()
  24. ok(!!popover.data('popover'), 'popover instance exists')
  25. })
  26. test("should get title and content from options", function () {
  27. $.support.transition = false
  28. var popover = $('<a href="#">@fat</a>')
  29. .appendTo('#qunit-fixture')
  30. .popover({
  31. title: function () {
  32. return '@fat'
  33. }
  34. , content: function () {
  35. return 'loves writing tests (╯°□°)╯︵ ┻━┻'
  36. }
  37. })
  38. popover.popover('show')
  39. ok($('.popover').length, 'popover was inserted')
  40. equals($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
  41. equals($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
  42. popover.popover('hide')
  43. ok(!$('.popover').length, 'popover was removed')
  44. $('#qunit-fixture').empty()
  45. })
  46. test("should get title and content from attributes", function () {
  47. $.support.transition = false
  48. var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
  49. .appendTo('#qunit-fixture')
  50. .popover()
  51. .popover('show')
  52. ok($('.popover').length, 'popover was inserted')
  53. equals($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
  54. equals($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
  55. popover.popover('hide')
  56. ok(!$('.popover').length, 'popover was removed')
  57. $('#qunit-fixture').empty()
  58. })
  59. test("should respect custom classes", function() {
  60. $.support.transition = false
  61. var popover = $('<a href="#">@fat</a>')
  62. .appendTo('#qunit-fixture')
  63. .popover({
  64. title: 'Test'
  65. , content: 'Test'
  66. , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'
  67. })
  68. popover.popover('show')
  69. ok($('.popover').length, 'popover was inserted')
  70. ok($('.popover').hasClass('foobar'), 'custom class is present')
  71. popover.popover('hide')
  72. ok(!$('.popover').length, 'popover was removed')
  73. $('#qunit-fixture').empty()
  74. })
  75. })