Files
transcription/tests/test_ui_theme.py
T

83 lines
2.4 KiB
Python

"""Tests for global UI theme registration."""
import re
from pathlib import Path
import pytest
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):
"""Global UI registration loads the standalone VibeScribe theme in light mode."""
registered_css: list[str] = []
run_options: dict[str, object] = {}
monkeypatch.setattr("transcription.ui.ui.add_css", lambda css, **_kwargs: registered_css.append(css))
monkeypatch.setattr("transcription.ui.register_jobs_page", lambda: None)
monkeypatch.setattr(
"transcription.ui.ui.run_with",
lambda _app, **options: run_options.update(options),
)
register_pages(FastAPI())
theme_css = read_css("theme.css")
assert registered_css == [theme_css]
assert set(re.findall(r"#[0-9a-fA-F]{6}", theme_css)) == {
"#1c2321",
"#7d98a1",
"#5e6572",
"#a9b4c2",
"#eef1ef",
}
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