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>
218 lines
8.0 KiB
Python
218 lines
8.0 KiB
Python
"""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"
|
|
|
|
# Tab-urile trebuie sa fie prezente (Import a fuzionat in Acasa; "Coada"->"Trimiteri" — PRD 3.5)
|
|
for label in ("Acasa", "Trimiteri", "Mapari", "Cont", "Nomenclator"):
|
|
assert label in html, f"Lipseste tab-ul '{label}' din tab-bar"
|
|
# "Import" nu mai e un tab separat in tab-bar (importul e direct pe Acasa)
|
|
assert not re.search(r'role="tab"[^>]*>\s*Import\s*<', html), \
|
|
"Tab-ul 'Import' nu ar mai trebui sa existe ca tab separat (US-002)"
|
|
|
|
|
|
# ============================================================
|
|
# 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):
|
|
"""US-003 (3.6): Trimiterile sunt sectiune pe Acasa, nu un tab separat.
|
|
|
|
First-run (zero trimiteri): sectiunea Trimiteri (si poll-ul ei) e suprimata.
|
|
Dupa ce contul are trimiteri, sectiunea apare pe Acasa cu poll-ul ei.
|
|
"""
|
|
acct, _ = _create_account_user("lazy@test.com", "parolasecreta10")
|
|
_login(client, "lazy@test.com", "parolasecreta10")
|
|
|
|
# First-run: fara trimiteri -> niciun poll de submissions pe Acasa.
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
assert "/_fragments/submissions" not in resp.text, (
|
|
"Poll-ul de submissions nu trebuie sa apara cand contul nu are inca trimiteri"
|
|
)
|
|
|
|
# Seed o trimitere -> sectiunea Trimiteri apare pe Acasa.
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) "
|
|
"VALUES (?, ?, 'sent', '{}')",
|
|
("k-lazy-1", acct),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
resp2 = client.get("/?tab=coada") # ?tab=coada cade pe Acasa, fara 404
|
|
assert resp2.status_code == 200
|
|
assert "/_fragments/submissions" in resp2.text, (
|
|
"Sectiunea Trimiteri de pe Acasa nu contine referinta la submissions"
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# 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"
|