generated from john/python-template
Continue GC code review: UI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Tests for global UI theme registration."""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
@@ -8,6 +9,8 @@ from fastapi import FastAPI
|
||||
from transcription.ui import register_pages
|
||||
from transcription.ui.resources import read_css
|
||||
|
||||
UI_ROOT = Path(__file__).parents[1] / "src" / "transcription" / "ui"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_page_registration_uses_vibescribe_theme(monkeypatch):
|
||||
@@ -35,3 +38,45 @@ def test_page_registration_uses_vibescribe_theme(monkeypatch):
|
||||
}
|
||||
assert "--q-primary" in theme_css
|
||||
assert run_options["dark"] is False
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_theme_is_the_only_ui_stylesheet():
|
||||
stylesheets = sorted(path.relative_to(UI_ROOT).as_posix() for path in UI_ROOT.rglob("*.css"))
|
||||
|
||||
assert stylesheets == ["static/theme.css"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_ui_python_uses_class_driven_theme():
|
||||
prohibited_patterns = {
|
||||
".style(": "inline NiceGUI style",
|
||||
"<style": "embedded style block",
|
||||
"vibe-": "legacy presentation class",
|
||||
}
|
||||
violations: list[str] = []
|
||||
|
||||
for path in sorted((*UI_ROOT.glob("components/**/*.py"), *UI_ROOT.glob("pages/**/*.py"))):
|
||||
source = path.read_text(encoding="utf-8")
|
||||
for pattern, description in prohibited_patterns.items():
|
||||
if pattern in source:
|
||||
violations.append(f"{path.relative_to(UI_ROOT)}: {description}")
|
||||
|
||||
assert violations == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_theme_defines_shared_semantic_surfaces():
|
||||
theme_css = read_css("theme.css")
|
||||
|
||||
for class_name in (
|
||||
"ui-card-surface",
|
||||
"ui-card-error",
|
||||
"ui-form-surface",
|
||||
"ui-table",
|
||||
"ui-chip-primary",
|
||||
"ui-badge-secondary",
|
||||
"ui-status",
|
||||
"document-panzoom-host",
|
||||
):
|
||||
assert f".{class_name}" in theme_css
|
||||
|
||||
Reference in New Issue
Block a user