Skip to content

Commit 948a746

Browse files
committed
Merge pull request twbs#14299 from twbs/fix-14076
Add unit test for tooltips on SVG elements
2 parents de1d8c3 + 08393bf commit 948a746

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

js/tests/unit/tooltip.js

+36
Original file line numberDiff line numberDiff line change
@@ -739,4 +739,40 @@ $(function () {
739739
$tooltip.trigger('mouseenter')
740740
})
741741

742+
test('should correctly position tooltips on SVG elements', function () {
743+
if (!window.SVGElement) {
744+
// Skip IE8 since it doesn't support SVG
745+
expect(0)
746+
return
747+
}
748+
749+
stop()
750+
751+
var styles = '<style>'
752+
+ '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }'
753+
+ '.tooltip { position: absolute; }'
754+
+ '.tooltip .tooltip-inner { width: 24px; height: 24px; font-family: Helvetica; }'
755+
+ '</style>'
756+
var $styles = $(styles).appendTo('head')
757+
758+
$('#qunit-fixture').append(
759+
'<div style="position: fixed; top: 0; left: 0;">'
760+
+ ' <svg width="200" height="200">'
761+
+ ' <circle cx="100" cy="100" r="10" title="m" id="theCircle" />'
762+
+ ' </svg>'
763+
+ '</div>')
764+
var $circle = $('#theCircle')
765+
766+
$circle
767+
.on('shown.bs.tooltip', function () {
768+
var offset = $('.tooltip').offset()
769+
$styles.remove()
770+
ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location')
771+
start()
772+
})
773+
.bootstrapTooltip({ container: 'body', placement: 'top', trigger: 'manual' })
774+
775+
$circle.bootstrapTooltip('show')
776+
})
777+
742778
})

0 commit comments

Comments
 (0)