bootstrap-popover.js 3.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$(function () {

    module("bootstrap-popover")

      test("should be defined on jquery object", function () {
        var div = $('<div></div>')
        ok(div.popover, 'popover method is defined')
      })

      test("should return element", function () {
        var div = $('<div></div>')
        ok(div.popover() == div, 'document.body returned')
      })

      test("should render popover element", function () {
        $.support.transition = false
Jacob Thornton's avatar
Jacob Thornton committed
17
        var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
18
          .appendTo('#qunit-fixture')
Jacob Thornton's avatar
Jacob Thornton committed
19
          .popover('show')
20
21

        ok($('.popover').length, 'popover was inserted')
Jacob Thornton's avatar
Jacob Thornton committed
22
        popover.popover('hide')
23
24
25
26
27
        ok(!$(".popover").length, 'popover removed')
      })

      test("should store popover instance in popover data object", function () {
        $.support.transition = false
Jacob Thornton's avatar
Jacob Thornton committed
28
        var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
29
30
31
32
33
34
35
36
          .popover()

        ok(!!popover.data('popover'), 'popover instance exists')
      })

      test("should get title and content from options", function () {
        $.support.transition = false
        var popover = $('<a href="#">@fat</a>')
37
          .appendTo('#qunit-fixture')
38
          .popover({
Jacob Thornton's avatar
Jacob Thornton committed
39
40
41
42
43
44
            title: function () {
              return '@fat'
            }
          , content: function () {
              return 'loves writing tests (╯°□°)╯︵ ┻━┻'
            }
45
          })
Jacob Thornton's avatar
Jacob Thornton committed
46
47

        popover.popover('show')
48
49

        ok($('.popover').length, 'popover was inserted')
50
51
        equals($('.popover .popover-title').text(), '@fat', 'title correctly inserted')
        equals($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted')
52

Jacob Thornton's avatar
Jacob Thornton committed
53
        popover.popover('hide')
54
        ok(!$('.popover').length, 'popover was removed')
55
        $('#qunit-fixture').empty()
56
57
58
59
      })

      test("should get title and content from attributes", function () {
        $.support.transition = false
Jacob Thornton's avatar
Jacob Thornton committed
60
        var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
61
          .appendTo('#qunit-fixture')
62
          .popover()
Jacob Thornton's avatar
Jacob Thornton committed
63
          .popover('show')
64
65

        ok($('.popover').length, 'popover was inserted')
66
67
        equals($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
        equals($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted')
68

Jacob Thornton's avatar
Jacob Thornton committed
69
        popover.popover('hide')
70
        ok(!$('.popover').length, 'popover was removed')
71
        $('#qunit-fixture').empty()
72
      })
73
74
75
76
77
78
79
80
81
82
83
84
    
      test("should respect custom classes", function() {
        $.support.transition = false
        var popover = $('<a href="#">@fat</a>')
          .appendTo('#qunit-fixture')
          .popover({
            title: 'Test'
          , content: 'Test'
          , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>'
          })
        
        popover.popover('show')
Jacob Thornton's avatar
Jacob Thornton committed
85

86
87
        ok($('.popover').length, 'popover was inserted')
        ok($('.popover').hasClass('foobar'), 'custom class is present')
88

89
90
91
92
        popover.popover('hide')
        ok(!$('.popover').length, 'popover was removed')
        $('#qunit-fixture').empty()
      })
93
94
95
96
97
98
99
100
101
102

      test("should destroy popover", function () {
        var popover = $('<div/>').popover()
        ok(popover.data('popover'), 'popover has data')
        ok(popover.data('events').mouseover && popover.data('events').mouseout, 'popover has hover event')
        popover.popover('destroy')
        ok(!popover.data('popover'), 'popover does not have data')
        ok(!popover.data('events'), 'popover does not have any events')
      })
      
103
})