from pathlib import Path

from src.frontend_bundle import build_frontend


ROOT = Path(__file__).parents[1]


def test_dashboard_packages_a_mobile_today_session_handoff():
    build = build_frontend(ROOT / "frontend")
    html = build.dashboard_html
    dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
    css = (ROOT / "frontend" / "dashboard.css").read_text()
    today_bundle = build.feature_bundles["today-timer"].runtime_bytes.decode()

    assert 'id="today-session-handoff"' in html
    assert 'id="continue-today-session"' in html
    assert 'id="today-session-sync-status"' in html
    assert 'aria-live="polite"' in html
    assert "createTodaySessionSync" in today_bundle
    assert "attachTodaySessionHandoff" in today_bundle
    assert "Session syncing…" in today_bundle
    assert "Session offline · will retry." in today_bundle
    assert "Session continued on another device." in today_bundle
    assert "todaySessionSync = attachTodaySessionHandoff" in dashboard
    assert "todaySessionSync?.publish(snapshot)" in dashboard
    assert "min-height:44px" in css
