Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add unit tests for the notification-settings persistence module (webui) #3

Description

@TKMD

Labels: good first issue, area:webui, area:testing
Difficulty: S (~1–3 hours)

Context

apps/webui/src/ui/notification-settings.ts persists the cockpit's notification
preferences to localStorage and is deliberately defensive: SSR, a missing
localStorage, and corrupt stored values must all degrade to the all-off default.
That coercion logic currently has no test coverage at all (no test file references the
module), so a refactor could silently break the safe-degradation behavior.

What to do

  1. Read apps/webui/src/ui/notification-settings.ts (70 lines). Public surface:
    defaultNotificationSettings(), readNotificationSettings(),
    persistNotificationSettings(); internal coerceCategories().
  2. Create apps/webui/test/notification-settings.test.ts. The webui test suite runs in
    a plain node environment (apps/webui/vitest.config.ts:16), so stub
    window.localStorage with a small in-memory object — copy the pattern from
    apps/webui/test/policy-cache.test.ts:28-51 (MemStorage + globalThis.window stub).
  3. Cover at least:
    • no window (SSR path) → defaults, no throw
    • empty storage → defaults
    • round-trip: persistNotificationSettings(s) then readNotificationSettings()s
    • corrupt JSON / non-object JSON ("42", "[]") → defaults
    • enabled present but not strictly true (1, "yes") → false
    • categories with unknown extra keys → dropped; non-true values → false
    • getItem / setItem throwing (private-mode simulation) → no throw, safe fallback

Acceptance criteria

  • New test file passes: pnpm --filter @actradeck/webui test
  • All bullets above are asserted (not just the happy path).
  • No production code changes needed. If you find an actual bug while testing, report it
    in the issue thread instead of folding a behavior change into the test PR.
  • Full gate green: pnpm type-check && pnpm lint && pnpm format && pnpm test

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions