feat(web): dashboard ergonomic cu tab-uri, stepper import si microcopy uman (3.4)
Reorganizeaza interfata web pe trei principii, fara a atinge backend-ul de trimitere (worker, mapping, idempotency, masina de stari neatinse): - US-001 app/web/labels.py: modul pur stari tehnice -> text uman + clasa CSS - US-002 bara status /_fragments/status: microcopy uman, defalcare blocate, scoped cont - US-003 shell 6 tab-uri (Acasa/Import/Coada/Mapari/Cont/Nomenclator): deep-link ?tab=, panou activ randat server-side, fragmente inactive lazy, ARIA real - US-004 stepper import 4 pasi (pur vizual; hx-target + csrf pastrate) - US-005 Acasa onboarding checklist auto-bifat + colaps + empty states prietenoase Reparat in cursul VERIFY/CLOSE: izolare teste (reset ratelimit._hits in fixturi), regresie avertisment "cont in asteptare de activare" (re-introdus in bara status), culori hardcodate -> variabile paleta. 434 teste pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
145
tests/test_web_labels.py
Normal file
145
tests/test_web_labels.py
Normal file
@@ -0,0 +1,145 @@
|
||||
"""
|
||||
Teste pentru app/web/labels.py — modul de etichete umane (US-001, PRD 3.4).
|
||||
|
||||
Ordinea: RED (scrise inainte de implementare), apoi GREEN dupa creare labels.py.
|
||||
"""
|
||||
|
||||
import re
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Utilitara: extrage starile din CHECK constraint in schema.sql
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _starile_din_schema() -> list[str]:
|
||||
"""
|
||||
Parseaza `app/schema.sql` si returneaza lista starilor din CHECK constraint
|
||||
al coloanei `status` din tabela `submissions`.
|
||||
|
||||
Linia relevanta (schema.sql, tabela submissions):
|
||||
CHECK (status IN ('queued','sending','sent','needs_mapping','needs_data','error'))
|
||||
|
||||
Testul devine automat RED daca cineva adauga o stare noua in schema
|
||||
fara s-o mapeze in labels.py.
|
||||
"""
|
||||
schema_path = Path(__file__).parent.parent / "app" / "schema.sql"
|
||||
sql = schema_path.read_text(encoding="utf-8")
|
||||
|
||||
# Cauta blocul CHECK aferent coloanei status din CREATE TABLE submissions.
|
||||
# Pattern: CHECK (status IN ('a','b',...)) pe una sau mai multe linii.
|
||||
match = re.search(
|
||||
r"CHECK\s*\(\s*status\s+IN\s*\(([^)]+)\)\s*\)",
|
||||
sql,
|
||||
)
|
||||
assert match, "Nu am gasit CHECK (status IN (...)) in schema.sql — schema s-a schimbat?"
|
||||
|
||||
raw = match.group(1)
|
||||
# Extrage valorile dintre ghilimele simple
|
||||
stari = re.findall(r"'([^']+)'", raw)
|
||||
assert stari, "Lista de stari din CHECK este goala — ceva s-a stricat la parsare."
|
||||
return stari
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Import modulul de etichete (va esua la RED, inainte de implementare)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
from app.web.labels import eticheta_stare, eticheta_worker, eticheta_rar # noqa: E402
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Teste worker
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_eticheta_worker_viu():
|
||||
text, subtext, css_class = eticheta_worker(viu=True)
|
||||
assert "Trimitere automata" in text, (
|
||||
f"Textul pentru worker viu trebuie sa contina 'Trimitere automata', got: {text!r}"
|
||||
)
|
||||
assert "activa" in text.lower() or "activa" in subtext.lower(), (
|
||||
f"Starea 'activa' trebuie sa apara in text sau subtext, got: text={text!r}, subtext={subtext!r}"
|
||||
)
|
||||
# Nu trebuie sa afiseze cuvintele tehnice brute
|
||||
assert "viu" not in text.lower(), f"Textul nu trebuie sa contina 'viu': {text!r}"
|
||||
# Clasa CSS trebuie sa fie definita (non-vida)
|
||||
assert css_class, "css_class nu trebuie sa fie vida pentru worker viu"
|
||||
|
||||
|
||||
def test_eticheta_worker_mort():
|
||||
text, subtext, css_class = eticheta_worker(viu=False)
|
||||
assert "Trimitere automata" in text, (
|
||||
f"Textul pentru worker mort trebuie sa contina 'Trimitere automata', got: {text!r}"
|
||||
)
|
||||
assert "oprita" in text.lower() or "oprita" in subtext.lower(), (
|
||||
f"Starea 'oprita' trebuie sa apara in text sau subtext, got: text={text!r}, subtext={subtext!r}"
|
||||
)
|
||||
assert "mort" not in text.lower(), f"Textul nu trebuie sa contina 'mort': {text!r}"
|
||||
assert css_class, "css_class nu trebuie sa fie vida pentru worker mort"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Teste eticheta_rar
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_eticheta_rar_ok():
|
||||
text, subtext, css_class = eticheta_rar(stare="ok")
|
||||
assert "Legatura cu RAR" in text, f"got: {text!r}"
|
||||
assert "functionala" in text.lower() or "functionala" in subtext.lower()
|
||||
assert css_class
|
||||
|
||||
|
||||
def test_eticheta_rar_indisponibil():
|
||||
text, subtext, css_class = eticheta_rar(stare="indisponibil")
|
||||
assert "Legatura cu RAR" in text, f"got: {text!r}"
|
||||
assert "indisponibila" in text.lower() or "indisponibila" in subtext.lower()
|
||||
assert css_class
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Test eticheta_stare pentru fiecare stare de submission
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_eticheta_stare_submission():
|
||||
"""Verifica textele umane concrete pentru fiecare stare cunoscuta."""
|
||||
cazuri = {
|
||||
"queued": ("In asteptare", "s-queued"),
|
||||
"sent": ("Declarate la RAR", "s-sent"),
|
||||
"sending": ("Se trimite", "s-sending"),
|
||||
"needs_mapping": ("Lipseste codul", "s-needs_mapping"),
|
||||
"needs_data": ("Date incomplete", "s-needs_data"),
|
||||
"error": ("Eroare", "s-error"),
|
||||
}
|
||||
for status, (fragment_text, clasa) in cazuri.items():
|
||||
text, subtext, css_class = eticheta_stare(status)
|
||||
assert fragment_text.lower() in text.lower(), (
|
||||
f"Status {status!r}: asteptam '{fragment_text}' in text, got {text!r}"
|
||||
)
|
||||
assert css_class == clasa, (
|
||||
f"Status {status!r}: asteptam css_class={clasa!r}, got {css_class!r}"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Test parametrizat: TOATE starile din schema au eticheta (anti-drift)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_STARI_SCHEMA = _starile_din_schema()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status", _STARI_SCHEMA)
|
||||
def test_toate_starile_au_eticheta(status: str):
|
||||
"""
|
||||
Fiecare stare din CHECK constraint (schema.sql) trebuie sa aiba o eticheta
|
||||
non-vida si o clasa CSS non-vida in labels.py.
|
||||
|
||||
Daca cineva adauga o stare noua in schema fara s-o mapeze, acest test devine RED.
|
||||
"""
|
||||
text, subtext, css_class = eticheta_stare(status)
|
||||
assert text, f"Status {status!r}: textul etichetei este vid."
|
||||
assert css_class, f"Status {status!r}: clasa CSS este vida."
|
||||
# Textul nu trebuie sa fie chiar statusul tehnic brut (ex. "queued" afisat ca atare)
|
||||
assert text.lower() != status.lower(), (
|
||||
f"Status {status!r}: eticheta umana este identica cu statusul tehnic — nu e o eticheta umana."
|
||||
)
|
||||
Reference in New Issue
Block a user