feat(header): badge mediu RAR compact langa chip-ul RAR
Muta indicatorul de mediu (Testare/PRODUCTIE) din statusbar (randare periodica, rand intreg) intr-un badge compact din header, langa chipul RAR scurtat la "RAR". Click pe badge comuta mediul cand exista 2 disponibile; pe mobil (<=560px) eticheta scurta PROD/TEST ramane mereu vizibila (semnal de risc L.142). Toggle-ul din header si schimbarea mediului implicit din Setari actualizeaza badge-ul via OOB swap. Co-Authored-By: Claude Agent <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
"""Indicator mediu RAR in statusbar + toggle conditionat.
|
||||
"""Badge mediu RAR compact in header + toggle conditionat.
|
||||
|
||||
Rute testate:
|
||||
GET /_fragments/status -- indicator mediu (eticheta statica sau toggle)
|
||||
GET / -- badge mediu in header (eticheta statica sau toggle)
|
||||
POST /_fragments/status/toggle-env -- comuta rar_env_default intre mediile disponibile
|
||||
POST /cont/rar-medii -- schimbare mediu implicit din Setari
|
||||
|
||||
Teste:
|
||||
test_afiseaza_env_default -- un mediu disponibil -> eticheta statica, fara toggle
|
||||
test_toggle_doar_la_doua_medii -- doua medii -> toggle prezent; un mediu -> toggle absent
|
||||
test_toggle_schimba_default -- POST toggle -> rar_env_default schimbat in DB, 200
|
||||
test_toggle_schimba_default -- POST toggle -> rar_env_default schimbat in DB, badge+status OOB
|
||||
test_rar_medii_actualizeaza_badge_oob -- schimbarea mediului implicit din Setari anexeaza badge OOB
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -116,14 +118,14 @@ def _seteaza_mediu_disponibil(acct_id: int, env: str) -> None:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _get_csrf_din_status(client) -> str:
|
||||
"""Obtine CSRF token din fragmentul /_fragments/status."""
|
||||
resp = client.get("/_fragments/status")
|
||||
assert resp.status_code == 200, f"/_fragments/status a returnat {resp.status_code}"
|
||||
def _get_csrf_din_pagina(client) -> str:
|
||||
"""Obtine CSRF token din pagina completa `/` (header, randat o singura data)."""
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200, f"/ a returnat {resp.status_code}"
|
||||
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, f"csrf_token negasit in statusbar: {resp.text[:600]}"
|
||||
assert m, f"csrf_token negasit pe pagina: {resp.text[:600]}"
|
||||
return m.group(1)
|
||||
|
||||
|
||||
@@ -133,7 +135,7 @@ def _get_csrf_din_status(client) -> str:
|
||||
|
||||
|
||||
def test_afiseaza_env_default(client):
|
||||
"""Cont cu UN singur mediu disponibil (prod) -> statusbar contine eticheta pentru Productie,
|
||||
"""Cont cu UN singur mediu disponibil (prod) -> header contine eticheta pentru Productie,
|
||||
fara niciun control de toggle/comutare.
|
||||
Eticheta foloseste 'PRODUCȚIE' (diacritice + majuscule).
|
||||
"""
|
||||
@@ -141,13 +143,14 @@ def test_afiseaza_env_default(client):
|
||||
_seteaza_mediu_disponibil(acct_id, "prod")
|
||||
_login(client, "env1@test.com", "parolasecreta10")
|
||||
|
||||
resp = client.get("/_fragments/status")
|
||||
resp = client.get("/")
|
||||
assert resp.status_code == 200, f"Status HTTP neasteptat: {resp.status_code}"
|
||||
html = resp.text
|
||||
|
||||
assert 'id="header-env-badge"' in html, f"Badge mediu absent din header: {html[:800]}"
|
||||
# Eticheta mediului trebuie prezenta — "PRODUC" acopera atat 'PRODUCȚIE' cat si
|
||||
# formele anterioare 'Productie'/'PRODUCTIE' (anti-regresie).
|
||||
assert "PRODUC" in html.upper(), f"Eticheta Productie absenta in statusbar: {html[:800]}"
|
||||
assert "PRODUC" in html.upper(), f"Eticheta Productie absenta din badge: {html[:800]}"
|
||||
|
||||
# Nu trebuie sa existe un control de comutare (toggle) la un singur mediu
|
||||
assert "toggle-env" not in html, \
|
||||
@@ -155,7 +158,7 @@ def test_afiseaza_env_default(client):
|
||||
|
||||
|
||||
def test_toggle_doar_la_doua_medii(client):
|
||||
"""Cont cu DOUA medii disponibile -> statusbar contine controlul de toggle.
|
||||
"""Cont cu DOUA medii disponibile -> header contine controlul de toggle.
|
||||
Cont cu UN singur mediu -> NU contine toggle.
|
||||
"""
|
||||
# Cont cu doua medii
|
||||
@@ -164,7 +167,7 @@ def test_toggle_doar_la_doua_medii(client):
|
||||
_seteaza_mediu_disponibil(acct2_id, "prod")
|
||||
_login(client, "env2@test.com", "parolasecreta10")
|
||||
|
||||
resp2 = client.get("/_fragments/status")
|
||||
resp2 = client.get("/")
|
||||
assert resp2.status_code == 200
|
||||
html2 = resp2.text
|
||||
assert "toggle-env" in html2, \
|
||||
@@ -176,7 +179,7 @@ def test_toggle_doar_la_doua_medii(client):
|
||||
# Relogin pe alt cont (simulam logout/login rapid prin schimbare sesiune)
|
||||
_login(client, "env1b@test.com", "parolasecreta10")
|
||||
|
||||
resp1 = client.get("/_fragments/status")
|
||||
resp1 = client.get("/")
|
||||
assert resp1.status_code == 200
|
||||
html1 = resp1.text
|
||||
assert "toggle-env" not in html1, \
|
||||
@@ -187,7 +190,7 @@ def test_toggle_doar_la_doua_medii(client):
|
||||
|
||||
def test_toggle_schimba_default(client):
|
||||
"""POST la /_fragments/status/toggle-env comuta rar_env_default in DB
|
||||
si intoarce statusbar-ul actualizat (200).
|
||||
si intoarce badge-ul actualizat (tinta hx-target) + status bar-ul ca OOB swap (200).
|
||||
"""
|
||||
acct_id, _ = _create_account_user("Firma Toggle", "toggle@test.com")
|
||||
_seteaza_mediu_disponibil(acct_id, "test")
|
||||
@@ -208,15 +211,17 @@ def test_toggle_schimba_default(client):
|
||||
env_inainte = row_inainte["rar_env_default"] or "prod"
|
||||
|
||||
# Obtine CSRF si face toggle
|
||||
csrf = _get_csrf_din_status(client)
|
||||
csrf = _get_csrf_din_pagina(client)
|
||||
resp = client.post("/_fragments/status/toggle-env", data={"csrf_token": csrf})
|
||||
assert resp.status_code == 200, \
|
||||
f"Toggle a returnat {resp.status_code}: {resp.text[:300]}"
|
||||
|
||||
# Verifica ca statusbar-ul actualizat e in raspuns
|
||||
# Raspunsul contine badge-ul (tinta hx-target) + status bar-ul ca OOB swap
|
||||
html = resp.text
|
||||
assert "status-bar" in html, \
|
||||
f"Raspunsul toggle nu contine statusbar: {html[:400]}"
|
||||
assert 'id="header-env-badge"' in html, \
|
||||
f"Raspunsul toggle nu contine badge-ul din header: {html[:400]}"
|
||||
assert "status-bar" in html and "hx-swap-oob" in html, \
|
||||
f"Raspunsul toggle nu contine status bar-ul ca OOB swap: {html[:400]}"
|
||||
|
||||
# Verifica schimbarea in DB
|
||||
conn = get_connection()
|
||||
@@ -232,3 +237,30 @@ def test_toggle_schimba_default(client):
|
||||
f"rar_env_default NU s-a schimbat: inainte={env_inainte!r}, dupa={env_dupa!r}"
|
||||
assert env_dupa in ("test", "prod"), \
|
||||
f"rar_env_default are valoare invalida: {env_dupa!r}"
|
||||
|
||||
|
||||
def test_rar_medii_actualizeaza_badge_oob(client):
|
||||
"""POST /cont/rar-medii cu un nou mediu implicit anexeaza badge-ul din header
|
||||
ca OOB swap, ca header-ul sa reflecte imediat schimbarea (fara reload).
|
||||
"""
|
||||
acct_id, _ = _create_account_user("Firma Setari", "setari@test.com")
|
||||
_seteaza_mediu_disponibil(acct_id, "test")
|
||||
_seteaza_mediu_disponibil(acct_id, "prod")
|
||||
_login(client, "setari@test.com", "parolasecreta10")
|
||||
|
||||
csrf = _get_csrf_din_pagina(client)
|
||||
resp = client.post(
|
||||
"/cont/rar-medii",
|
||||
data={
|
||||
"csrf_token": csrf,
|
||||
"test_enabled": "1",
|
||||
"prod_enabled": "1",
|
||||
"rar_env_default": "test",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200, \
|
||||
f"/cont/rar-medii a returnat {resp.status_code}: {resp.text[:400]}"
|
||||
|
||||
html = resp.text
|
||||
assert 'id="header-env-badge"' in html and "hx-swap-oob" in html, \
|
||||
f"Raspunsul /cont/rar-medii nu anexeaza badge-ul OOB din header: {html[:600]}"
|
||||
|
||||
Reference in New Issue
Block a user