Skip to content

[Test Improver] Add unit tests for notifications store actions - #53

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/notifications-store-actions-c24bfa543ee61ed7
Draft

[Test Improver] Add unit tests for notifications store actions#53
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/notifications-store-actions-c24bfa543ee61ed7

Conversation

@github-actions

Copy link
Copy Markdown

🤖 Test Improver — automated AI assistant

Goal and Rationale

shell/store/notifications.ts already has a pending PR (#40) covering mutations and getters. The actions layer (markRead, markUnread, markAllRead, and init) had zero test coverage despite containing meaningful branching logic:

  • markRead / markUnread: conditional prefs/set dispatch and extension handler invocation
  • markUnread: unsetValue fallback to empty string when unset
  • markAllRead: iterates over all notifications, dispatching prefs and invoking handlers for each
  • init: 7 distinct code paths — missing user data early returns, deriveKey failure, happy path (empty + non-empty localStorage), expired-notification filtering, per-notification decrypt failure, BroadcastChannel message filtering by userId

Approach

  • Mocked @shell/utils/crypto/encryption (deriveKey, decrypt, encrypt) to avoid SubtleCrypto unavailability in jsdom
  • Mocked @shell/utils/crypto (md5) for deterministic hash output
  • Mocked BroadcastChannel globally per test to isolate module-level bc state
  • Tested actions in isolation by calling them directly with mock context objects (no full Vuex store wiring needed)
  • Used .call({ $extension: mockExtension }, ...) to inject the this.$extension context required by callNotifyHandler

Coverage Impact

File Coverage added
shell/store/notifications.ts (actions) markRead, markUnread, markAllRead, init — all major branches

Test Status

✅ All 20 new tests pass
✅ ESLint clean (--max-warnings 0)

Reproducibility

NODE_OPTIONS=--max_old_space_size=8192 ./node_modules/.bin/jest shell/store/__tests__/notifications-actions.test.ts

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

Cover markRead, markUnread, markAllRead, and init actions with 20
new tests. Key branches exercised:

- markRead/markUnread: commit path, prefs/set dispatch (with and
  without unsetValue), extension handler invocation (read=true/false)
- markAllRead: no-pref/handler case, multi-notification prefs
  dispatch, multi-notification handler invocation
- init: early-return on missing userKey/userId, early-return on
  deriveKey failure, full happy path (empty and non-empty localStorage),
  expired-notification filtering, per-notification decrypt failure,
  BroadcastChannel onmessage with matching and non-matching userId

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