QUnit.test('should use title attribute for tooltip text', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
$tooltip
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should prefer title attribute over title option', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should use title option', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not error when trying to show an top-placed tooltip that has been removed from the dom', function (assert) {
assert.expect(1)
var passed = true
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.one('show.bs.tooltip', function () {
$(this).remove()
})
.bootstrapTooltip({
placement: 'top'
})
try {
$tooltip.bootstrapTooltip('show')
} catch (err) {
passed = false
}
assert.ok(passed, '.tooltip(\'show\') should not throw an error if element no longer is in dom')
})
QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: 150
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip is not faded active')
}, 100)
setTimeout(function () {
assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip is faded active')
done()
}, 200)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
delay: 150
})
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active')
$tooltip.trigger('mouseout')
}, 100)
setTimeout(function () {
assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active')
done()
}, 200)
$tooltip.trigger('mouseenter')
})
QUnit.test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) {
assert.expect(3)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')