info@54: $(function () {
info@54:
info@54: module("tooltip")
info@54:
info@54: test("should provide no conflict", function () {
info@54: var tooltip = $.fn.tooltip.noConflict()
info@54: ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)')
info@54: $.fn.tooltip = tooltip
info@54: })
info@54:
info@54: test("should be defined on jquery object", function () {
info@54: var div = $("
")
info@54: ok(div.tooltip, 'popover method is defined')
info@54: })
info@54:
info@54: test("should return element", function () {
info@54: var div = $("")
info@54: ok(div.tooltip() == div, 'document.body returned')
info@54: })
info@54:
info@54: test("should expose default settings", function () {
info@54: ok(!!$.fn.tooltip.Constructor.DEFAULTS, 'defaults is defined')
info@54: })
info@54:
info@54: test("should empty title attribute", function () {
info@54: var tooltip = $('').tooltip()
info@54: ok(tooltip.attr('title') === '', 'title attribute was emptied')
info@54: })
info@54:
info@54: test("should add data attribute for referencing original title", function () {
info@54: var tooltip = $('').tooltip()
info@54: equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
info@54: })
info@54:
info@54: test("should place tooltips relative to placement option", function () {
info@54: $.support.transition = false
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({placement: 'bottom'})
info@54: .tooltip('show')
info@54:
info@54: ok($(".tooltip").is('.fade.bottom.in'), 'has correct classes applied')
info@54: tooltip.tooltip('hide')
info@54: })
info@54:
info@54: test("should allow html entities", function () {
info@54: $.support.transition = false
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({html: true})
info@54: .tooltip('show')
info@54:
info@54: ok($('.tooltip b').length, 'b tag was inserted')
info@54: tooltip.tooltip('hide')
info@54: ok(!$(".tooltip").length, 'tooltip removed')
info@54: })
info@54:
info@54: test("should respect custom classes", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ template: ''})
info@54: .tooltip('show')
info@54:
info@54: ok($('.tooltip').hasClass('some-class'), 'custom class is present')
info@54: tooltip.tooltip('hide')
info@54: ok(!$(".tooltip").length, 'tooltip removed')
info@54: })
info@54:
info@54: test("should fire show event", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("show.bs.tooltip", function() {
info@54: ok(true, "show was called")
info@54: start()
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should fire shown event", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("shown.bs.tooltip", function() {
info@54: ok(true, "shown was called")
info@54: start()
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should not fire shown event when default prevented", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("show.bs.tooltip", function(e) {
info@54: e.preventDefault()
info@54: ok(true, "show was called")
info@54: start()
info@54: })
info@54: .on("shown.bs.tooltip", function() {
info@54: ok(false, "shown was called")
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should fire hide event", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("shown.bs.tooltip", function() {
info@54: $(this).tooltip('hide')
info@54: })
info@54: .on("hide.bs.tooltip", function() {
info@54: ok(true, "hide was called")
info@54: start()
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should fire hidden event", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("shown.bs.tooltip", function() {
info@54: $(this).tooltip('hide')
info@54: })
info@54: .on("hidden.bs.tooltip", function() {
info@54: ok(true, "hidden was called")
info@54: start()
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should not fire hidden event when default prevented", function () {
info@54: stop()
info@54: var tooltip = $('')
info@54: .on("shown.bs.tooltip", function() {
info@54: $(this).tooltip('hide')
info@54: })
info@54: .on("hide.bs.tooltip", function(e) {
info@54: e.preventDefault()
info@54: ok(true, "hide was called")
info@54: start()
info@54: })
info@54: .on("hidden.bs.tooltip", function() {
info@54: ok(false, "hidden was called")
info@54: })
info@54: .tooltip('show')
info@54: })
info@54:
info@54: test("should not show tooltip if leave event occurs before delay expires", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: 200 })
info@54:
info@54: stop()
info@54:
info@54: tooltip.trigger('mouseenter')
info@54:
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: tooltip.trigger('mouseout')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: start()
info@54: }, 200)
info@54: }, 100)
info@54: })
info@54:
info@54: test("should not show tooltip if leave event occurs before delay expires, even if hide delay is 0", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: { show: 200, hide: 0} })
info@54:
info@54: stop()
info@54:
info@54: tooltip.trigger('mouseenter')
info@54:
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: tooltip.trigger('mouseout')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: start()
info@54: }, 200)
info@54: }, 100)
info@54: })
info@54:
info@54: test("should wait 200 ms before hiding the tooltip", 3, function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: { show: 0, hide: 200} })
info@54:
info@54: stop()
info@54:
info@54: tooltip.trigger('mouseenter')
info@54:
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
info@54: tooltip.trigger('mouseout')
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.fade.in'), '100ms:tooltip is still faded in')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.in'), 'tooltip removed')
info@54: start()
info@54: }, 150)
info@54: }, 100)
info@54: }, 1)
info@54: })
info@54:
info@54: test("should not hide tooltip if leave event occurs, then tooltip is show immediately again", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: { show: 0, hide: 200} })
info@54:
info@54: stop()
info@54:
info@54: tooltip.trigger('mouseenter')
info@54:
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
info@54: tooltip.trigger('mouseout')
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.fade.in'), '100ms:tooltip is still faded in')
info@54: tooltip.trigger('mouseenter')
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.in'), 'tooltip removed')
info@54: start()
info@54: }, 150)
info@54: }, 100)
info@54: }, 1)
info@54: })
info@54:
info@54: test("should not show tooltip if leave event occurs before delay expires", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: 100 })
info@54: stop()
info@54: tooltip.trigger('mouseenter')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: tooltip.trigger('mouseout')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: start()
info@54: }, 100)
info@54: }, 50)
info@54: })
info@54:
info@54: test("should show tooltip if leave event hasn't occured before delay expires", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({ delay: 150 })
info@54: stop()
info@54: tooltip.trigger('mouseenter')
info@54: setTimeout(function () {
info@54: ok(!$(".tooltip").is('.fade.in'), 'tooltip is not faded in')
info@54: }, 100)
info@54: setTimeout(function () {
info@54: ok($(".tooltip").is('.fade.in'), 'tooltip has faded in')
info@54: start()
info@54: }, 200)
info@54: })
info@54:
info@54: test("should destroy tooltip", function () {
info@54: var tooltip = $('').tooltip().on('click.foo', function(){})
info@54: ok(tooltip.data('bs.tooltip'), 'tooltip has data')
info@54: ok($._data(tooltip[0], 'events').mouseover && $._data(tooltip[0], 'events').mouseout, 'tooltip has hover event')
info@54: ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
info@54: tooltip.tooltip('show')
info@54: tooltip.tooltip('destroy')
info@54: ok(!tooltip.hasClass('in'), 'tooltip is hidden')
info@54: ok(!$._data(tooltip[0], 'bs.tooltip'), 'tooltip does not have data')
info@54: ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo')
info@54: ok(!$._data(tooltip[0], 'events').mouseover && !$._data(tooltip[0], 'events').mouseout, 'tooltip does not have any events')
info@54: })
info@54:
info@54: test("should show tooltip with delegate selector on click", function () {
info@54: var div = $('')
info@54: var tooltip = div.appendTo('#qunit-fixture')
info@54: .tooltip({ selector: 'a[rel=tooltip]',
info@54: trigger: 'click' })
info@54: div.find('a').trigger('click')
info@54: ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
info@54: })
info@54:
info@54: test("should show tooltip when toggle is called", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({trigger: 'manual'})
info@54: .tooltip('toggle')
info@54: ok($(".tooltip").is('.fade.in'), 'tooltip should be toggled in')
info@54: })
info@54:
info@54: test("should place tooltips inside the body", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({container:'body'})
info@54: .tooltip('show')
info@54: ok($("body > .tooltip").length, 'inside the body')
info@54: ok(!$("#qunit-fixture > .tooltip").length, 'not found in parent')
info@54: tooltip.tooltip('hide')
info@54: })
info@54:
info@54: test("should place tooltip inside window", function(){
info@54: var container = $("").appendTo("body")
info@54: .css({position: "absolute", width: 200, height: 200, bottom: 0, left: 0})
info@54: , tooltip = $("Hover me")
info@54: .css({position: "absolute", top:0, left: 0})
info@54: .appendTo(container)
info@54: .tooltip({placement: "top", animate: false})
info@54: .tooltip("show")
info@54:
info@54: stop()
info@54:
info@54: setTimeout(function(){
info@54: ok($(".tooltip").offset().left >= 0)
info@54:
info@54: start()
info@54: container.remove()
info@54: }, 100)
info@54: })
info@54:
info@54: test("should place tooltip on top of element", function(){
info@54: var container = $("").appendTo("body")
info@54: .css({position: "absolute", bottom: 0, left: 0, textAlign: "right", width: 300, height: 300})
info@54: , p = $("").appendTo(container)
info@54: , tooltiped = $("Hover me")
info@54: .css({marginTop: 200})
info@54: .appendTo(p)
info@54: .tooltip({placement: "top", animate: false})
info@54: .tooltip("show")
info@54:
info@54: stop()
info@54:
info@54: setTimeout(function(){
info@54: var tooltip = container.find(".tooltip")
info@54:
info@54: start()
info@54: ok(tooltip.offset().top + tooltip.outerHeight() <= tooltiped.offset().top)
info@54: container.remove()
info@54: }, 100)
info@54: })
info@54:
info@54: test("should add position class before positioning so that position-specific styles are taken into account", function(){
info@54: $("head").append('')
info@54:
info@54: var container = $("").appendTo("body")
info@54: , target = $('')
info@54: .appendTo(container)
info@54: .tooltip({placement: 'right'})
info@54: .tooltip('show')
info@54: , tooltip = container.find(".tooltip")
info@54:
info@54: ok( Math.round(target.offset().top + target[0].offsetHeight/2 - tooltip[0].offsetHeight/2) === Math.round(tooltip.offset().top) )
info@54: target.tooltip('hide')
info@54: })
info@54:
info@54: test("tooltip title test #1", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({
info@54: })
info@54: .tooltip('show')
info@54: equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
info@54: tooltip.tooltip('hide')
info@54: ok(!$(".tooltip").length, 'tooltip removed')
info@54: })
info@54:
info@54: test("tooltip title test #2", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({
info@54: title: 'This is a tooltip with some content'
info@54: })
info@54: .tooltip('show')
info@54: equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while prefered over title option')
info@54: tooltip.tooltip('hide')
info@54: ok(!$(".tooltip").length, 'tooltip removed')
info@54: })
info@54:
info@54: test("tooltip title test #3", function () {
info@54: var tooltip = $('')
info@54: .appendTo('#qunit-fixture')
info@54: .tooltip({
info@54: title: 'This is a tooltip with some content'
info@54: })
info@54: .tooltip('show')
info@54: equal($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
info@54: tooltip.tooltip('hide')
info@54: ok(!$(".tooltip").length, 'tooltip removed')
info@54: })
info@54:
info@54: test("tooltips should be placed dynamically, with the dynamic placement option", function () {
info@54: $.support.transition = false
info@54: var ttContainer = $('').css({
info@54: 'height' : 400
info@54: , 'overflow' : 'hidden'
info@54: , 'position' : 'absolute'
info@54: , 'top' : 0
info@54: , 'left' : 0
info@54: , 'width' : 600})
info@54: .appendTo('body')
info@54:
info@54: var topTooltip = $('Top Dynamic Tooltip
')
info@54: .appendTo('#dynamic-tt-test')
info@54: .tooltip({placement: 'auto'})
info@54: .tooltip('show')
info@54:
info@54:
info@54: ok($(".tooltip").is('.bottom'), 'top positioned tooltip is dynamically positioned bottom')
info@54:
info@54: topTooltip.tooltip('hide')
info@54:
info@54: var rightTooltip = $('Right Dynamic Tooltip
')
info@54: .appendTo('#dynamic-tt-test')
info@54: .tooltip({placement: 'right auto'})
info@54: .tooltip('show')
info@54:
info@54: ok($(".tooltip").is('.left'), 'right positioned tooltip is dynamically positioned left')
info@54: rightTooltip.tooltip('hide')
info@54:
info@54: var bottomTooltip = $('Bottom Dynamic Tooltip
')
info@54: .appendTo('#dynamic-tt-test')
info@54: .tooltip({placement: 'auto bottom'})
info@54: .tooltip('show')
info@54:
info@54: ok($(".tooltip").is('.top'), 'bottom positioned tooltip is dynamically positioned top')
info@54: bottomTooltip.tooltip('hide')
info@54:
info@54: var leftTooltip = $('Left Dynamic Tooltip
')
info@54: .appendTo('#dynamic-tt-test')
info@54: .tooltip({placement: 'auto left'})
info@54: .tooltip('show')
info@54:
info@54: ok($(".tooltip").is('.right'), 'left positioned tooltip is dynamically positioned right')
info@54: leftTooltip.tooltip('hide')
info@54:
info@54: ttContainer.remove()
info@54: })
info@54:
info@54: })