""" Step 10 — PWA Finalization & Polish tests. Tests manifest presence and validity, service worker registration, icon availability, and install prompt absence in test environment. """ import json import pytest def test_manifest_link_present(page, app_url): """HTML page includes a pointing to /manifest.json.""" page.goto(app_url) handle = page.query_selector('link[rel="manifest"]') assert handle is not None, " not found in
" href = handle.get_attribute("href") assert href == "/manifest.json", f"Unexpected manifest href: {href}" def test_manifest_json_valid(page, app_url): """manifest.json is reachable, valid JSON, and has required PWA fields.""" response = page.request.get(f"{app_url}/manifest.json") assert response.status == 200, f"manifest.json returned {response.status}" manifest = json.loads(response.text()) assert manifest.get("name"), "manifest missing 'name'" assert manifest.get("display") == "standalone", "manifest display should be 'standalone'" icons = manifest.get("icons", []) assert len(icons) >= 2, "manifest should declare at least 2 icons" sizes = {icon["sizes"] for icon in icons} assert "192x192" in sizes, "192x192 icon missing from manifest" assert "512x512" in sizes, "512x512 icon missing from manifest" def test_icon_192_accessible(page, app_url): """icon-192.png is served with a 200 status.""" response = page.request.get(f"{app_url}/icon-192.png") assert response.status == 200, f"icon-192.png returned {response.status}" def test_icon_512_accessible(page, app_url): """icon-512.png is served with a 200 status.""" response = page.request.get(f"{app_url}/icon-512.png") assert response.status == 200, f"icon-512.png returned {response.status}" def test_service_worker_registered(page, app_url): """Service worker is registered in the browser after page load.""" page.goto(app_url) page.wait_for_selector('[data-testid="db-loading"]', state="detached", timeout=15000) registration = page.evaluate( "() => navigator.serviceWorker.getRegistration().then(r => !!r)" ) assert registration, "No service worker registration found" def test_install_prompt_hidden_by_default(page, app_url): """Install prompt button is not shown in the test environment (beforeinstallprompt not fired).""" page.goto(app_url) page.wait_for_selector('[data-testid="db-loading"]', state="detached", timeout=15000) btn = page.query_selector('[data-testid="install-prompt-btn"]') assert btn is None, "Install prompt button should not appear without beforeinstallprompt" def test_favicon_linked(page, app_url): """HTML page includes a for the favicon.""" page.goto(app_url) handle = page.query_selector('link[rel="icon"]') assert handle is not None, " not found in " def test_apple_touch_icon_linked(page, app_url): """HTML page includes a .""" page.goto(app_url) handle = page.query_selector('link[rel="apple-touch-icon"]') assert handle is not None, " not found in " def test_nav_has_aria_label(page, app_url): """Main navigation has an aria-label for screen readers.""" page.goto(app_url) page.wait_for_selector('[data-testid="db-loading"]', state="detached", timeout=15000) nav = page.query_selector("nav.navbar") assert nav is not None, "