Skip to content

[Test Improver] Add unit tests for ui-context store - #61

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/ui-context-store-1402a3567d662899
Draft

[Test Improver] Add unit tests for ui-context store#61
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/ui-context-store-1402a3567d662899

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/ui-context.ts. This store manages UI context elements (tag-based overlays/annotations). It had zero test coverage despite containing meaningful validation logic in its actions.

Key testable logic:

  • actions.add: throws on invalid context (undefined value, falsy tag, null), auto-increments idCounter, generates sequential ctx-N ids
  • actions.update/remove: throw when element id not found in state
  • getters.all: sorts contexts alphabetically by tag (empty tags sort first)
  • mutations.update: silently no-ops for missing element id

Approach

  • Tested state() factory, all 3 mutations, the getters.all getter, and all 3 actions
  • Used it.each with named-object entries for the 4 invalid-context throw cases
  • Avoided testing trivial pass-through behaviour; focused on validation, sorting, and commit calls

Coverage Impact

File Before After
shell/store/ui-context.ts 0% ~100% statements

Trade-offs

  • Tests use as any casts in a few places because the Element.id TypeScript interface says number but the runtime code assigns string values ('ctx-0'). The type discrepancy is in the source, not the tests.
  • No mocking required — pure functions tested directly.

Reproducibility

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

Test Status

✅ 22 tests passing, 0 failing
✅ ESLint: no warnings or errors

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

22 tests covering state factory, getters.all (sorting by tag, edge
cases), mutations (add, update no-op for missing id, remove), and
actions (add validation for invalid context, sequential id generation,
idCounter increments; update/remove throw for missing elements and
call correct commits).

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