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:
212
tests/test_web_tabs.py
Normal file
212
tests/test_web_tabs.py
Normal file
@@ -0,0 +1,212 @@
|
||||
"""Teste US-003 (PRD 3.4): navigare cu tab-uri (shell dashboard).
|
||||
|
||||
TDD: testele se scriu INAINTE de implementare; la inceput pica (RED),
|
||||
dupa implementare trec (GREEN).
|
||||
|
||||
Rute testate:
|
||||
- GET / -> dashboard cu tab-bar si panou activ randat server-side
|
||||
- GET /?tab=<name> -> deep-link, panoul corespunzator randat server-side
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
|
||||
def _create_account_user(email: str = "tabs@test.com", password: str = "parolasecreta10"):
|
||||
"""Creeaza cont + user. Intoarce (acct_id, user_id)."""
|
||||
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 Test Tabs", active=True)
|
||||
user_id = create_user(conn, acct_id, email, password)
|
||||
return acct_id, user_id
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _login(client, email: str, password: str) -> None:
|
||||
"""Face login real prin HTTP si seteaza cookie-ul de sesiune pe client."""
|
||||
resp = client.get("/login")
|
||||
assert resp.status_code == 200
|
||||
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text)
|
||||
if not m:
|
||||
m = re.search(r'value="([^"]+)"\s+name="csrf_token"', resp.text)
|
||||
assert m, "csrf_token negasit pe /login"
|
||||
csrf = m.group(1)
|
||||
|
||||
resp = client.post("/login", data={
|
||||
"email": email,
|
||||
"parola": password,
|
||||
"csrf_token": csrf,
|
||||
})
|
||||
assert resp.status_code == 303, f"Login esuat: {resp.status_code} {resp.text[:200]}"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(monkeypatch):
|
||||
"""Client cu BD izolata si autentificare web activata."""
|
||||
tmp = tempfile.mkdtemp()
|
||||
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "tabs_test.db"))
|
||||
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "true")
|
||||
from app.config import get_settings
|
||||
get_settings.cache_clear()
|
||||
from app.web import ratelimit
|
||||
ratelimit._hits.clear() # izolare: limiterul login e global in-proces
|
||||
from app.main import app
|
||||
with TestClient(app, follow_redirects=False) as c:
|
||||
yield c
|
||||
ratelimit._hits.clear()
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_dashboard_are_tabbar
|
||||
# ============================================================
|
||||
|
||||
def test_dashboard_are_tabbar(client):
|
||||
"""Dashboard-ul contine un tab-bar cu cele 6 tab-uri."""
|
||||
_create_account_user("tabbar@test.com", "parolasecreta10")
|
||||
_login(client, "tabbar@test.com", "parolasecreta10")
|
||||
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
assert 'role="tablist"' in html, "Lipseste role=tablist"
|
||||
|
||||
# Cele 6 tab-uri trebuie sa fie prezente
|
||||
for label in ("Acasa", "Import", "Coada", "Mapari", "Cont", "Nomenclator"):
|
||||
assert label in html, f"Lipseste tab-ul '{label}' din tab-bar"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_tab_implicit_acasa
|
||||
# ============================================================
|
||||
|
||||
def test_tab_implicit_acasa(client):
|
||||
"""Fara ?tab=, tab-ul Acasa are aria-selected=true."""
|
||||
_create_account_user("implicit@test.com", "parolasecreta10")
|
||||
_login(client, "implicit@test.com", "parolasecreta10")
|
||||
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
# Tab-ul activ trebuie sa aiba aria-selected="true"
|
||||
assert 'aria-selected="true"' in html, "Lipseste aria-selected=true pe tab-ul activ"
|
||||
|
||||
# Verificam ca Acasa e cel cu aria-selected=true
|
||||
# Cautam un fragment care contine atat Acasa cat si aria-selected="true" in proximitate
|
||||
assert re.search(r'aria-selected="true"[^>]*>.*?Acasa|Acasa.*?aria-selected="true"', html, re.DOTALL), \
|
||||
"Tab-ul Acasa nu are aria-selected=true"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_deeplink_tab_import
|
||||
# ============================================================
|
||||
|
||||
def test_deeplink_tab_import(client):
|
||||
"""/?tab=import randeaza panoul Import server-side la full load."""
|
||||
_create_account_user("deeplink@test.com", "parolasecreta10")
|
||||
_login(client, "deeplink@test.com", "parolasecreta10")
|
||||
|
||||
resp = client.get("/?tab=import")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
# Panoul Import trebuie sa contina id="import-section" (din _upload.html)
|
||||
assert 'id="import-section"' in html, (
|
||||
"Panoul Import nu contine id='import-section' la full load cu ?tab=import"
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_tab_activ_randat_server_side
|
||||
# ============================================================
|
||||
|
||||
def test_tab_activ_randat_server_side(client):
|
||||
"""Panoul activ e in HTML-ul initial, nu doar cerut prin HTMX dupa load."""
|
||||
_create_account_user("serverside@test.com", "parolasecreta10")
|
||||
_login(client, "serverside@test.com", "parolasecreta10")
|
||||
|
||||
# Tab-ul implicit (Acasa) trebuie sa fie randat server-side
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
# Panoul trebuie sa aiba role="tabpanel"
|
||||
assert 'role="tabpanel"' in html, "Lipseste role=tabpanel in HTML initial"
|
||||
|
||||
# Import tab server-side
|
||||
resp2 = client.get("/?tab=import")
|
||||
assert resp2.status_code == 200
|
||||
html2 = resp2.text
|
||||
# Continutul Import trebuie sa fie randat direct, nu prin hx-trigger=load pe panoul inactiv
|
||||
assert 'id="import-section"' in html2, "Panoul Import nu e randat server-side la ?tab=import"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_fragmentele_inactive_lazy
|
||||
# ============================================================
|
||||
|
||||
def test_fragmentele_inactive_lazy(client):
|
||||
"""Panourile inactive nu se cer la load — fara hx-trigger=load pe fragmentele inactive."""
|
||||
_create_account_user("lazy@test.com", "parolasecreta10")
|
||||
_login(client, "lazy@test.com", "parolasecreta10")
|
||||
|
||||
# La tab implicit (Acasa): panoul de submissions (Coada) NU trebuie sa fie in HTML
|
||||
# cu hx-trigger="load" (ar insemna ca se incarca automat la deschiderea paginii)
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
# Verificam ca nu exista un container de submissions cu hx-trigger care include "load"
|
||||
# cand Coada NU e tab-ul activ
|
||||
# Pattern: hx-get="/_fragments/submissions" ... hx-trigger="load..."
|
||||
# Aceasta combinatie NU trebuie sa apara cand tab-ul activ e Acasa
|
||||
submissions_load_pattern = re.search(
|
||||
r'hx-get="/_fragments/submissions"[^>]*hx-trigger="[^"]*load|'
|
||||
r'hx-trigger="[^"]*load[^"]*"[^>]*hx-get="/_fragments/submissions"',
|
||||
html
|
||||
)
|
||||
assert not submissions_load_pattern, (
|
||||
"Fragmentul de submissions (Coada) are hx-trigger=load cand tab-ul activ nu e Coada"
|
||||
)
|
||||
|
||||
# La ?tab=coada: panoul de submissions TREBUIE sa fie in HTML (randat server-side sau cu poll)
|
||||
resp2 = client.get("/?tab=coada")
|
||||
assert resp2.status_code == 200
|
||||
html2 = resp2.text
|
||||
# Cand Coada e activ, containerul de submissions trebuie sa existe
|
||||
assert "/_fragments/submissions" in html2 or "Coada submissions" in html2, (
|
||||
"Panoul Coada nu contine referinta la submissions cand e tab-ul activ"
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_tabbar_aria
|
||||
# ============================================================
|
||||
|
||||
def test_tabbar_aria(client):
|
||||
"""Prezenta atributelor ARIA: role=tablist/tab/tabpanel, aria-selected."""
|
||||
_create_account_user("aria@test.com", "parolasecreta10")
|
||||
_login(client, "aria@test.com", "parolasecreta10")
|
||||
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
html = resp.text
|
||||
assert 'role="tablist"' in html, "Lipseste role=tablist"
|
||||
assert 'role="tab"' in html, "Lipseste role=tab"
|
||||
assert 'role="tabpanel"' in html, "Lipseste role=tabpanel"
|
||||
assert 'aria-selected="true"' in html, "Lipseste aria-selected=true pe tab-ul activ"
|
||||
assert 'aria-selected="false"' in html, "Lipseste aria-selected=false pe tab-urile inactive"
|
||||
Reference in New Issue
Block a user