test(админка): визуальный проход пяти разделов
This commit is contained in:
@@ -366,6 +366,11 @@
|
||||
- `feat/topup` — **no-go**, отдельный релиз 2; `main`/прод `94e7c39` не трогаем.
|
||||
- Политика данных **не подтверждена**; P4.7b заблокирован.
|
||||
|
||||
## 4.50. P5.1 — визуальный проход
|
||||
|
||||
- `tests/test_admin_v2_visual.py`: 5 разделов на 1280, h1, нет pageerror, нет горизонтального скролла.
|
||||
- Осталось: 2FA-визуал и детерминированные скриншоты.
|
||||
|
||||
## 5. Следующий шаг
|
||||
|
||||
P0.0 design-gate → P0.1 backup/restore → P0.2 (release `feat/topup` отдельно, не в рамках выравнивания).
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
"""P5.1: пять разделов v2 на 1280 — заголовок, данные, без ошибок и разъезда."""
|
||||
import http.server
|
||||
import json
|
||||
import socketserver
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT)); sys.path.insert(0, str(ROOT / "tests"))
|
||||
pytest.importorskip("playwright.sync_api", reason="playwright не установлен")
|
||||
from test_admin_design_ui import browser # noqa: E402,F401
|
||||
|
||||
DASH = {"user": "boss@x", "generated_at": 1794000000, "last_visit": None,
|
||||
"work_24h": {"people": 1, "requests": 5, "failures": 0, "failure_share": 0,
|
||||
"limit_hits": 0, "latency_qa_ms": 1, "latency_qa_p95_ms": 1,
|
||||
"latency_agent_ms": 1, "latency_agent_p95_ms": 1},
|
||||
"money": {"revenue_rub": 100, "flow_rub": 50, "accounts_total_rub": 200,
|
||||
"topups_included": False, "unpriced": 0},
|
||||
"customers": {"total": 2, "active_24h": 1},
|
||||
"attention": {"failures": 0, "limit_hits": 0, "unpriced": 0}}
|
||||
MONEY = {"period_days": 30, "revenue_rub": 100, "refunded_rub": 0, "cost_rub": 50,
|
||||
"flow_rub": 50, "charged_rub": 80, "accounts_total_rub": 200,
|
||||
"accounts_count": 1, "unpriced": 0}
|
||||
SYS = {"channels": [{"name": "database", "ok": True, "detail": "ок", "level": "fail"}],
|
||||
"settings": [{"key": "agent_killswitch", "value": "off"}],
|
||||
"history": [], "errors": {"items": [], "total": 0}, "generated_at": 1793000000}
|
||||
|
||||
|
||||
class H(http.server.SimpleHTTPRequestHandler):
|
||||
def __init__(self, *a, **kw):
|
||||
super().__init__(*a, directory=str(ROOT), **kw)
|
||||
|
||||
def do_GET(self):
|
||||
from urllib.parse import urlparse
|
||||
u = urlparse(self.path)
|
||||
mapping = {
|
||||
"/api/admin/v2/dashboard": DASH,
|
||||
"/api/admin/v2/attention": {"items": [], "count": 0},
|
||||
"/api/admin/v2/customers": {"items": [], "total": 0, "page": 1, "per_page": 50},
|
||||
"/api/admin/v2/customer-emails": {"emails": []},
|
||||
"/api/admin/v2/money": MONEY,
|
||||
"/api/admin/v2/finance": {"months": [], "days": 30},
|
||||
"/api/admin/v2/payments": {"items": [], "total": 0, "page": 1, "per_page": 50},
|
||||
"/api/admin/v2/accounts": {"items": [], "total": 0, "total_rub": 0},
|
||||
"/api/admin/v2/feedback": {"items": [], "total": 0, "page": 1, "per_page": 50},
|
||||
"/api/admin/v2/system": SYS,
|
||||
"/api/admin/v2/sessions": {"items": []},
|
||||
"/api/admin/v2/work/dialogs": {"items": [], "total": 0, "page": 1},
|
||||
"/api/admin/v2/work/failures": {"items": [], "total": 0, "page": 1},
|
||||
"/api/admin/v2/work/journal": {"items": [], "total": 0, "page": 1},
|
||||
}
|
||||
if u.path in mapping:
|
||||
return self._json(mapping[u.path])
|
||||
if self.path == "/admin/v2" or self.path.startswith("/admin/v2/"):
|
||||
data = (ROOT / "static/admin2/index.html").read_bytes()
|
||||
self.send_response(200); self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(data))); self.end_headers()
|
||||
self.wfile.write(data); return
|
||||
return super().do_GET()
|
||||
|
||||
def _json(self, obj):
|
||||
data = json.dumps(obj).encode()
|
||||
self.send_response(200); self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(data))); self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
def log_message(self, *a):
|
||||
return
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def site():
|
||||
class Quiet(socketserver.ThreadingTCPServer):
|
||||
allow_reuse_address = True
|
||||
daemon_threads = True
|
||||
srv = Quiet(("127.0.0.1", 0), H)
|
||||
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
||||
yield f"http://127.0.0.1:{srv.server_address[1]}"
|
||||
srv.shutdown()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path,title", [
|
||||
("", "Мой день"), ("/customers", "Клиенты"), ("/money", "Деньги"),
|
||||
("/work", "Работа"), ("/system", "Система")])
|
||||
def test_sections_render(browser, site, path, title):
|
||||
page = browser.new_page(viewport={"width": 1280, "height": 800})
|
||||
errors = []
|
||||
page.on("pageerror", lambda e: errors.append(str(e)))
|
||||
page.add_init_script("localStorage.setItem('token','t')")
|
||||
page.goto(site + "/admin/v2" + path)
|
||||
page.wait_for_selector("h1")
|
||||
assert page.locator("h1").inner_text() == title
|
||||
page.wait_for_timeout(300)
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= innerWidth")
|
||||
assert errors == []
|
||||
page.close()
|
||||
Reference in New Issue
Block a user