from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
JS = ROOT / "scripts/health/assets/health-assets/dashboard-v5-api-explorer.js"
CSS = ROOT / "scripts/health/assets/health-assets/dashboard-v5.css"


def test_explorer_has_explicit_series_states_and_abort_guards():
    source = JS.read_text(encoding="utf-8")
    for state in ("loading", "visible", "hidden", "empty", "failed"):
        assert state in source
    assert "new AbortController()" in source
    assert "metricRequestVersions.get(metric.id)!==requestVersion" in source
    assert "selected.includes(metric)" in source
    assert "retryFailedMetrics" in source
    assert "shown.length - failedById.size" not in source


def test_event_categories_are_text_and_icon_identifiable():
    source = JS.read_text(encoding="utf-8")
    for label in (
        "Symptome/Beschwerden", "Medikamente", "Ernährung", "Training",
        "Sauna/Erholung", "Labor", "Termine", "Dokumente", "Weitere Ereignisse",
    ):
        assert label in source
    assert "event-marker-tooltip" in source
    assert "api-explorer-event-detail" in source
    assert "Tag öffnen" in source and "Details öffnen" in source


def test_today_layout_does_not_force_midword_breaks_or_equal_height_rows():
    source = CSS.read_text(encoding="utf-8")
    assert "repeat(auto-fit, minmax(min(100%, 280px), 1fr))" in source
    assert ".today-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--v5-space-3); align-items: start; }" in source
    assert ".today-nutrition-card, .today-completeness-card { grid-column: span 6; }" in source
    assert "overflow-wrap: normal; word-break: normal; hyphens: none" in source
