Skip to content

[Test Improver] Add unit tests for wm store (window manager) - #57

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/wm-store-00d3bfe1992bda4f
Draft

[Test Improver] Add unit tests for wm store (window manager)#57
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/wm-store-00d3bfe1992bda4f

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

Add unit tests for shell/store/wm.ts — the Vuex store powering the window manager panel (tabs, positions, pinning, dimensions). This store has zero existing test coverage despite containing complex, conditional logic for:

  • Tab deduplication and default-value injection on addTab
  • Position fallback from localStorage (pin key) when no position is supplied
  • Forced-BOTTOM pinning when lockedPositions is set
  • Multi-tab active-state reconciliation on switchTab and closeTab
  • localStorage persistence for panel dimensions and pin preferences
  • Guard-throw semantics on both open and close actions

Approach

Direct mutation/getter/action calls against a plain state object — no full Vuex store needed, matching the pattern used in cookies.test.ts and catalog.test.ts.

window.localStorage is replaced with a per-test in-memory mock (same pattern as dynamic-content/__tests__/index.test.ts) so setItem/getItem calls can be asserted without touching disk state.

Layout const-enum values are referenced as their underlying string literals ('default', 'home') to avoid isolatedModules const-enum inlining issues at test time.

Coverage Impact

Metric Before After (wm.ts only)
wm.ts — statements 0 % ~100 %
wm.ts — branches 0 % ~95 %
wm.ts — functions 0 % 100 %

58 new tests, zero pre-existing tests modified.

Trade-offs

  • Tests call mutations/getters directly rather than through createStore. This is intentional: it keeps tests fast, focused, and free of Vuex plumbing noise. The store module's logic is self-contained.
  • The state() factory's localStorage.getItem calls are exercised by the localStorage mock — no special initialisation tricks required.

Reproducibility

# Run just this test file
YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern="shell/store/__tests__/wm.test.ts"

# Run the full suite
yarn test:ci

Test Status

✅ 58 / 58 tests pass
✅ ESLint clean (--max-warnings 0)
✅ No pre-existing tests broken

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.3M ·

Cover state factory, getters, mutations, and actions for the
window manager Vuex store:

- state factory: reads panelHeight/panelWidth from localStorage on
  initialisation, defaults tabs/active/open/lockedPositions to empty
  collections, userPin to null
- getters: byId (hit/miss), tabs, isOpen, panelWidth, panelHeight,
  userPin, lockedPositions
- mutations.addTab: deduplication, position fallback (localStorage pin /
  BOTTOM), lockedPositions forced BOTTOM, default layouts/showHeader,
  active+open+userPin state updates, localStorage.setItem
- mutations.switchTab: position move, target-position active/open update,
  old-position cleanup (no remaining tabs → active='' + open=false),
  remaining tab promoted to active, userPin + localStorage.setItem
- mutations.closeTab: removal, active-tab promotion, open cleared when
  no remaining tabs, early return for non-existent id
- mutations.removeTab: simple removal and no-op for unknown tab
- mutations.setOpen/setActive: setter correctness
- mutations.setPanelHeight/setPanelWidth: value update, localStorage
  persistence, containerHeight/containerWidth propagation to tabs
- mutations.setUserPin/setLockedPositions: state + localStorage side effects
- actions.close: throws on missing id, commits closeTab
- actions.open: throws on missing tab.id, commits addTab

58 tests total, all passing. ESLint clean.

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