bootstrap-source/bootstrap-3.0.3/js/tests/unit/popover.js
changeset 54 0ded9d7748b7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/tests/unit/popover.js	Fri Dec 20 22:49:16 2013 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +$(function () {
     1.5 +
     1.6 +    module("popover")
     1.7 +
     1.8 +      test("should provide no conflict", function () {
     1.9 +        var popover = $.fn.popover.noConflict()
    1.10 +        ok(!$.fn.popover, 'popover was set back to undefined (org value)')
    1.11 +        $.fn.popover = popover
    1.12 +      })
    1.13 +
    1.14 +      test("should be defined on jquery object", function () {
    1.15 +        var div = $('<div></div>')
    1.16 +        ok(div.popover, 'popover method is defined')
    1.17 +      })
    1.18 +
    1.19 +      test("should return element", function () {
    1.20 +        var div = $('<div></div>')
    1.21 +        ok(div.popover() == div, 'document.body returned')
    1.22 +      })
    1.23 +
    1.24 +      test("should render popover element", function () {
    1.25 +        $.support.transition = false
    1.26 +        var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
    1.27 +          .appendTo('#qunit-fixture')
    1.28 +          .popover('show')
    1.29 +
    1.30 +        ok($('.popover').length, 'popover was inserted')
    1.31 +        popover.popover('hide')
    1.32 +        ok(!$(".popover").length, 'popover removed')
    1.33 +      })
    1.34 +
    1.35 +      test("should store popover instance in popover data object", function () {
    1.36 +        $.support.transition = false
    1.37 +        var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
    1.38 +          .popover()
    1.39 +
    1.40 +        ok(!!popover.data('bs.popover'), 'popover instance exists')
    1.41 +      })
    1.42 +
    1.43 +      test("should get title and content from options", function () {
    1.44 +        $.support.transition = false
    1.45 +        var popover = $('<a href="#">@fat</a>')
    1.46 +          .appendTo('#qunit-fixture')
    1.47 +          .popover({
    1.48 +            title: function () {
    1.49 +              return '@fat'
    1.50 +            }
    1.51 +          , content: function () {
    1.52 +              return 'loves writing tests (╯°□°)╯︵ ┻━┻'
    1.53 +            }
    1.54 +          })
    1.55 +
    1.56 +        popover.popover('show')
    1.57 +
    1.58 +        ok($('.popover').length, 'popover was inserted')
    1.59 +        equal($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
    1.60 +        equal($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
    1.61 +
    1.62 +        popover.popover('hide')
    1.63 +        ok(!$('.popover').length, 'popover was removed')
    1.64 +        $('#qunit-fixture').empty()
    1.65 +      })
    1.66 +
    1.67 +      test("should get title and content from attributes", function () {
    1.68 +        $.support.transition = false
    1.69 +        var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
    1.70 +          .appendTo('#qunit-fixture')
    1.71 +          .popover()
    1.72 +          .popover('show')
    1.73 +
    1.74 +        ok($('.popover').length, 'popover was inserted')
    1.75 +        equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
    1.76 +        equal($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
    1.77 +
    1.78 +        popover.popover('hide')
    1.79 +        ok(!$('.popover').length, 'popover was removed')
    1.80 +        $('#qunit-fixture').empty()
    1.81 +      })
    1.82 +
    1.83 +
    1.84 +      test("should get title and content from attributes #2", function () {
    1.85 +        $.support.transition = false
    1.86 +        var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
    1.87 +          .appendTo('#qunit-fixture')
    1.88 +          .popover({
    1.89 +              title: 'ignored title option',
    1.90 +              content: 'ignored content option'
    1.91 +          })
    1.92 +          .popover('show')
    1.93 +
    1.94 +        ok($('.popover').length, 'popover was inserted')
    1.95 +        equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
    1.96 +        equal($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
    1.97 +
    1.98 +        popover.popover('hide')
    1.99 +        ok(!$('.popover').length, 'popover was removed')
   1.100 +        $('#qunit-fixture').empty()
   1.101 +      })
   1.102 +
   1.103 +      test("should respect custom classes", function() {
   1.104 +        $.support.transition = false
   1.105 +        var popover = $('<a href="#">@fat</a>')
   1.106 +          .appendTo('#qunit-fixture')
   1.107 +          .popover({
   1.108 +            title: 'Test'
   1.109 +          , content: 'Test'
   1.110 +          , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'
   1.111 +          })
   1.112 +
   1.113 +        popover.popover('show')
   1.114 +
   1.115 +        ok($('.popover').length, 'popover was inserted')
   1.116 +        ok($('.popover').hasClass('foobar'), 'custom class is present')
   1.117 +
   1.118 +        popover.popover('hide')
   1.119 +        ok(!$('.popover').length, 'popover was removed')
   1.120 +        $('#qunit-fixture').empty()
   1.121 +      })
   1.122 +
   1.123 +      test("should destroy popover", function () {
   1.124 +        var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function(){})
   1.125 +        ok(popover.data('bs.popover'), 'popover has data')
   1.126 +        ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event')
   1.127 +        ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover has extra click.foo event')
   1.128 +        popover.popover('show')
   1.129 +        popover.popover('destroy')
   1.130 +        ok(!popover.hasClass('in'), 'popover is hidden')
   1.131 +        ok(!popover.data('popover'), 'popover does not have data')
   1.132 +        ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo')
   1.133 +        ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events')
   1.134 +      })
   1.135 +
   1.136 +})
Impressum Datenschutzerklärung