Files
TieMeasureFlow/src/frontend/flask_app/tests/test_layout_shell.py
T
2026-10-07 13:46:27 +02:00

75 lines
3.1 KiB
Python

"""Point 14: the frame must not move when the operator changes view.
The report was «le dimensioni delle viste cambiano a seconda del menu». On the
code it was seven different page widths across seventeen templates, none of them
the width of the navbar sitting above them, plus a scrollbar that came and went.
This test guards the part that is easy to undo: the next page someone writes will
copy the shell from a neighbour, and if a neighbour has gone back to declaring its
own `container mx-auto ... max-w-5xl` the drift starts again.
"""
from pathlib import Path
import pytest
TEMPLATES = Path(__file__).resolve().parents[1] / "templates"
# Two views own their geometry on purpose, and say why here so that a reader does
# not have to guess whether they were forgotten:
# login — a full-viewport splash, no navbar to line up with;
# task_execute — the measurement screen, a fixed full-height instrument panel
# that must not scroll while an operator is measuring.
EXEMPT = {"auth/login.html", "measure/task_execute.html"}
# What a page must not go back to doing: setting its own width and padding.
FORBIDDEN = ("container mx-auto", "max-w-2xl mx-auto", "max-w-3xl mx-auto",
"max-w-4xl mx-auto", "max-w-5xl mx-auto", "max-w-6xl mx-auto",
"max-w-7xl mx-auto")
def _views():
for path in sorted(TEMPLATES.rglob("*.html")):
rel = path.relative_to(TEMPLATES).as_posix()
if rel.startswith("components/") or rel == "base.html":
continue
# #65: i parziali (nome che comincia per "_") sono inclusi da un'altra vista
# e stanno dentro la sua cornice .tmf-page: da soli non ne hanno una.
if path.name.startswith("_"):
continue
yield rel, path
def test_every_view_uses_the_shared_shell():
"""One frame, declared in one place, so it cannot drift per page."""
missing = [
rel for rel, path in _views()
if rel not in EXEMPT and "tmf-page" not in path.read_text(encoding="utf-8")
]
assert not missing, f"viste senza la cornice condivisa: {missing}"
@pytest.mark.parametrize("rel,path", list(_views()))
def test_no_view_declares_its_own_width(rel, path):
if rel in EXEMPT:
pytest.skip("geometria propria, documentata in EXEMPT")
html = path.read_text(encoding="utf-8")
found = [f for f in FORBIDDEN if f in html]
assert not found, (
f"{rel} torna a dichiarare la propria larghezza ({found}): "
"usare .tmf-page / .tmf-page-narrow"
)
def test_the_shell_matches_the_navbar():
"""The content lines up with the bar above it, or the page looks like it has
two widths at once - which is what the operator was seeing."""
navbar = (TEMPLATES / "components/navbar.html").read_text(encoding="utf-8")
assert "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8" in navbar, (
"la navbar ha cambiato cornice: allineare .tmf-page in themes.css"
)
css = (
TEMPLATES.parent / "static/css/themes.css"
).read_text(encoding="utf-8")
assert "max-width: 80rem;" in css # 80rem == max-w-7xl
assert "scrollbar-gutter: stable;" in css