"""Teste US-001 + US-002 (PRD 5.3): Light/Dark mode comutator tema. TDD: testele se scriu INAINTE de implementare (RED), dupa implementare trec (GREEN). """ from __future__ import annotations import os import re import tempfile from pathlib import Path import pytest from starlette.testclient import TestClient @pytest.fixture() def client(monkeypatch): tmp = tempfile.mkdtemp() monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "tema.db")) from app.config import get_settings get_settings.cache_clear() from app.main import app with TestClient(app) as c: yield c get_settings.cache_clear() def _create_user(email: str = "tema@test.com", password: str = "parolasecreta"): from app.accounts import create_account from app.users import create_user from app.db import get_connection conn = get_connection() try: acct_id = create_account(conn, "Service Tema", active=True) create_user(conn, acct_id, email, password) return acct_id finally: conn.close() def _login(client, email: str, password: str = "parolasecreta") -> None: resp = client.get("/login") m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text) or \ re.search(r'value="([^"]+)"\s+name="csrf_token"', resp.text) assert m, "csrf_token negasit in /login" resp = client.post( "/login", data={"email": email, "parola": password, "csrf_token": m.group(1)}, follow_redirects=False, ) assert resp.status_code == 303, f"Login esuat: {resp.status_code}" # ── US-001: Tema light ───────────────────────────────────────────────────────── def test_paleta_light_definita(client): """HTML de la GET /login contine un selector [data-theme="light"] care redefineste cel putin --bg, --card, --ink, --muted, --line.""" resp = client.get("/login") assert resp.status_code == 200 html = resp.text assert '[data-theme="light"]' in html, 'Lipseste blocul [data-theme="light"] in HTML' light_block = re.search(r'\[data-theme=["\']light["\']\]\s*\{([^}]+)\}', html, re.DOTALL) assert light_block, 'Nu am gasit blocul CSS [data-theme="light"] { ... }' block = light_block.group(1) for var in ("--bg", "--card", "--ink", "--muted", "--line"): assert var in block, f"Variabila {var} lipseste din blocul [data-theme=\"light\"]" def test_dark_ramane_default(client): """:root contine paleta dark exacta: --bg:#0f1218, --card:#181c24, --ink:#e6e9ef. Valorile actualizate la US-013 (PRD 5.10) conform DESIGN.md (accent azur ROMFAST). """ resp = client.get("/login") assert resp.status_code == 200 html = resp.text assert "--bg:#0f1218" in html, "Paleta dark --bg:#0f1218 a fost modificata sau stearsa" assert "--card:#181c24" in html, "Paleta dark --card:#181c24 a fost modificata sau stearsa" assert "--ink:#e6e9ef" in html, "Paleta dark --ink:#e6e9ef a fost modificata sau stearsa" def test_suprafete_fara_fundal_hardcodat(client): """', resp.text, re.DOTALL) assert style_match, "