[Test Improver] Add unit tests for prefs store - #136
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
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>
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
shell/store/prefs.jsis the core user-preferences Vuex store for Rancher Dashboard. It had no existing unit tests and contains non-trivial logic:getters.theme: strips legacyui-prefix, resolvesautousing theprefers-color-schemecookie, falls back to'dark', and lets a management setting override everythinggetters.afterLoginRoute: 6-branch switch that converts a string pref ('home','last-visited','<cluster>-dashboard', or any other name) into a Vue Router location object, consultingauthRedirectstate and other prefsgetters.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 onesactions.setLastVisited: conditional — only tracks the last page when theafter-login-routepref 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
Tests Added (35 total)
getters.get(4): unknown-key throw, user-set value, default fallback, clone isolation for objectsgetters.defaultValue(3): unknown-key throw, returns default, clone isolation for arraysgetters.options(4): unknown-key throw, no-options throw, correct array returned, clone isolationgetters.theme(6): management setting override, direct theme,ui-prefix stripped,auto→pcs light,auto→pcs dark,auto→dark when pcs emptygetters.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 defaultgetters.dev(2): returns PLUGIN_DEVELOPER value, falls back to DEV on throwmutations (7):
load,cookiesLoaded,resetclears non-cookies,resetpreserves cookies (LOCALE, PREFERS_SCHEME),setDefinition,setAuthRedirectactions.setLastVisited(3): falsy route early-return, non-last-visited pref early-return, dispatchessetwhen pref is'last-visited'Trade-offs
loadServerandsetactions are not tested here — they require a running Vuex store (dispatchwith root modules) and are better covered by integration tests.loadThemeuseswindow.matchMediaandsetTimeoutwhich require more involved mocking.Reproducibility
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.ioSee Network Configuration for more information.