Skip to content

[Test Improver] Add unit tests for addReleaseNotesNotification utility - #41

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/release-notes-util-fe981a869b8051c0
Draft

[Test Improver] Add unit tests for addReleaseNotesNotification utility#41
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/release-notes-util-fe981a869b8051c0

Conversation

@github-actions

Copy link
Copy Markdown

🤖 Test Improver — automated AI assistant

Goal and Rationale

shell/utils/release-notes.ts contains addReleaseNotesNotification, an async function that manages "What's New" release-note notifications in the Rancher Notification Centre. It had zero test coverage despite containing several meaningful branches:

Branch Description
found = true Current-version notification already in store — skip add
lastReadVersion === rancherVersion User already read this version — skip add
Old-prefix notification Dispatch notifications/remove for stale entries
Prefix match + old version Remove old, then add current
Version suffix stripping 2.11.0-rc12.11.0 via .split('-')[0]

Approach

  • New test file: shell/utils/__tests__/release-notes.test.ts (11 tests)
  • Mocks getVersionData and READ_WHATS_NEW; all other collaborators (getters, dispatch) are inline mocks — no Vuex store mounting needed
  • Each test case targets exactly one branch or behaviour
  • Covers both happy paths (add fired) and guard conditions (add suppressed)

Coverage Impact

Before: release-notes.ts had 0% unit test coverage.
After: All conditional branches in addReleaseNotesNotification are exercised by the 11 tests.

Trade-offs

  • dispatch is mocked as jest.fn().mockResolvedValue(undefined) — no real Vuex store overhead
  • The i18n/t mock returns the translation key as-is; tests only assert structure, not translated strings

Reproducibility

yarn test:ci shell/utils/__tests__/release-notes.test.ts

Test Status

✅ 11/11 tests pass
eslint --max-warnings 0 passes

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

11 tests covering all branches in addReleaseNotesNotification:
- dispatches notifications/add when not found and not previously read
- skips notifications/add when current version already exists in store
- skips notifications/add when version already read via preference
- dispatches notifications/remove for older release-notes notification
- dispatches both remove and add for correct transition
- skips add when version was read even after removing old notification
- ignores non-release-notes notifications (no remove, still adds)
- verifies full notification structure (level, preference, primaryAction)
- strips pre-release suffix from version string (e.g. 2.11.0-rc1 → 2.11.0)
- handles co-existing old and current version notifications
- makes no dispatch calls when list empty and version already read

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