Files
TimeTracker/tests/test_service_worker.py
T
Dries Peeters 8fc823c252 feat(pwa): static manifest, root-scoped worker, offline fallback
Add app/static/manifest.json (TimeTracker / Tracker, indigo theme) and PNG install icons via scripts/generate_pwa_icons.py.

Replace inline Flask service worker with app/static/js/sw.js served at /service-worker.js for full-site scope. Cache name timetracker-v1: cache-first for /static, network-first for HTML and non-v1 /api, no interception of /api/v1/* (preserves Authorization).

Add public GET /offline and offline.html for SW navigation fallback; redirect /manifest.webmanifest to the static manifest.

Wire base.html (manifest link, theme-color #4F46E5, SW registration) and pwa-enhancements.js (ready/update/push without duplicate registration). Remove legacy app/static/service-worker.js and manifest.webmanifest.

Tests: service worker and offline routes, manifest redirect, TestPWA expectations; drop duplicate test_enhanced_ui app/client fixtures in favor of conftest.

Docs: ASSETS.md, BUILD_CONFIGURATION.md, implementation notes, and incomplete-features analysis updated for new paths.
2026-04-27 18:43:14 +02:00

21 lines
772 B
Python

def test_service_worker_serves_sw_js(client):
resp = client.get("/service-worker.js")
assert resp.status_code == 200
text = resp.get_data(as_text=True)
assert "application/javascript" in (resp.headers.get("Content-Type") or "")
assert "const CACHE_NAME = 'timetracker-v1'" in text
def test_manifest_legacy_redirect(client):
resp = client.get("/manifest.webmanifest", follow_redirects=False)
assert resp.status_code == 302
assert "/static/manifest.json" in resp.headers.get("Location", "")
def test_offline_page_public(client):
resp = client.get("/offline")
assert resp.status_code == 200
body = resp.get_data(as_text=True)
assert "timer is still running on the server" in body
assert "Cache-Control" in resp.headers