import re import subprocess import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] HTML = (ROOT / "templates" / "index.html").read_text(encoding="utf-8") JS = (ROOT / "static" / "js" / "app.js").read_text(encoding="utf-8") CSS = (ROOT / "static" / "css" / "style.css").read_text(encoding="utf-8") class FrontendContractTests(unittest.TestCase): def test_stable_dom_ids_exist_once(self): required = { "nav-dashboard", "nav-alerts", "nav-hosts", "nav-config", "sysStatus", "lastScan", "mOk", "mSize", "mLatest", "mLatestHost", "mWarn", "mWarnCard", "clusterList", "liveStream", "chartSvg", "hostGrid", "alertList", "drawer", "drawerBg", "drawerTitle", "drawerBody", "modal", "modalBg", "hostForm", "formMode", "formName", "formKumaUrl", "formEnabled", "toasts", } for element_id in required: count = len(re.findall(rf'id=["\']{re.escape(element_id)}["\']', HTML)) self.assertEqual(count, 1, f"#{element_id} must exist exactly once") def test_uses_local_styles_without_runtime_css_framework(self): self.assertIn('/static/css/style.css', HTML) self.assertNotIn('cdn.tailwindcss.com', HTML) self.assertNotIn('Material+Symbols', HTML) self.assertNotIn('backdrop-blur', HTML) self.assertNotIn('pulse-', HTML) def test_monitor_surface_has_semantic_landmarks_and_accessible_actions(self): self.assertRegex(HTML, r']+aria-label="Hauptnavigation"') self.assertIn('