Add a Popover API shim to the Jest DOM shims
What does this MR do and why?
Adds a small Popover API shim to our Jest DOM shims (spec/frontend/__helpers__/dom_shims/popover.js), ahead of time and as a no-op for now.
Why now, when nothing uses it?
The upcoming GlTooltip in @gitlab/ui is built on the native Popover API: gitlab-org/gitlab-services/design.gitlab.com!6294 (merged). jsdom, which runs our frontend specs, doesn't implement that API (https://github.com/jsdom/jsdom/issues/3721), so specs that render the new GlTooltip for real (without the global @gitlab/ui mock) would throw.
The @gitlab/ui upgrade has to come with this shim. It's tested in the integration branch (!255018), which carries exactly this commit. Merging the shim separately keeps that upgrade small and reviewable. It's one of several prep MRs, after !262798 (merged).
What the shim does
It behaves like the shim in @gitlab/ui's own specs:
showPopover(),hidePopover()andtogglePopover()track the open state in adata-popover-openattribute and dispatchtoggleevents.- Repeated calls are ignored, and elements without a
popoverattribute throwNotSupportedError, as in browsers. togglePopover()returns whether the popover is now open.
Two deliberate differences:
- It also answers
matches(':popover-open'). The jsdom version here (20) doesn't throw on that selector, it always returnsfalse. Without the patch,GlTooltipwould consider every tooltip closed and never hide it.@gitlab/ui's specs run jsdom 26, where the selector throws andGlTooltipfalls back todata-popover-open. - It doesn't define the
popoverproperty. Vue 3 sets an attribute as a DOM property when the element has one, so defining it would stoppopover="manual"from rendering as an attribute in the Vue 3 specs.
Like the other jsdom shims, it lives in dom_shims, which both jest and jest-integration load. spec/frontend/__helpers__/dom_shims/popover_spec.js covers it.
Why it's a no-op today
- Nothing in
app,ee/app, our specs or templates calls the Popover API or renders apopoverattribute. TheshowPopover/hidePopovernames that exist are Vue component methods, not DOM calls. - The current
@gitlab/ui, including its vendored bootstrap-vue, doesn't use it. - The only dependency loaded in specs that touches it is
@floating-ui/dom, which callselement.matches(':popover-open'). That still returnsfalse, because nothing is ever shown through the shim.
Checked locally on master:
- I ran 202 spec files with and without the shim: sidebar, super sidebar, filtered search, diffs components, tooltips, user popover and cycle analytics components. Every test result was identical, in both Vue versions (3538 results with Vue 2, 3385 with Vue 3). The failures in those runs were identical too, and come from my local setup (missing generated fixtures, plus local Vue 3 issues).
- In the integration branch, with the new
GlTooltip, the real component and directive renderpopover="manual"in both Vue versions, and show, hide and hover work.
No production code changes.
References
- GitLab UI MR (new
GlTooltip): gitlab-org/gitlab-services/design.gitlab.com!6294 (merged) - GitLab UI's own Popover API shim:
packages/gitlab-ui/tests/__helpers__/popover_api_shim.jsin that MR - Integration MR: !255018
- Previous prep MR (feature spec selectors): !262798 (merged)
- jsdom issue: https://github.com/jsdom/jsdom/issues/3721
How to set up and validate locally
yarn jest spec/frontend/__helpers__/dom_shims/popover_spec.js
VUE_VERSION=3 yarn jest spec/frontend/__helpers__/dom_shims/popover_spec.jsThe full Jest pipeline of this MR is the real check that nothing else changes.