46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import re
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
HTML_PATH = Path(__file__).resolve().parents[2] / "docs" / "design" / "brain" / "index.html"
|
|
|
|
|
|
class UIContractTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls) -> None:
|
|
cls.html = HTML_PATH.read_text(encoding="utf-8")
|
|
|
|
def test_prototype_is_self_contained_and_labels_fixture_truthfully(self) -> None:
|
|
self.assertIn("合成回放不等于模型效果", self.html)
|
|
self.assertIn("离线 HTML 原型数据", self.html)
|
|
self.assertNotRegex(self.html, r'(?:src|href)=["\']https?://')
|
|
self.assertNotIn("@import url", self.html)
|
|
|
|
def test_accessibility_and_responsive_guards_are_present(self) -> None:
|
|
required = (
|
|
'name="viewport"',
|
|
'class="skip-link"',
|
|
'aria-live="polite"',
|
|
':focus-visible',
|
|
'prefers-reduced-motion',
|
|
'min-height: 44px',
|
|
'@media (max-width: 420px)',
|
|
'.toolbar { display: grid; grid-template-columns: 1fr; }',
|
|
'键盘用户可使用右侧坐标表单',
|
|
)
|
|
for marker in required:
|
|
with self.subTest(marker=marker):
|
|
self.assertIn(marker, self.html)
|
|
|
|
def test_no_structural_emoji_or_unescaped_secret_placeholder_in_text(self) -> None:
|
|
visible_without_script = re.sub(r"<script[\s\S]*?</script>", "", self.html)
|
|
self.assertNotRegex(visible_without_script, r"[\U0001F300-\U0001FAFF]")
|
|
self.assertEqual(self.html.count("__BRAIN_DEMO_TOKEN__"), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|