"""The kit's snippets, the chrome, and the rules the estate agreed to. This module used to be copied into every service. It lives here now; a service keeps only the part that lists its own pages. """ from __future__ import annotations import re from pathlib import Path import pytest from django.template.loader import render_to_string from django.test import Client from yksa_web.states import STATES ROOT = Path(__file__).resolve().parent.parent / "yksa_web" TEMPLATES = sorted((ROOT / "templates").rglob("*.html")) STYLESHEETS = [ROOT / "static" / "yksa" / "css" / "kit.css"] # --- the chrome ------------------------------------------------------------- @pytest.mark.django_db def test_the_shared_pages_render(): client = Client() for url in ("/preferences/timezone/", "/privacy/", "/cookies/"): assert client.get(url).status_code == 200, url @pytest.mark.django_db def test_the_navbar_and_footer_are_on_every_page(): """Both are stated requirements, and both were hand-copied before this.""" html = Client().get("/privacy/").content.decode() assert "custom-navbar" in html assert "yksa/img/logo-full-en.svg" in html assert 'href="/cookies/"' in html # footer link assert "yksa/css/kit.css" in html @pytest.mark.django_db def test_the_service_cannot_reorder_the_chrome(): """navbar, then main, then footer — a service that wants otherwise has to stop extending the kit, which is the point.""" html = Client().get("/privacy/").content.decode() assert html.index(" str: return re.sub(r"/\*.*?\*/", "", css, flags=re.S) def test_no_legacy_text_muted(): """Deprecated in Bootstrap 5.3. Muted text is text-body-secondary.""" assert [str(p) for p in TEMPLATES if "text-muted" in p.read_text(encoding="utf-8")] == [] def test_no_display_classes(): """`.display-*` is a marketing scale; headings take `.h1`-`.h6`.""" offenders = [ str(p) for p in TEMPLATES if re.search(r"\bdisplay-[1-6]\b", p.read_text(encoding="utf-8")) ] assert offenders == [] def test_no_django_comment_syntax(): """`{# #}` breaks across edits and leaks into rendered output.""" assert [str(p) for p in TEMPLATES if "{#" in p.read_text(encoding="utf-8")] == [] def test_bootstrap_is_at_least_5_3(): """text-body-secondary and --bs-*-bg-subtle arrived in 5.3. On 5.2.3 every rule above passes and the page still renders wrong, which is what happened across the estate before this package owned the bundle.""" bundle = ROOT / "static" / "yksa" / "css" / "bootstrap.min.css" assert "--bs-success-bg-subtle" in bundle.read_text(encoding="utf-8")