[Test Improver] Add unit tests for getFirstFocusableElement in focusTrap composable - #73
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…able Add 16 unit tests covering getFirstFocusableElement from shell/composables/focusTrap.ts: - Returns document.body when no focusable elements exist (including default document parameter) - Identifies all focusable element types: button, anchor, input, textarea, select, details, tabindex >=0 - Excludes elements with tabindex="-1" - Skips disabled elements (button and input) - Returns document.body when all elements are disabled - Returns the first of multiple eligible elements - Returns first non-disabled element when leading elements are disabled 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
getFirstFocusableElementinshell/composables/focusTrap.ts. This function is responsible for finding the first keyboard-focusable element within a container — it is used byuseBasicSetupFocusTrapanduseWatcherBasedSetupFocusTrapWithDestroyIncludedto anchor the focus trap. It had zero test coverage despite containing non-trivial logic:tabindex="-1"elementsdisabledelements from the result setdocument.bodywhen no candidates remainApproach
getFirstFocusableElementin isolation — it is a pure function with no Vue lifecycle hooks or Vuex dependencies, so no component mount is required.document.createElementto build controlled containers for each case.it.eachwith named-object entries (descfield) for the element-type cases to avoid repetition.-1, empty container).Coverage Impact
getFirstFocusableElementgoes from 0% to 100% statement/branch/function coverage.getFirstFocusableElementstatementsgetFirstFocusableElementbranchesTest Cases (16 total)
returns document.body when the container has no focusable elementsreturns document.body when no element argument is provided and document has no focusable elementsreturns the button element(viait.eachover all 8 focusable types)skips a disabled button and returns the next non-disabled focusable elementskips a disabled input and returns the next non-disabled focusable elementreturns document.body when every focusable element is disableddoes not return an element with tabindex="-1"returns the first of multiple focusable elementsreturns the first non-disabled element when leading elements are all disabledTrade-offs
document.createElement,innerHTML) — low maintenance burden.useBasicSetupFocusTrapanduseWatcherBasedSetupFocusTrapWithDestroyIncludedare not tested here; they rely on thefocus-traplibrary and Vue lifecycle hooks and are best tested via component integration tests.Reproducibility
Test Status
✅ All 16 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.