Skip to content

[Test Improver] Add unit tests for prefs store - #136

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/prefs-store-tests-7814f19457c317e3
Draft

[Test Improver] Add unit tests for prefs store#136
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/prefs-store-tests-7814f19457c317e3

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

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

Goal and Rationale

shell/store/prefs.js is the core user-preferences Vuex store for Rancher Dashboard. It had no existing unit tests and contains non-trivial logic:

  • getters.theme: strips legacy ui- prefix, resolves auto using the prefers-color-scheme cookie, falls back to 'dark', and lets a management setting override everything
  • getters.afterLoginRoute: 6-branch switch that converts a string pref ('home', 'last-visited', '<cluster>-dashboard', or any other name) into a Vue Router location object, consulting authRedirect state and other prefs
  • getters.get/getters.options/getters.defaultValue: throw typed errors for unknown keys; all return clones (important for Vue reactivity)
  • mutations.reset: clears non-cookie prefs, preserving cookie-backed ones
  • actions.setLastVisited: conditional — only tracks the last page when the after-login-route pref is 'last-visited'

Approach

All functions are unit-tested by calling them directly without a real Vuex store — the same pattern used throughout shell/store/__tests__/. Getters receive a constructed state + mocked inner-getter; mutations and actions receive the state directly.

Coverage Impact

Metric Before After (file)
Statements 0 ~75% of prefs.js
Branches 0 ~85% of prefs.js
Functions 0 ~80% of prefs.js

Tests Added (35 total)

getters.get (4): unknown-key throw, user-set value, default fallback, clone isolation for objects

getters.defaultValue (3): unknown-key throw, returns default, clone isolation for arrays

getters.options (4): unknown-key throw, no-options throw, correct array returned, clone isolation

getters.theme (6): management setting override, direct theme, ui- prefix stripped, auto→pcs light, auto→pcs dark, auto→dark when pcs empty

getters.afterLoginRoute (7): non-string passthrough, 'home' route, 'last-visited'+authRedirect, 'last-visited'+stored last-visited, 'last-visited' fallback to cluster explorer, 'my-cluster-dashboard' pattern, arbitrary string default

getters.dev (2): returns PLUGIN_DEVELOPER value, falls back to DEV on throw

mutations (7): load, cookiesLoaded, reset clears non-cookies, reset preserves cookies (LOCALE, PREFERS_SCHEME), setDefinition, setAuthRedirect

actions.setLastVisited (3): falsy route early-return, non-last-visited pref early-return, dispatches set when pref is 'last-visited'

Trade-offs

  • loadServer and set actions are not tested here — they require a running Vuex store (dispatch with root modules) and are better covered by integration tests.
  • loadTheme uses window.matchMedia and setTimeout which require more involved mocking.

Reproducibility

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci shell/store/__tests__/prefs.test.ts

Test Status

✅ 35/35 tests pass
✅ ESLint: no warnings

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 ·

35 unit tests covering:
- getters.get: unknown-key throw, user value, default value, clone isolation
- getters.defaultValue: unknown-key throw, default value, clone isolation for arrays
- getters.options: unknown-key throw, no-options throw, options copy, clone isolation
- getters.theme: management override, direct theme, ui- prefix stripping, auto+pcs, auto fallback to dark
- getters.afterLoginRoute: non-string passthrough, home, last-visited with authRedirect, last-visited with stored pref, last-visited fallback to cluster explorer, cluster-dashboard pattern, arbitrary string
- getters.dev: PLUGIN_DEVELOPER value, DEV fallback on throw
- mutations.load, cookiesLoaded, reset (cookie preservation), setDefinition, setAuthRedirect
- actions.setLastVisited: falsy route, non-last-visited pref, dispatch on last-visited

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