Add Intel copyright header.
[profile/ivi/cowhide.git] / tests / unit / bootstrap-tooltip.js
1 $(function () {
2
3     module("bootstrap-tooltip")
4
5       test("should provide no conflict", function () {
6         var tooltip = $.fn.tooltip.noConflict()
7         ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)')
8         $.fn.tooltip = tooltip
9       })
10
11       test("should be defined on jquery object", function () {
12         var div = $("<div></div>")
13         ok(div.tooltip, 'popover method is defined')
14       })
15
16       test("should return element", function () {
17         var div = $("<div></div>")
18         ok(div.tooltip() == div, 'document.body returned')
19       })
20
21       test("should expose default settings", function () {
22         ok(!!$.fn.tooltip.defaults, 'defaults is defined')
23       })
24
25       test("should remove title attribute", function () {
26         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
27         ok(!tooltip.attr('title'), 'title tag was removed')
28       })
29
30       test("should add data attribute for referencing original title", function () {
31         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip()
32         equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
33       })
34
35       test("should place tooltips relative to placement option", function () {
36         $.support.transition = false
37         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
38           .appendTo('#qunit-fixture')
39           .tooltip({placement: 'bottom'})
40           .tooltip('show')
41
42         ok($(".tooltip").is('.fade.bottom.in'), 'has correct classes applied')
43         tooltip.tooltip('hide')
44       })
45
46       test("should allow html entities", function () {
47         $.support.transition = false
48         var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>')
49           .appendTo('#qunit-fixture')
50           .tooltip({html: true})
51           .tooltip('show')
52
53         ok($('.tooltip b').length, 'b tag was inserted')
54         tooltip.tooltip('hide')
55         ok(!$(".tooltip").length, 'tooltip removed')
56       })
57
58       test("should respect custom classes", function () {
59         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
60           .appendTo('#qunit-fixture')
61           .tooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'})
62           .tooltip('show')
63
64         ok($('.tooltip').hasClass('some-class'), 'custom class is present')
65         tooltip.tooltip('hide')
66         ok(!$(".tooltip").length, 'tooltip removed')
67       })
68
69       test("should not show tooltip if leave event occurs before delay expires", function () {
70         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
71           .appendTo('#qunit-fixture')
72           .tooltip({ delay: 200 })
73
74         stop()
75
76         tooltip.trigger('mouseenter')
77
78         setTimeout(function () {
79           ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
80           tooltip.trigger('mouseout')
81           setTimeout(function () {
82             ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
83             start()
84           }, 200)
85         }, 100)
86       })
87
88       test("should not show tooltip if leave event occurs before delay expires, even if hide delay is 0", function () {
89         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
90           .appendTo('#qunit-fixture')
91           .tooltip({ delay: { show: 200, hide: 0} })
92
93         stop()
94
95         tooltip.trigger('mouseenter')
96
97         setTimeout(function () {
98           ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
99           tooltip.trigger('mouseout')
100           setTimeout(function () {
101             ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
102             start()
103           }, 200)
104         }, 100)
105       })
106
107       test("should not show tooltip if leave event occurs before delay expires", function () {
108         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
109           .appendTo('#qunit-fixture')
110           .tooltip({ delay: 100 })
111         stop()
112         tooltip.trigger('mouseenter')
113         setTimeout(function () {
114           ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
115           tooltip.trigger('mouseout')
116           setTimeout(function () {
117             ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
118             start()
119           }, 100)
120         }, 50)
121       })
122
123       test("should show tooltip if leave event hasn't occured before delay expires", function () {
124         var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
125           .appendTo('#qunit-fixture')
126           .tooltip({ delay: 150 })
127         stop()
128         tooltip.trigger('mouseenter')
129         setTimeout(function () {
130           ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
131         }, 100)
132         setTimeout(function () {
133           ok($(".tooltip").is('.fade.in'), 'tooltip has faded in')
134           start()
135         }, 200)
136       })
137
138       test("should destroy tooltip", function () {
139         var tooltip = $('<div/>').tooltip().on('click.foo', function(){})
140         ok(tooltip.data('tooltip'), 'tooltip has data')
141         ok($._data(tooltip[0], 'events').mouseover && $._data(tooltip[0], 'events').mouseout, 'tooltip has hover event')
142         ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
143         tooltip.tooltip('show')
144         tooltip.tooltip('destroy')
145         ok(!tooltip.hasClass('in'), 'tooltip is hidden')
146         ok(!$._data(tooltip[0], 'tooltip'), 'tooltip does not have data')
147         ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo')
148         ok(!$._data(tooltip[0], 'events').mouseover && !$._data(tooltip[0], 'events').mouseout, 'tooltip does not have any events')
149       })
150
151       test("should show tooltip with delegate selector on click", function () {
152         var div = $('<div><a href="#" rel="tooltip" title="Another tooltip"></a></div>')
153         var tooltip = div.appendTo('#qunit-fixture')
154                          .tooltip({ selector: 'a[rel=tooltip]',
155                                     trigger: 'click' })
156         div.find('a').trigger('click')
157         ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
158       })
159 })