feat(web): editare celule in preview + Acasa unificata (PRD 3.6)
Implementeaza PRD 3.6 (US-001..007), pe canalul de import + stratul web;
worker / masina stari / idempotenta / mapare raman neatinse.
- US-003/004: tab-ul "Trimiteri" eliminat; Trimiterile devin sectiune
permanenta sub upload pe Acasa ("Trimiterile tale"); upload comprimat la
bara slim (hero pastrat la first-run); ?tab=coada si /_fragments/coada
servesc Acasa (fara fragment orfan); poll gated pe visibilityState.
- US-001: coloana noua import_rows.override_json (nullable, Fernet, Approach B)
+ _migrate defensiv; ruta v1 + alias web .../rand/{i}/editeaza aplica patch
canonic ULTIMUL in _resolve_row_for_preview si commit_import (mutatie pura,
status rederivat, fara drift). Scoping JOIN -> 404, guard committed -> 409,
semantica empty=clear, decrypt fail -> no-op.
- US-002: buton "Editeaza" pe rand; swap pe <tr> + OOB contoare (nu pe sectiune);
form propriu (confirm dezactivat la editare); refoloseste grila responsiva +
error-map din _trimitere_detaliu.html; mutual-exclusion intre randuri.
- US-005/006: "De rezolvat", "Operatii salvate" si "Formate de coloane" ca
tabele (.tablewrap); H4: comutatorul reflecta auto_send STOCAT.
- US-007: bifa "auto-send" devine comutator etichetat pe COADA ("Pune automat
in coada" / "Tine pentru verificare"), scoped pe operatie; name="auto_send"
pastrat (semantica de prezenta -> bool corect cu ambele parsere, zero backend).
Fix-uri gasite la verificarea E2E in browser (htmx 1.9.12, JS — invizibile la
TestClient): useTemplateFragments=true (raspuns <tr>+OOB era parsat in context
de tabel -> swapError + contoare pierdute); re-activarea confirm-btn dupa salvare
deferita pe tick (evita editing=true tranzitoriu); n-hint actualizat de updateN.
Teste: 523 passed. E2E browser: Acasa unificata, upload slim, editare rand
(needs_data -> ok, swap pe rand, contoare OOB), Mapari tabelar + comutator.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
137
tests/test_preview_edit_ui.py
Normal file
137
tests/test_preview_edit_ui.py
Normal file
@@ -0,0 +1,137 @@
|
||||
"""Teste US-002 (PRD 3.6): buton "Editeaza" pe rand in tabelul de preview.
|
||||
|
||||
Mod editare pe rand (form propriu, NU #confirm-form). Swap pe rand + OOB contoare,
|
||||
NU pe #import-section (D-3.1). La eroare de validare randul ramane in editare cu
|
||||
valorile pastrate (D-2.1/D-2.2). Enter intr-un camp salveaza randul, nu confirma (D-3.3).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
_FIXTURES = pathlib.Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(monkeypatch):
|
||||
tmp = tempfile.mkdtemp()
|
||||
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "edit_ui.db"))
|
||||
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "false")
|
||||
from app.config import get_settings
|
||||
get_settings.cache_clear()
|
||||
from app.crypto import reset_cache
|
||||
reset_cache()
|
||||
from app.main import app
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
get_settings.cache_clear()
|
||||
reset_cache()
|
||||
|
||||
|
||||
def _seed_op1() -> None:
|
||||
from app.db import get_connection
|
||||
conn = get_connection()
|
||||
try:
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO nomenclator_rar (cod_prestatie, nume_prestatie) "
|
||||
"VALUES ('R-FRANE','Reparatie frane')"
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO operations_mapping (account_id, cod_op_service, cod_prestatie, auto_send) "
|
||||
"VALUES (1, 'OP-1', 'R-FRANE', 1)"
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _upload_and_preview(client: TestClient) -> int:
|
||||
"""Upload fixture necanonic + salveaza maparea -> preview. Intoarce import_id."""
|
||||
data = (_FIXTURES / "import_antet_necanonic.csv").read_bytes()
|
||||
r = client.post(
|
||||
"/_import/upload",
|
||||
files={"file": ("import_antet_necanonic.csv", io.BytesIO(data), "text/csv")},
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
m = re.search(r"/_import/(\d+)/mapare-coloane", r.text)
|
||||
assert m, "import_id negasit in formularul de mapare"
|
||||
iid = int(m.group(1))
|
||||
r = client.post(f"/_import/{iid}/mapare-coloane", data={
|
||||
"colname": ["Serie sasiu", "Nr", "Data", "KM", "Operatie"],
|
||||
"canon": ["vin", "nr_inmatriculare", "data_prestatie", "odometru_final", "operatie"],
|
||||
"format_data": "YYYY-MM-DD",
|
||||
})
|
||||
assert r.status_code == 200, r.text
|
||||
return iid
|
||||
|
||||
|
||||
def test_preview_are_buton_editeaza_pe_rand(client):
|
||||
"""Tabelul de preview are buton 'Editeaza' pe rand (coloana de actiuni)."""
|
||||
_seed_op1()
|
||||
iid = _upload_and_preview(client)
|
||||
r = client.get(f"/_import/{iid}/preview")
|
||||
assert r.status_code == 200
|
||||
assert "Editeaza" in r.text
|
||||
assert f"/_import/{iid}/rand/0/editare" in r.text
|
||||
|
||||
|
||||
def test_editeaza_intra_in_mod_editare_form_propriu(client):
|
||||
"""GET editare: randul devine un FORM separat care posteaza la .../editeaza, NU #confirm-form."""
|
||||
_seed_op1()
|
||||
iid = _upload_and_preview(client)
|
||||
r = client.get(f"/_import/{iid}/rand/0/editare")
|
||||
assert r.status_code == 200
|
||||
html = r.text
|
||||
assert f'hx-post="/_import/{iid}/rand/0/editeaza"' in html
|
||||
# Inputurile de editare NU stau in #confirm-form (form propriu).
|
||||
assert 'id="confirm-form"' not in html
|
||||
assert 'name="data_prestatie"' in html and 'name="vin"' in html
|
||||
|
||||
|
||||
def test_salveaza_reda_doar_randul(client):
|
||||
"""POST editeaza: raspuns = fragmentul randului + OOB contoare, NU tot #import-section (D-3.1)."""
|
||||
_seed_op1()
|
||||
iid = _upload_and_preview(client)
|
||||
r = client.post(f"/_import/{iid}/rand/0/editeaza", data={"data_prestatie": "2026-06-10"})
|
||||
assert r.status_code == 200
|
||||
html = r.text
|
||||
assert 'id="preview-row-0"' in html
|
||||
# OOB pe rezumat (contoare), NU re-randarea sectiunii intregi.
|
||||
assert 'id="preview-rezumat"' in html and 'hx-swap-oob="true"' in html
|
||||
assert 'id="import-section"' not in html
|
||||
|
||||
|
||||
def test_enter_in_camp_editare_nu_declanseaza_confirm(client):
|
||||
"""Inputurile de editare sunt in form propriu (post editeaza); Enter salveaza randul,
|
||||
nu declanseaza confirmarea ireversibila. Niciun input de editare nu e legat de #confirm-form."""
|
||||
_seed_op1()
|
||||
iid = _upload_and_preview(client)
|
||||
r = client.get(f"/_import/{iid}/rand/0/editare")
|
||||
assert r.status_code == 200
|
||||
html = r.text
|
||||
# Formul de editare posteaza la editeaza (Enter -> save), nu la /confirma.
|
||||
assert f'hx-post="/_import/{iid}/rand/0/editeaza"' in html
|
||||
assert "/confirma" not in html
|
||||
# Inputurile NU sunt asociate explicit la #confirm-form.
|
||||
assert 'form="confirm-form"' not in html
|
||||
|
||||
|
||||
def test_eroare_validare_pastreaza_valorile_introduse(client):
|
||||
"""Data invalida -> randul ramane in editare, valoarea introdusa pastrata, mesaj pe camp."""
|
||||
_seed_op1()
|
||||
iid = _upload_and_preview(client)
|
||||
r = client.post(f"/_import/{iid}/rand/0/editeaza", data={"data_prestatie": "data-gresita"})
|
||||
assert r.status_code == 200
|
||||
html = r.text
|
||||
# Inca in editare (form propriu prezent) cu valoarea pastrata.
|
||||
assert f'hx-post="/_import/{iid}/rand/0/editeaza"' in html
|
||||
assert "data-gresita" in html
|
||||
# Mesaj de validare pentru data.
|
||||
assert "data" in html.lower() and ("invalid" in html.lower() or "YYYY-MM-DD" in html)
|
||||
Reference in New Issue
Block a user