14 stories TDD prin echipa de workeri (lead orchestreaza, 3 teammates pe valuri cu fisiere disjuncte; routes.py + base.html serializate ca fisiere fierbinti). - US-001 fix filtrare data (_iso_date_prefix pe garda+comparatie, prinde timestamp cu ora) - US-002/007 operatie service distincta in payload_view + afisare in detaliu - US-003 pill-uri categorii (button/aria-pressed; needs_mapping --warn, needs_data/error --err); fara lista ID-uri/dropdown - US-004 paginare numerotata 25/pag (total ramificat SQL-COUNT vs fetch-all+slice, clamp page, poll pastreaza pagina) - US-005 VIN block-level sub nr - US-006/006b editare cod RAR + validare nomenclator + recalcul idempotency (needs_data/needs_mapping via /corecteaza, error via /repune) - US-008 card eroare 3-niveluri doar pe read-only + rezumat top-of-form - US-009 Mapari in meniu hamburger; scoatere tab-bar + role=tablist orfan - US-010/011 pagina Mapari consolidata + butoane icon SVG + dirty-state (fara kebab/emoji) - US-012/012b header centrat + logo ROMFAST (/static/romfast_logo.png) in header - US-013 paleta azur ROMFAST (#2E74D6/#1F66C9) + IBM Plex Sans/Mono self-host (woff2 reale) - US-014 selector tema ciclic Light/Dark/Petrol/Auto + anti-FOUC pe 4 stari Backend trimitere (worker/masina stari/idempotenta/mapping) + schema NEATINSE (UI/UX pur + 1 fix de filtrare). VERIFY context curat PASS; /code-review high: 1 finding material reparat (US-006b). Regresie 896 passed, 1 skipped, 0 failed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
133 lines
4.3 KiB
Python
133 lines
4.3 KiB
Python
"""Teste US-011 (PRD 3.5): badge cu contoare pe tab-uri (atentionari).
|
|
|
|
Badge doar cand contorul > 0; numar corect scoped pe cont; aria-label cu sens.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
def _create_account_user(email: str, name: str = "Service", password: str = "parolasecreta10"):
|
|
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, name, active=True)
|
|
create_user(conn, acct_id, email, password)
|
|
return acct_id
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _login(client, email: str, password: str = "parolasecreta10") -> 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
|
|
resp = client.post("/login", data={"email": email, "parola": password, "csrf_token": m.group(1)})
|
|
assert resp.status_code == 303
|
|
|
|
|
|
def _ins(acct: int, status: str) -> None:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) VALUES (?, ?, ?, ?)",
|
|
(f"k-{os.urandom(5).hex()}", acct, status, json.dumps({"vin": "X", "prestatii": []})),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _tab_link(html: str, elem_id: str) -> str:
|
|
"""Extrage tag-ul <a ...>...</a> al tab-ului cu id-ul dat."""
|
|
m = re.search(rf'<a id="{elem_id}".*?</a>', html, re.DOTALL)
|
|
assert m, f"Tab {elem_id} negasit"
|
|
return m.group(0)
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "badge.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()
|
|
from app.main import app
|
|
with TestClient(app, follow_redirects=False) as c:
|
|
yield c
|
|
ratelimit._hits.clear()
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def test_badge_mapari(client):
|
|
"""US-009: cu operatii needs_mapping, intrarea Mapari din meniu poarta un badge cu numar."""
|
|
acct = _create_account_user("bm@test.com")
|
|
_ins(acct, "needs_mapping")
|
|
_ins(acct, "needs_mapping")
|
|
_login(client, "bm@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
# US-009: Mapari e acum in meniu (nu tab); badgeul apare in intrarea meniului
|
|
idx = html.find('href="/?tab=mapari"')
|
|
assert idx != -1, "Intrarea Mapari lipseste din meniu"
|
|
# Cauta badgeul in contextul link-ului Mapari
|
|
window = html[idx:idx + 300]
|
|
assert "tab-badge" in window, "Badgeul (tab-badge) trebuie sa apara langa intrarea Mapari"
|
|
assert "2" in window, "Contorul 2 trebuie sa apara in badge-ul Mapari"
|
|
|
|
|
|
def test_badge_trimiteri_blocate(client):
|
|
"""US-003 (3.6): cu randuri blocate, marcajul de atentie apare in heading-ul
|
|
sectiunii 'Trimiterile tale' de pe Acasa (tab-ul Trimiteri a disparut)."""
|
|
acct = _create_account_user("bt@test.com")
|
|
_ins(acct, "needs_data")
|
|
_ins(acct, "error")
|
|
_login(client, "bt@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'id="tab-coada"' not in html # tab-ul a fost eliminat
|
|
idx = html.find("Trimiterile tale")
|
|
assert idx != -1, "sectiunea Trimiteri lipseste de pe Acasa"
|
|
near = html[idx:idx + 400]
|
|
assert "tab-badge" in near
|
|
assert "2" in near
|
|
|
|
|
|
def test_badge_zero_ascuns(client):
|
|
"""Fara nimic de rezolvat, niciun badge."""
|
|
_create_account_user("bz@test.com")
|
|
_login(client, "bz@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
assert "tab-badge" not in resp.text
|
|
|
|
|
|
def test_badge_scoped_pe_cont(client):
|
|
"""Badge-ul numara doar submission-urile contului propriu."""
|
|
acct1 = _create_account_user("bs1@test.com", name="C1")
|
|
_create_account_user("bs2@test.com", name="C2")
|
|
_ins(acct1, "needs_mapping")
|
|
|
|
_login(client, "bs2@test.com")
|
|
resp = client.get("/")
|
|
assert "tab-badge" not in resp.text # contul 2 nu are nimic
|