From b16127fc105f159ebd06b02df2853941b2aba67c Mon Sep 17 00:00:00 2001
From: Johann-S
Date: Thu, 30 Nov 2017 10:54:27 +0100
Subject: Allow Tooltips/Popovers to work in shadow DOM
---
js/tests/unit/util.js | 38 ++++++++++++++++++++++++++++++++++++++
js/tests/visual/tooltip.html | 22 +++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletion(-)
(limited to 'js/tests')
diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js
index 61727304d..2fd6f6b7c 100644
--- a/js/tests/unit/util.js
+++ b/js/tests/unit/util.js
@@ -124,4 +124,42 @@ $(function () {
assert.expect(1)
assert.ok(Util.supportsTransitionEnd())
})
+
+ QUnit.test('Util.findShadowRoot should find the shadow DOM root', function (assert) {
+ // Only for newer browsers
+ if (!document.documentElement.attachShadow) {
+ assert.expect(0)
+ return
+ }
+
+ assert.expect(2)
+ var $div = $('').appendTo($('#qunit-fixture'))
+ var shadowRoot = $div[0].attachShadow({
+ mode: 'open'
+ })
+ console.warn($div[0].attachShadow, shadowRoot)
+
+ assert.equal(shadowRoot, Util.findShadowRoot(shadowRoot))
+ shadowRoot.innerHTML = ''
+ assert.equal(shadowRoot, Util.findShadowRoot(shadowRoot.firstChild))
+ })
+
+ QUnit.test('Util.findShadowRoot should return null when attachShadow is not available', function (assert) {
+ assert.expect(1)
+
+ var $div = $('').appendTo($('#qunit-fixture'))
+ if (!document.documentElement.attachShadow) {
+ assert.equal(null, Util.findShadowRoot($div[0]))
+ } else {
+ var sandbox = sinon.createSandbox()
+
+ sandbox.replace(document.documentElement, 'attachShadow', function () {
+ // to avoid empty function
+ return $div
+ })
+
+ assert.equal(null, Util.findShadowRoot($div[0]))
+ sandbox.restore()
+ }
+ })
})
diff --git a/js/tests/visual/tooltip.html b/js/tests/visual/tooltip.html
index 436f5c1cd..831f26d0a 100644
--- a/js/tests/visual/tooltip.html
+++ b/js/tests/visual/tooltip.html
@@ -62,7 +62,12 @@
-
+
@@ -72,6 +77,21 @@