2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-08 17:22:31 +03:00

Use BrowserStack for our unit tests.

This commit is contained in:
Johann-S
2018-09-07 22:32:52 +03:00
committed by XhmikosR
parent cee8e8653d
commit 4ebe2b8753
20 changed files with 10263 additions and 6686 deletions
+399 -194
View File
@@ -16,6 +16,7 @@ $(function () {
afterEach: function () {
$.fn.tooltip = $.fn.bootstrapTooltip
delete $.fn.bootstrapTooltip
$('#qunit-fixture').html('')
}
})
@@ -26,7 +27,7 @@ $(function () {
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('<div/>')
var $el = $('<div/>').appendTo('#qunit-fixture')
var $tooltip = $el.bootstrapTooltip()
assert.ok($tooltip instanceof $, 'returns jquery collection')
assert.strictEqual($tooltip[0], $el[0], 'collection contains element')
@@ -39,92 +40,132 @@ $(function () {
QUnit.test('should empty title attribute', function (assert) {
assert.expect(1)
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied')
})
QUnit.test('should add data attribute for referencing original title', function (assert) {
assert.expect(1)
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
assert.strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute')
})
QUnit.test('should add aria-describedby to the trigger on show', function (assert) {
assert.expect(3)
var done = assert.async()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
$trigger
.bootstrapTooltip()
.on('shown.bs.tooltip', function () {
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'has a unique id')
assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
done()
})
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'has a unique id')
assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
})
QUnit.test('should remove aria-describedby from trigger on hide', function (assert) {
assert.expect(2)
var done = assert.async()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
$trigger.bootstrapTooltip('show')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
$trigger.bootstrapTooltip('hide')
assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
$trigger.one('shown.bs.tooltip', function () {
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
$trigger.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should assign a unique id tooltip element', function (assert) {
assert.expect(2)
var done = assert.async()
$('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
done()
})
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
})
QUnit.test('should place tooltips relative to placement option', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$tooltip.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.bootstrapTooltip({ placement: 'bottom' })
$tooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
})
QUnit.test('should allow html entities', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="&lt;b&gt;@fat&lt;/b&gt;"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ html: true })
$tooltip.bootstrapTooltip('show')
assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
$tooltip.one('shown.bs.tooltip', function () {
assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should respect custom classes', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>' })
$tooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
$tooltip.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should fire show event', function (assert) {
@@ -255,6 +296,8 @@ $(function () {
QUnit.test('should show tooltip with delegate selector on click', function (assert) {
assert.expect(2)
var done = assert.async()
var $div = $('<div><a href="#" rel="tooltip" title="Another tooltip"/></div>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
@@ -262,11 +305,16 @@ $(function () {
trigger: 'click'
})
$div.find('a').trigger('click')
assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
$div.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
$div.find('a').trigger('click')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip was removed from dom')
done()
})
$div.find('a').trigger('click')
assert.strictEqual($('.tooltip').length, 0, 'tooltip was removed from dom')
})
QUnit.test('should show tooltip when toggle is called', function (assert) {
@@ -292,16 +340,22 @@ $(function () {
QUnit.test('should place tooltips inside body when container is body', function (assert) {
assert.expect(3)
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
var done = assert.async()
$('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ container: 'body' })
.one('shown.bs.tooltip', function () {
assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body')
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom')
done()
})
.bootstrapTooltip('show')
assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body')
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom')
})
QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
@@ -335,49 +389,68 @@ $(function () {
QUnit.test('should use title attribute for tooltip text', function (assert) {
assert.expect(2)
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
var done = assert.async()
$('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
})
QUnit.test('should prefer title attribute over title option', function (assert) {
assert.expect(2)
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
var done = assert.async()
$('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
.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')
$(this).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 $tooltip = $('<a href="#" rel="tooltip"/>')
var done = assert.async()
$('<a href="#" rel="tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
title: 'This is a tooltip with some content'
})
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
.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')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should be placed dynamically to viewport with the dynamic placement option', function (assert) {
assert.expect(6)
var done = assert.async()
var $style = $('<style> div[rel="tooltip"] { position: absolute; } #qunit-fixture { top: inherit; left: inherit } </style>').appendTo('head')
var $container = $('<div/>')
.css({
@@ -390,38 +463,71 @@ $(function () {
.appendTo($container)
.bootstrapTooltip({ placement: 'auto', viewport: '#qunit-fixture' })
$topTooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
var topDone = false
var rightDone = false
var leftDone = false
$topTooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'top positioned tooltip removed from dom')
function isDone() {
if (topDone && rightDone && leftDone) {
$container.remove()
$style.remove()
done()
}
}
var $rightTooltip = $('<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
function leftTooltip() {
var $leftTooltip = $('<div style="left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>')
.appendTo($container)
.bootstrapTooltip({ placement: 'auto left', viewport: '#qunit-fixture' })
$leftTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right')
$leftTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'left positioned tooltip removed from dom')
leftDone = true
isDone()
})
.bootstrapTooltip('show')
}
function rightTooltip() {
var $rightTooltip = $('<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
.appendTo($container)
.bootstrapTooltip({ placement: 'right auto', viewport: '#qunit-fixture' })
$rightTooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left')
$rightTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.in'), 'right positioned tooltip is dynamically positioned left')
$rightTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'right positioned tooltip removed from dom')
rightDone = true
leftTooltip()
})
.bootstrapTooltip('show')
}
$rightTooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'right positioned tooltip removed from dom')
var $leftTooltip = $('<div style="left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>')
.appendTo($container)
.bootstrapTooltip({ placement: 'auto left', viewport: '#qunit-fixture' })
$leftTooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right')
$leftTooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'left positioned tooltip removed from dom')
$container.remove()
$style.remove()
$topTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
$topTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'top positioned tooltip removed from dom')
topDone = true
rightTooltip()
})
.bootstrapTooltip('show')
})
QUnit.test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; padding-top: 50px }'
@@ -437,17 +543,23 @@ $(function () {
viewport: '#section'
})
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should position tip on top if viewport has enough space and is not parent', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#section { height: 300px; border: 1px solid red; margin-top: 100px; }'
+ 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }'
@@ -462,17 +574,23 @@ $(function () {
viewport: '#qunit-fixture'
})
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; }'
@@ -488,17 +606,23 @@ $(function () {
viewport: '#section'
})
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should display the tip on top whenever scrollable viewport has enough room if the given placement is "auto top"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
@@ -515,17 +639,23 @@ $(function () {
$('#scrollable-div').scrollTop(100)
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should display the tip on bottom whenever scrollable viewport doesn\'t have enough room if the given placement is "auto top"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { padding: 200px 0 400px; width: 150px; }'
@@ -542,17 +672,23 @@ $(function () {
$('#scrollable-div').scrollTop(200)
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should display the tip on bottom whenever scrollable viewport has enough room if the given placement is "auto bottom"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.spacer { height: 400px; }'
@@ -573,17 +709,23 @@ $(function () {
$('#scrollable-div').scrollTop(200)
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should display the tip on top whenever scrollable viewport doesn\'t have enough room if the given placement is "auto bottom"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin-top: 400px; width: 150px; }'
@@ -600,17 +742,23 @@ $(function () {
$('#scrollable-div').scrollTop(400)
$target.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s top position when up against the top of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -628,17 +776,23 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
assert.strictEqual(Math.round($container.find('.tooltip').offset().top), 12)
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.strictEqual(Math.round($container.find('.tooltip').offset().top), 12)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s top position when up against the bottom of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -656,19 +810,31 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().top), Math.round($(window).height() - 12 - $tooltip[0].offsetHeight))
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
var padding = 50
var result = Math.round($tooltip.offset().top)
var resultMax = result + padding
var resultMin = result - padding
var expected = Math.round($(window).height() - 12 - $tooltip[0].offsetHeight)
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
assert.ok(expected < resultMax && expected > resultMin)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s left position when up against the left of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -686,18 +852,24 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
assert.strictEqual(Math.round($container.find('.tooltip').offset().left), 12)
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
assert.strictEqual(Math.round($container.find('.tooltip').offset().left), 12)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s left position when up against the right of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -715,19 +887,25 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($(window).width() - 12 - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($(window).width() - 12 - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip when up against the right of an arbitrary viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip, .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ '.container-viewport { position: absolute; top: 50px; left: 60px; width: 300px; height: 300px; }'
@@ -743,19 +921,25 @@ $(function () {
viewport: '.container-viewport'
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should get viewport element from function', function (assert) {
assert.expect(3)
var done = assert.async()
var styles = '<style>'
+ '.tooltip, .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ '.container-viewport { position: absolute; top: 50px; left: 60px; width: 300px; height: 300px; }'
@@ -774,19 +958,25 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not misplace the tip when the right edge offset is greater or equal than the viewport width', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }'
+ '.container-viewport, .container-viewport *, .container-viewport *:before, .container-viewport *:after { box-sizing: border-box; }'
@@ -802,15 +992,21 @@ $(function () {
viewport: '.container-viewport'
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2))
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
var expected = Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2)
var result = Math.round($tooltip.offset().left)
assert.ok(result === (expected - 1) || result === expected)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) {
@@ -1013,6 +1209,11 @@ $(function () {
})
QUnit.test('should wait 200ms before hiding the tooltip', function (assert) {
if (window.__karma__) {
assert.expect(0)
return
}
assert.expect(3)
var done = assert.async()
@@ -1070,6 +1271,9 @@ $(function () {
$styles.remove()
assert.ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location')
$circle.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
@@ -1218,10 +1422,11 @@ $(function () {
QUnit.test('should correctly position tooltips on transformed elements', function (assert) {
var styleProps = document.documentElement.style
if (!('transform' in styleProps) && !('webkitTransform' in styleProps) && !('msTransform' in styleProps)) {
if ((!('transform' in styleProps) && !('webkitTransform' in styleProps) && !('msTransform' in styleProps)) || window.__karma__) {
assert.expect(0)
return
}
assert.expect(2)
var done = assert.async()