Skip to content

[Test Improver] Add unit tests for dynamic content notification-handler - #93

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/notification-handler-7b1c2d5da15fea0e
Draft

[Test Improver] Add unit tests for dynamic content notification-handler#93
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/notification-handler-7b1c2d5da15fea0e

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

shell/utils/dynamic-content/notification-handler.ts provides the createHandler factory and the onReadUpdated callback that manages the "read announcements" user preference. This is the core mechanism for tracking which dynamic content announcements a user has already dismissed — a user-facing feature with no existing test coverage.

Approach

15 unit tests covering all branches of onReadUpdated:

Scenario Test
Non-announcement notification ID returns early, no dispatch
Valid announcement, empty pref adds stripped ID, dispatches
Valid announcement, existing pref appends stripped ID, dispatches
Mark as unread removes stripped ID from pref
Remove only entry → empty pref dispatches ''
Re-mark already-read as read deduplicates via Set
Alphabetical sort result is sorted before dispatch
Mark unread, ID not in pref pref unchanged
null pref (same as empty string) handled correctly
Multi-part ID (e.g. release-2.8.0-important) prefix stripped correctly

Coverage Impact

File Before After
notification-handler.ts 0% 100% Statements / Branches / Functions / Lines

Test Commands

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern=shell/utils/dynamic-content/__tests__/notification-handler.test.ts

Test Status

✅ All 15 tests pass, 0 lint 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 · ● 4.9M ·

Add 15 unit tests for createHandler/onReadUpdated in
shell/utils/dynamic-content/notification-handler.ts achieving 100%
statement/branch/function/line coverage.

Tests cover:
- Returns early for non-announcement notification IDs
- Dispatches prefs/set for valid announcement notifications
- Strips ANNOUNCEMENT_PREFIX before storing in pref
- Marks notification as read: adds stripped ID to pref
- Marks notification as unread: removes stripped ID from pref
- Handles empty pref value (no existing entries)
- Deduplicates IDs via Set (no double-entry on re-read)
- Sorts resulting IDs alphabetically before dispatching
- Unread of absent ID leaves pref unchanged
- Handles null pref value (same as empty string)
- Stores multi-part IDs (e.g. release-2.8.0-important) correctly

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