From e949505b89ca146e3af0cf735e100c82703f1cda Mon Sep 17 00:00:00 2001 From: Adrien Siami Date: Wed, 25 Mar 2015 14:46:21 +0100 Subject: Allow viewport option to be a function Closes #16151 by merging a rebased version of it that adds docs and 1 more assertion. --- js/tests/unit/tooltip.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 8086631c8..0cb964e9b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -733,6 +733,37 @@ $(function () { $styles.remove() }) + QUnit.test('should get viewport element from function', function (assert) { + assert.expect(3) + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo(document.body) + var $target = $('').appendTo($container) + $target + .bootstrapTooltip({ + placement: 'bottom', + viewport: function ($element) { + assert.strictEqual($element[0], $target[0], 'viewport function was passed target as argument') + return ($element.closest('.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() + }) + QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) { assert.expect(1) var passed = true -- cgit v1.2.3