Skip to content

[Test Improver] Add unit tests for modal store mutations - #45

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/modal-store-mutations-0be72dd21d5d8e18
Draft

[Test Improver] Add unit tests for modal store mutations#45
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/modal-store-mutations-0be72dd21d5d8e18

Conversation

@github-actions

Copy link
Copy Markdown

🤖 Test Improver — automated AI assistant

Goal and Rationale

shell/store/modal.ts manages the global modal dialog state used across the entire Rancher Dashboard UI. It had zero test coverage despite containing non-trivial logic:

  • resources normalization: array → kept as-is, truthy non-array → [value], falsy → []
  • Nullish-coalescing defaults for closeOnClickOutside and modalSticky
  • Falsy-fallback defaults for componentProps and modalWidth

These are real decision branches — bugs here could cause modals to open with wrong resources, wrong width, or wrong stickiness.

Approach

  • Directly import state, mutations from the store module (no Vuex store needed)
  • Reset state via makeState() in beforeEach to keep tests isolated
  • Table-driven it.each for the 5-case resources normalisation
  • Individual it() for each default and explicit-value case
  • closeModal tests verify full state reset

Coverage Impact

File Stmts Branch Funcs Lines
Before 0 % 0 % 0 % 0 %
After 100 % 100 % 30 % 100 %

Function coverage is 30 % because the seven trivial getter pass-throughs ((state) => state.X) are intentionally not tested (see Guidelines: "What NOT to Test").

Test Status

PASS shell/store/__tests__/modal.test.ts
Tests: 23 passed, 23 total
ESLint: 0 warnings, 0 errors

Reproducibility

# run tests
NODE_OPTIONS=--max_old_space_size=8192 node_modules/.bin/jest --no-coverage shell/store/__tests__/modal.test.ts

# lint
node_modules/.bin/eslint --max-warnings 0 shell/store/__tests__/modal.test.ts

Trade-offs

  • Test file is self-contained and straightforward — low maintenance burden
  • Getters are trivially simple (state => state.x) and not tested per project guidelines

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

23 tests covering openModal and closeModal mutations in
shell/store/modal.ts:

- openModal: isOpen flag, component storage (markRaw),
  componentProps default, resources normalisation (array / single
  object / null / undefined / empty array), closeOnClickOutside
  default/explicit, modalWidth default/explicit, modalSticky
  default/explicit
- closeModal: full state reset to initial defaults
- state: initial values verified
- namespaced: confirms module is namespaced

100 % statement, branch, and line coverage for modal.ts.

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