[Test Improver] Add unit tests for useClickOutside composable - #77
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[Test Improver] Add unit tests for useClickOutside composable#77github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Cover the key behaviours of useClickOutside: - Lifecycle: click and pointerdown listeners registered on mount, deregistered on unmount (it.each for both events) - Click handler: callback called for outside click; not called when click target equals or is inside the component element; not called when component.value is null; no throw when callback is non-function - Ignore option (CSS selector): callback suppressed after a pointerdown on a selector-matched element; callback fires when pointerdown is on a non-ignored element outside the component - Pointerdown inside component: drag-inside-then-click-outside does not fire callback (setShouldListen guard) - Keyboard click (detail=0): callback suppressed when the click event target matches an ignore selector 13 tests total; all pass with 0 ESLint warnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 tasks
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.
Goal and Rationale
Add unit tests for
shell/composables/useClickOutside.ts. This composable manages DOM click-outside detection — it registersclickandpointerdownlisteners onwindowto call a callback when the user clicks outside a given element.It had zero test coverage despite containing non-trivial logic:
ignoreoption supporting CSS selectors to suppress callbacks from specific elements (e.g. dropdown overlays, modal backdrops)pointerdownguard that prevents drag-from-inside-to-outside from falsely triggering the callback (setShouldListen)detail === 0) that setsshouldListenviashouldIgnoreto respect the ignore list for keyboard-triggered clicksApproach
@vue/test-utilsmountwith a minimaldefineComponentwrapper to trigger theonMounted/onBeforeUnmountlifecycle hooks naturallywindow.addEventListener/window.removeEventListenerwithmockImplementationto capture the handlers without altering DOM behaviourtarget,composedPath,detail) to exercise the listener logic in isolationit.eachwith named-object entries for the lifecycle registration/deregistration testsCoverage Impact
useClickOutsidestatementsuseClickOutsidebranchesTest Cases (13 total)
Lifecycle (×2 for click + pointerdown):
registers the click/pointerdown event listener on mountremoves the click/pointerdown event listener on unmountClick listener:
calls callback when click target is outside the component elementdoes not call callback when click target is the component elementdoes not call callback when the composedPath of the click includes the component elementdoes not call callback when component.value is nulldoes not throw when callback is not a functionIgnore option:
suppresses callback when a prior pointerdown targeted a css-selector-matched ignore elementcalls callback when pointerdown targets a non-ignored element outside the componentPointerdown inside component:
does not call callback when pointerdown was inside the component and click was outsideKeyboard click (detail=0):
does not call callback when detail is 0 and click event target matches an ignore selectorTrade-offs
window.addEventListenerto capture handlers — this avoids JSDOMcomposedPath()limitations on real events and keeps tests deterministicuseBasicSetupFocusTrapanduseWatcherBasedSetupFocusTrapWithDestroyIncluded(which use this composable) are not tested here; those require component-level integration testsReproducibility
Test Status
✅ All 13 new tests pass
✅ All 42 existing composable tests continue to pass
✅ ESLint: no warnings or errors
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
download.cypress.ioSee Network Configuration for more information.