Skip to content

[Test Improver] Add unit tests for useDragHandler composable - #100

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-drag-handler-9b67867118b6112a
Draft

[Test Improver] Add unit tests for useDragHandler composable#100
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/use-drag-handler-9b67867118b6112a

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/components/nav/WindowManager/composables/useDragHandler.ts handles all drag-and-drop tab positioning in the Window Manager — a critical interactive feature. It had zero test coverage. The composable has real branching logic (CENTER guards, shared module-level state, dataTransfer encoding) that benefits from targeted testing.

Approach

  • Mocked vuex (useStore) to return a controllable store with state.wm.lockedPositions and state.wm.userPin
  • Created a makeDragEvent helper to simulate DragEvent with dataTransfer and preventDefault mocks
  • Reset shared module-level refs (dragOverPositionsActive, pinArea) in beforeEach to prevent test pollution
  • Verified the shared-state guarantee explicitly (two instances share the same dragOverPositionsActive and pinArea refs)

Tests (31 total)

Group Tests
initial state dragOverPositionsActive/dragOverTabBarActive/pinArea defaults
lockedPositions empty array; populated from store
lockedPosition no-prop → false; not in list → false; in list → true
pin computed getter reads userPin; setter commits (non-CENTER) / skips (CENTER)
onDragPositionStart dataTransfer JSON, dragOverPositionsActive=true, dragOverTabBarActive=true
onDragPositionOver pinArea update; preventDefault for non-CENTER; no preventDefault for CENTER
onDragPositionEnd setUserPin commit; switchTab commit (non-CENTER); no switchTab (CENTER); flag reset
onTabBarDragOver dragOverTabBarActive=true; preventDefault
onTabBarDragLeave dragOverTabBarActive=false
onTabBarDrop commit switchTab; reset flag; warn on empty data; no commit on empty data
shared module state dragOverPositionsActive and pinArea are same ref across instances

Coverage Impact

The composable was previously untested (0% coverage). After this PR it reaches 100% statement/branch/function coverage for useDragHandler.ts.

Test Status

31/31 tests pass (yarn test:ci --testPathPattern=useDragHandler)
ESLint clean (eslint --max-warnings 0)

Reproducibility

NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern=useDragHandler

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 · ● 3.9M ·

31 unit tests covering the drag-and-drop tab composable:
- initial state (dragOverPositionsActive, dragOverTabBarActive, pinArea)
- lockedPositions computed — store state passthrough
- lockedPosition computed — position membership check
- pin computed getter/setter (CENTER guard on commit)
- onDragPositionStart — dataTransfer encoding, shared flags
- onDragPositionOver — pinArea update, conditional preventDefault
- onDragPositionEnd — setUserPin, switchTab, flag reset
- onTabBarDragOver / onTabBarDragLeave — dragOverTabBarActive toggle
- onTabBarDrop — commit wm/switchTab, missing-data warn path
- shared module-level refs verified across instances

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