Skip to content

[Test Improver] Add unit tests for useDrawer composable - #105

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-drawer-composable-1115cbd437f0997f
Draft

[Test Improver] Add unit tests for useDrawer composable#105
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-drawer-composable-1115cbd437f0997f

Conversation

@github-actions

Copy link
Copy Markdown

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.

Goal and Rationale

shell/composables/drawer.ts (the useDrawer composable) had no test coverage. It wraps slideInPanel Vuex store commits with a typed API for opening/closing drawer panels, and has non-trivial invariant behavior worth validating:

  • open() always sets triggerFocusTrap: true regardless of what the caller passes in options
  • open() always uses the returnFocusSelector argument, even if options includes a conflicting value
  • Options properties are spread before the invariants, meaning the invariants cannot be accidentally overridden by callers

These properties are important for accessibility (focus trap) and focus-return correctness.

Approach

  • Mocked vuex.useStore to return a spy commit function
  • Called useDrawer() directly (no Vue lifecycle hooks to trigger)
  • Used toHaveBeenCalledWith with exact payload shapes for strong assertions
  • 7 tests covering: no-options call, options merging, triggerFocusTrap invariant, returnFocusSelector invariant, empty options, close behaviour, and payload arity

Coverage Impact

File Before After
shell/composables/drawer.ts 0% 100%

Test Status

PASS shell/composables/drawer.test.ts
Tests: 7 passed, 7 total

Reproducibility

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern=shell/composables/drawer.test.ts

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 4.2M ·

7 unit tests covering the open() and close() functions
of the useDrawer composable:

- open() without options: correct payload shape
- open() with extra options: options merged into componentProps
- open() always sets triggerFocusTrap=true regardless of options
- open() returnFocusSelector argument always wins over options
- open() with empty {} same as no options
- close() commits 'slideInPanel/close'
- close() passes no additional payload

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants