popover.js 4.88 KB
Newer Older
1
2
$(function () {

XhmikosR's avatar
XhmikosR committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  module('popover')

  test('should provide no conflict', function () {
    var popover = $.fn.popover.noConflict()
    ok(!$.fn.popover, 'popover was set back to undefined (org value)')
    $.fn.popover = 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
    var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
      .appendTo('#qunit-fixture')
      .popover('show')

    ok($('.popover').length, 'popover was inserted')
    popover.popover('hide')
    ok(!$('.popover').length, 'popover removed')
  })

  test('should store popover instance in popover data object', function () {
    $.support.transition = false
    var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
      .popover()

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

  test('should get title and content from options', function () {
    $.support.transition = false
    var popover = $('<a href="#">@fat</a>')
      .appendTo('#qunit-fixture')
      .popover({
        title: function () {
          return '@fat'
        },
        content: function () {
          return 'loves writing tests (╯°□°)╯︵ ┻━┻'
        }
51
52
      })

XhmikosR's avatar
XhmikosR committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    popover.popover('show')

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

    popover.popover('hide')
    ok(!$('.popover').length, 'popover was removed')
    $('#qunit-fixture').empty()
  })

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

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

    popover.popover('hide')
    ok(!$('.popover').length, 'popover was removed')
    $('#qunit-fixture').empty()
  })


  test('should get title and content from attributes #2', function () {
    $.support.transition = false
    var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
      .appendTo('#qunit-fixture')
      .popover({
        title: 'ignored title option',
        content: 'ignored content option'
88
      })
XhmikosR's avatar
XhmikosR committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
      .popover('show')

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

    popover.popover('hide')
    ok(!$('.popover').length, 'popover was removed')
    $('#qunit-fixture').empty()
  })

  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>'
108
109
      })

XhmikosR's avatar
XhmikosR committed
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    popover.popover('show')

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

    popover.popover('hide')
    ok(!$('.popover').length, 'popover was removed')
    $('#qunit-fixture').empty()
  })

  test('should destroy popover', function () {
    var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function () {})
    ok(popover.data('bs.popover'), 'popover has data')
    ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event')
    ok($._data(popover[0], 'events').click[0].namespace == 'foo', 'popover has extra click.foo event')
    popover.popover('show')
    popover.popover('destroy')
    ok(!popover.hasClass('in'), 'popover is hidden')
    ok(!popover.data('popover'), 'popover does not have data')
    ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo')
    ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events')
  })
132

133
})