bootstrap-source/bootstrap-3.0.3/js/tests/unit/popover.js
changeset 115 a9d04f5f5650
parent 54 0ded9d7748b7
equal deleted inserted replaced
114:6093dda9fe38 115:a9d04f5f5650
     1 $(function () {
       
     2 
       
     3     module("popover")
       
     4 
       
     5       test("should provide no conflict", function () {
       
     6         var popover = $.fn.popover.noConflict()
       
     7         ok(!$.fn.popover, 'popover was set back to undefined (org value)')
       
     8         $.fn.popover = popover
       
     9       })
       
    10 
       
    11       test("should be defined on jquery object", function () {
       
    12         var div = $('<div></div>')
       
    13         ok(div.popover, 'popover method is defined')
       
    14       })
       
    15 
       
    16       test("should return element", function () {
       
    17         var div = $('<div></div>')
       
    18         ok(div.popover() == div, 'document.body returned')
       
    19       })
       
    20 
       
    21       test("should render popover element", function () {
       
    22         $.support.transition = false
       
    23         var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
       
    24           .appendTo('#qunit-fixture')
       
    25           .popover('show')
       
    26 
       
    27         ok($('.popover').length, 'popover was inserted')
       
    28         popover.popover('hide')
       
    29         ok(!$(".popover").length, 'popover removed')
       
    30       })
       
    31 
       
    32       test("should store popover instance in popover data object", function () {
       
    33         $.support.transition = false
       
    34         var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
       
    35           .popover()
       
    36 
       
    37         ok(!!popover.data('bs.popover'), 'popover instance exists')
       
    38       })
       
    39 
       
    40       test("should get title and content from options", function () {
       
    41         $.support.transition = false
       
    42         var popover = $('<a href="#">@fat</a>')
       
    43           .appendTo('#qunit-fixture')
       
    44           .popover({
       
    45             title: function () {
       
    46               return '@fat'
       
    47             }
       
    48           , content: function () {
       
    49               return 'loves writing tests (╯°□°)╯︵ ┻━┻'
       
    50             }
       
    51           })
       
    52 
       
    53         popover.popover('show')
       
    54 
       
    55         ok($('.popover').length, 'popover was inserted')
       
    56         equal($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
       
    57         equal($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
       
    58 
       
    59         popover.popover('hide')
       
    60         ok(!$('.popover').length, 'popover was removed')
       
    61         $('#qunit-fixture').empty()
       
    62       })
       
    63 
       
    64       test("should get title and content from attributes", function () {
       
    65         $.support.transition = false
       
    66         var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
       
    67           .appendTo('#qunit-fixture')
       
    68           .popover()
       
    69           .popover('show')
       
    70 
       
    71         ok($('.popover').length, 'popover was inserted')
       
    72         equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
       
    73         equal($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
       
    74 
       
    75         popover.popover('hide')
       
    76         ok(!$('.popover').length, 'popover was removed')
       
    77         $('#qunit-fixture').empty()
       
    78       })
       
    79 
       
    80 
       
    81       test("should get title and content from attributes #2", function () {
       
    82         $.support.transition = false
       
    83         var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
       
    84           .appendTo('#qunit-fixture')
       
    85           .popover({
       
    86               title: 'ignored title option',
       
    87               content: 'ignored content option'
       
    88           })
       
    89           .popover('show')
       
    90 
       
    91         ok($('.popover').length, 'popover was inserted')
       
    92         equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
       
    93         equal($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
       
    94 
       
    95         popover.popover('hide')
       
    96         ok(!$('.popover').length, 'popover was removed')
       
    97         $('#qunit-fixture').empty()
       
    98       })
       
    99 
       
   100       test("should respect custom classes", function() {
       
   101         $.support.transition = false
       
   102         var popover = $('<a href="#">@fat</a>')
       
   103           .appendTo('#qunit-fixture')
       
   104           .popover({
       
   105             title: 'Test'
       
   106           , content: 'Test'
       
   107           , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'
       
   108           })
       
   109 
       
   110         popover.popover('show')
       
   111 
       
   112         ok($('.popover').length, 'popover was inserted')
       
   113         ok($('.popover').hasClass('foobar'), 'custom class is present')
       
   114 
       
   115         popover.popover('hide')
       
   116         ok(!$('.popover').length, 'popover was removed')
       
   117         $('#qunit-fixture').empty()
       
   118       })
       
   119 
       
   120       test("should destroy popover", function () {
       
   121         var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function(){})
       
   122         ok(popover.data('bs.popover'), 'popover has data')
       
   123         ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event')
       
   124         ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover has extra click.foo event')
       
   125         popover.popover('show')
       
   126         popover.popover('destroy')
       
   127         ok(!popover.hasClass('in'), 'popover is hidden')
       
   128         ok(!popover.data('popover'), 'popover does not have data')
       
   129         ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo')
       
   130         ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events')
       
   131       })
       
   132 
       
   133 })
       
Impressum Datenschutzerklärung