diff options
| author | Johann-S <[email protected]> | 2018-12-05 10:25:00 +0100 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2018-12-05 10:57:02 +0100 |
| commit | 37f74c70702c4e90e12f062e63358cb64670eb01 (patch) | |
| tree | b51bfab62ae869cef3502b79319888866bdcd2ba /js/tests | |
| parent | 1a171b80ab1b46f59cfd727a7e5f8a10fc43b189 (diff) | |
| download | bootstrap-37f74c70702c4e90e12f062e63358cb64670eb01.tar.xz bootstrap-37f74c70702c4e90e12f062e63358cb64670eb01.zip | |
fix regression about using element for tooltip container option
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/unit/tooltip.js | 46 | ||||
| -rw-r--r-- | js/tests/visual/tooltip.html | 10 |
2 files changed, 54 insertions, 2 deletions
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 7652d4cf8..289f8aebf 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -414,6 +414,52 @@ $(function () { .bootstrapTooltip('show') }) + QUnit.test('should place tooltips inside a specific container when container is an element', function (assert) { + assert.expect(3) + var done = assert.async() + var $container = $('<div></div>').appendTo('#qunit-fixture') + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + container: $container[0] + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.strictEqual($container.find('.tooltip').length, 1) + assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should place tooltips inside a specific container when container is a selector', function (assert) { + assert.expect(3) + var done = assert.async() + var $container = $('<div id="container"></div>').appendTo('#qunit-fixture') + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + container: '#container' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.strictEqual($container.find('.tooltip').length, 1) + assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($container.find('.tooltip').length, 0, 'tooltip was removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) { assert.expect(2) var done = assert.async() diff --git a/js/tests/visual/tooltip.html b/js/tests/visual/tooltip.html index 8759f3dcd..436f5c1cd 100644 --- a/js/tests/visual/tooltip.html +++ b/js/tests/visual/tooltip.html @@ -51,8 +51,11 @@ <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with XSS" data-container="<img src=1 onerror=alert(123) />"> Tooltip with XSS </button> - <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with container" data-container="#customContainer"> - Tooltip with container + <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip with container (selector)" data-container="#customContainer"> + Tooltip with container (selector) + </button> + <button id="tooltipElement" type="button" class="btn btn-secondary" data-placement="left" title="Tooltip with container (element)"> + Tooltip with container (element) </button> <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>"> Tooltip with HTML @@ -70,6 +73,9 @@ <script> $(function () { $('[data-toggle="tooltip"]').tooltip() + $('#tooltipElement').tooltip({ + container: $('#customContainer')[0] + }) $('#target').tooltip({ placement : 'top', trigger : 'manual' |
