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>
152 lines
5.2 KiB
Python
152 lines
5.2 KiB
Python
"""Teste US-005 (PRD 5.10): VIN pe rand separat sub numarul de inmatriculare.
|
|
|
|
VIN-ul era randat ca <span> inline in aceeasi celula cu nr. Story-ul cere un
|
|
element block-level (div/small/p cu display:block) sub nr, in stil muted.
|
|
Testul asserteaza tipul elementului (block), nu doar prezenta textului.
|
|
"""
|
|
|
|
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, *, vin: str = "", nr: str = "B01TST", status: str = "queued") -> int:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
cur = conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) VALUES (?, ?, ?, ?)",
|
|
(
|
|
f"k-{os.urandom(5).hex()}", acct, status,
|
|
json.dumps({
|
|
"vin": vin,
|
|
"nr_inmatriculare": nr,
|
|
"data_prestatie": "2026-06-20",
|
|
"odometru_final": "100",
|
|
"prestatii": [{"cod_prestatie": "R-X"}],
|
|
}),
|
|
),
|
|
)
|
|
conn.commit()
|
|
return cur.lastrowid # type: ignore[return-value]
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "layout_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()
|
|
from app.main import app
|
|
with TestClient(app, follow_redirects=False) as c:
|
|
yield c
|
|
ratelimit._hits.clear()
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def test_vin_pe_rand_separat_sub_nr(client):
|
|
"""VIN-ul apare intr-un element block-level (div/p/small cu display:block) sub nr.
|
|
|
|
Inainte: <span class="muted">...VIN...</span> inline.
|
|
Dupa: <div class="muted">...VIN...</div> (block, rand separat).
|
|
Testul asserteaza prezenta unui element block, nu doar textul.
|
|
"""
|
|
acct = _create_account_user("vin_layout@test.com")
|
|
sid = _ins(acct, vin="WVWZZZ1JZXW000001", nr="B123XYZ")
|
|
_login(client, "vin_layout@test.com")
|
|
|
|
resp = client.get("/_fragments/submissions")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
|
|
# VIN trunchiat trebuie sa apara in HTML
|
|
assert "000001" in html, "VIN-ul trunchiat trebuie sa apara in tabel"
|
|
|
|
# Elementul ce contine VIN-ul trebuie sa fie block-level (div, p, small etc.)
|
|
# NU un simplu <span> inline.
|
|
# Pattern: <div ... >...000001...</div> sau <p ... >...000001...</p>
|
|
# Acceptam orice block-level tag (div/p/small) care contine fragmentul VIN.
|
|
block_tags = ["div", "p", "small"]
|
|
vin_fragment = "000001"
|
|
found_block = any(
|
|
re.search(
|
|
rf"<{tag}[^>]*>[^<]*{re.escape(vin_fragment)}[^<]*</{tag}>",
|
|
html,
|
|
)
|
|
for tag in block_tags
|
|
)
|
|
assert found_block, (
|
|
f"VIN '{vin_fragment}' trebuie sa fie intr-un element block-level "
|
|
f"(div/p/small), nu intr-un <span> inline. HTML gasit: "
|
|
+ html[max(0, html.find(vin_fragment) - 80):html.find(vin_fragment) + 80]
|
|
)
|
|
|
|
# Elementul block trebuie sa aiba clasa 'muted' (stil discret)
|
|
muted_block = any(
|
|
re.search(
|
|
rf'<{tag}[^>]*class="[^"]*muted[^"]*"[^>]*>[^<]*{re.escape(vin_fragment)}[^<]*</{tag}>',
|
|
html,
|
|
)
|
|
for tag in block_tags
|
|
)
|
|
assert muted_block, (
|
|
f"Elementul block cu VIN trebuie sa aiba clasa 'muted'"
|
|
)
|
|
|
|
|
|
def test_vin_lipsa_nu_genereaza_rand_gol(client):
|
|
"""Cand VIN-ul lipseste (sau e EMPTY='—'), nu apare un element gol in celula Vehicul."""
|
|
acct = _create_account_user("vin_gol@test.com")
|
|
sid = _ins(acct, vin="", nr="B999TST") # VIN gol -> EMPTY="—"
|
|
_login(client, "vin_gol@test.com")
|
|
|
|
resp = client.get("/_fragments/submissions")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
|
|
# Randul trebuie sa existe
|
|
assert f'id="trimitere-row-{sid}"' in html
|
|
|
|
# In coloana vehicul nu trebuie sa apara un element block gol cu "—"
|
|
# (garda != '—' exista deja, verifica ca e respectata)
|
|
assert 'class="muted"' not in html.split('col-vehicul')[1].split('col-operatie')[0] or \
|
|
'—' not in (html.split('col-vehicul')[1].split('col-operatie')[0]), \
|
|
"Elementul muted din coloana Vehicul nu trebuie sa contina '—' (rand gol VIN)"
|