Skip to content

test: add unit tests for service worker registration (registerOfflineServiceWorker.ts) - #204

Open
Laks04 wants to merge 20 commits into
vicharanashala:mainfrom
Laks04:test/bookmark-toggle
Open

Laks04 wants to merge 20 commits into
vicharanashala:mainfrom
Laks04:test/bookmark-toggle

Conversation

@Laks04

@Laks04 Laks04 commented Aug 3, 2026 •

Copy link
Copy Markdown

⚠️ Note: This PR's tests target code from #169 (Offline Mode), which is
not yet merged into main. CI will fail until #169 merges — this is
expected, not a bug in this PR. Once #169 lands, this will pass cleanly
against main.

What changed
Adds a new test file covering registerOfflineServiceWorker.ts — the
flag-gated service worker registration/unregistration logic introduced
in #169. No existing files are modified; this only adds test coverage
that the Offline Mode report itself flagged as missing ("No automated
tests were added for the new code... in this first iteration").

Related issue
Refs #162
Refs #169

Type of change

  • Tests

Area affected

  • Frontend (React / Vite)

CI verification

  • Run locally: npx vitest run — 7/7 passing
  • One test initially failed (afterEach cleanup left a stale caches
    property on window, leaking into the next test); fixed by deleting
    the property instead of reassigning it when the original was
    undefined
  • Tests added for previously untested code
  • Single logical change — no existing files touched, addition only

Notes for reviewer
Individual contribution within the Offline Mode team project (#169).

shlokjangid606 and others added 17 commits July 17, 2026 07:10
Adds the offlineMode flag to both the backend registry and its
required frontend mirror, following the existing pattern used by
goldenTicket and askAiChatbot. Defaults to false; category is
experimental, which was previously defined in the type but unused.

Refs vicharanashala#162
Configures vite-plugin-pwa with manual service worker registration
(injectRegister: false) so nothing registers unless the offlineMode
flag is on. Caches FAQ content and program-context endpoints
(batches, feature-flags) via Workbox StaleWhileRevalidate, since the
FAQ page can't render without knowing the active program even when
the FAQ data itself is cached.

skipWaiting/clientsClaim are enabled so a newly-installed worker
takes over immediately instead of waiting for all tabs to close.

Refs vicharanashala#162
OfflineModeManager is a headless component mounted inside
FeatureFlagProvider that watches the offlineMode flag's live value
and enables/disables the service worker accordingly — including
unregistering it and clearing its caches if the flag is turned off
after being on, rather than just leaving a dormant worker behind.

Refs vicharanashala#162
Adds /offline, gated by FeatureGate like other experimental
features (e.g. /golden). Shows live connection status, whether the
service worker is active, how many FAQ pages are cached, and an
install button using the beforeinstallprompt event.

Refs vicharanashala#162
apps/frontend/dev-dist/ is generated by devOptions when running
pnpm dev with the PWA plugin enabled. dist/ was already ignored;
dev-dist/ wasn't.

Refs vicharanashala#162
…t-fix

fix(lint): remove unused vars in scripts, bootstrap, config
@Laks04 Laks04 changed the title test: add unit tests for bookmark toggle/get test: add unit tests for service worker registration (registerServiceWorker.ts) Aug 3, 2026
@Laks04
Laks04 force-pushed the test/bookmark-toggle branch from 170be79 to df90197 Compare September 3, 2026 13:26
@Laks04 Laks04 changed the title test: add unit tests for service worker registration (registerServiceWorker.ts) test: add unit tests for service worker registration (registerOfflineServiceWorker.ts) Sep 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants