diff options
| author | Pierre-Denis Vanduynslager <[email protected]> | 2016-12-28 19:57:38 -0500 |
|---|---|---|
| committer | Pierre-Denis Vanduynslager <[email protected]> | 2016-12-28 19:57:38 -0500 |
| commit | 425d156df27fa6c18e979aa000bfe5a346ee3450 (patch) | |
| tree | 4157dfcbdf8334e9d9fb2bb239f4ae78706bbc71 /js/tests/unit/tooltip.js | |
| parent | ab2fc63d08b8c53d6f29bcfd73b7f2d5ceaacacd (diff) | |
| parent | e1e621be046a4541a2fd36e445015ee44de3c67e (diff) | |
| download | bootstrap-425d156df27fa6c18e979aa000bfe5a346ee3450.tar.xz bootstrap-425d156df27fa6c18e979aa000bfe5a346ee3450.zip | |
Merge branch 'twbs/v4-dev' into dropdown-keyboard
Diffstat (limited to 'js/tests/unit/tooltip.js')
| -rw-r--r-- | js/tests/unit/tooltip.js | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 9ec5ddb03..7ff967fab 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1,5 +1,5 @@ $(function () { - 'use strict'; + 'use strict' QUnit.module('tooltip plugin') @@ -111,7 +111,7 @@ $(function () { assert .ok($('.tooltip') - .is('.fade.bs-tether-element-attached-top.bs-tether-element-attached-center.in'), 'has correct classes applied') + .is('.fade.bs-tether-element-attached-top.bs-tether-element-attached-center.show'), 'has correct classes applied') $tooltip.bootstrapTooltip('hide') @@ -185,6 +185,19 @@ $(function () { .bootstrapTooltip('show') }) + QUnit.test('should throw an error when show is called on hidden elements', function (assert) { + assert.expect(1) + var done = assert.async() + + try { + $('<div title="tooltip title" style="display: none"/>').bootstrapTooltip('show') + } + catch (err) { + assert.strictEqual(err.message, 'Please use show on visible elements') + done() + } + }) + QUnit.test('should fire inserted event', function (assert) { assert.expect(2) var done = assert.async() @@ -293,7 +306,7 @@ $(function () { $tooltip.bootstrapTooltip('show') $tooltip.bootstrapTooltip('dispose') - assert.ok(!$tooltip.hasClass('in'), 'tooltip is hidden') + assert.ok(!$tooltip.hasClass('show'), 'tooltip is hidden') assert.ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data') assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo') assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events') @@ -322,7 +335,7 @@ $(function () { .bootstrapTooltip({ trigger: 'manual' }) .bootstrapTooltip('toggle') - assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') + assert.ok($('.tooltip').is('.fade.show'), 'tooltip is faded active') }) QUnit.test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) { @@ -333,7 +346,7 @@ $(function () { .bootstrapTooltip('show') $('.tooltip').bootstrapTooltip('toggle') - assert.ok($('.tooltip').not('.fade.in'), 'tooltip was faded out') + assert.ok($('.tooltip').not('.fade.show'), 'tooltip was faded out') }) QUnit.test('should place tooltips inside body when container is body', function (assert) { @@ -368,8 +381,8 @@ $(function () { var $tooltip = $($target.data('bs.tooltip').tip) - // this is some dumb hack shit because sub pixels in firefox - var top = Math.round($target.offset().top + ($target[0].offsetHeight / 2) - ($tooltip[0].offsetHeight / 2)) + // this is some dumb hack stuff because sub pixels in firefox + var top = Math.round($target.offset().top + $target[0].offsetHeight / 2 - $tooltip[0].offsetHeight / 2) var top2 = Math.round($tooltip.offset().top) var topDiff = top - top2 assert.ok(topDiff <= 1 && topDiff >= -1) @@ -489,11 +502,11 @@ $(function () { .bootstrapTooltip({ delay: 150 }) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '100ms: tooltip is not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip is not faded active') }, 100) setTimeout(function () { - assert.ok($('.tooltip').is('.fade.in'), '200ms: tooltip is faded in') + assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip is faded active') done() }, 200) @@ -509,12 +522,12 @@ $(function () { .bootstrapTooltip({ delay: 150 }) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '100ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') $tooltip.trigger('mouseout') }, 100) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '200ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active') done() }, 200) @@ -527,19 +540,19 @@ $(function () { var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 0, hide: 150 }}) + .bootstrapTooltip({ delay: { show: 0, hide: 150 } }) setTimeout(function () { - assert.ok($('.tooltip').is('.fade.in'), '1ms: tooltip faded in') + assert.ok($('.tooltip').is('.fade.show'), '1ms: tooltip faded active') $tooltip.trigger('mouseout') setTimeout(function () { - assert.ok($('.tooltip').is('.fade.in'), '100ms: tooltip still faded in') + assert.ok($('.tooltip').is('.fade.show'), '100ms: tooltip still faded active') $tooltip.trigger('mouseenter') }, 100) setTimeout(function () { - assert.ok($('.tooltip').is('.fade.in'), '200ms: tooltip still faded in') + assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip still faded active') done() }, 200) }, 0) @@ -556,12 +569,12 @@ $(function () { .bootstrapTooltip({ delay: 150 }) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '100ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') $tooltip.trigger('mouseout') }, 100) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '200ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active') done() }, 200) @@ -574,15 +587,15 @@ $(function () { var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 150, hide: 0 }}) + .bootstrapTooltip({ delay: { show: 150, hide: 0 } }) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '100ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') $tooltip.trigger('mouseout') }, 100) setTimeout(function () { - assert.ok(!$('.tooltip').is('.fade.in'), '250ms: tooltip not faded in') + assert.ok(!$('.tooltip').is('.fade.show'), '250ms: tooltip not faded active') done() }, 250) @@ -595,19 +608,19 @@ $(function () { var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 0, hide: 150 }}) + .bootstrapTooltip({ delay: { show: 0, hide: 150 } }) setTimeout(function () { - assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.in'), '1ms: tooltip faded in') + assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '1ms: tooltip faded active') $tooltip.trigger('mouseout') setTimeout(function () { - assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.in'), '100ms: tooltip still faded in') + assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '100ms: tooltip still faded active') }, 100) setTimeout(function () { - assert.ok(!$($tooltip.data('bs.tooltip').tip).is('.in'), '200ms: tooltip removed') + assert.ok(!$($tooltip.data('bs.tooltip').tip).is('.show'), '200ms: tooltip removed') done() }, 200) @@ -710,10 +723,10 @@ $(function () { $('#tt-outer').trigger('mouseleave') assert.strictEqual(currentUid, $('#tt-content').text()) - assert.ok(obj._hoverState == 'out', 'the tooltip hoverState should be set to "out"') + assert.ok(obj._hoverState === 'out', 'the tooltip hoverState should be set to "out"') $('#tt-outer').trigger('mouseenter') - assert.ok(obj._hoverState == 'in', 'the tooltip hoverState should be set to "in"') + assert.ok(obj._hoverState === 'show', 'the tooltip hoverState should be set to "show"') assert.strictEqual(currentUid, $('#tt-content').text()) }) @@ -775,7 +788,7 @@ $(function () { var tooltip = $el.data('bs.tooltip') var $tooltip = $(tooltip.getTipElement()) - function showingTooltip() { return $tooltip.hasClass('in') || tooltip._hoverState == 'in' } + function showingTooltip() { return $tooltip.hasClass('show') || tooltip._hoverState === 'show' } var tests = [ ['mouseenter', 'mouseleave'], @@ -799,10 +812,31 @@ $(function () { $.each(tests, function (idx, triggers) { for (var i = 0, len = triggers.length; i < len; i++) { - $el.trigger(triggers[i]); - assert.equal(i < (len - 1), showingTooltip()) + $el.trigger(triggers[i]) + assert.equal(i < len - 1, showingTooltip()) } }) }) + QUnit.test('should show on first trigger after hide', function (assert) { + assert.expect(3) + var $el = $('<a href="#" rel="tooltip" title="Test tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ trigger: 'click hover focus', animation: false }) + + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + + function showingTooltip() { return $tooltip.hasClass('show') || tooltip._hoverState === 'show' } + + $el.trigger('click') + assert.ok(showingTooltip(), 'tooltip is faded in') + + $el.bootstrapTooltip('hide') + assert.ok(!showingTooltip(), 'tooltip was faded out') + + $el.trigger('click') + assert.ok(showingTooltip(), 'tooltip is faded in again') + }) + }) |
