Хозяин 21.11.2026: «запихать логин между кнопками — это бестпрактикс?» — нет. Логин и выход собраны в меню аккаунта у правого края: кружок с инициалом и почтой, по нажатию — полный адрес и «Выйти»; меню fixed под кнопкой, поэтому не обрезается прокруткой шапки на телефоне; закрывается по Escape и клику мимо. Проверки — живая страница, включая ширину 390 пикселей; мутация без отрисовки краснеет. Co-Authored-By: Claude Code <noreply@anthropic.com>
88 lines
3.8 KiB
Python
88 lines
3.8 KiB
Python
"""Аккаунт в шапке чата: кто вошёл и выход — в меню справа, а не кнопкой среди действий.
|
|
|
|
Живой случай 21.11.2026 (Хозяин): вошёл под sale@teplodv.ru и не увидел логина; первая
|
|
правка поставила почту кнопкой между действиями — Хозяин справедливо назвал это уродством.
|
|
Здесь проверяется меню аккаунта: кружок с инициалом и почта, по нажатию — полный адрес
|
|
и «Выйти», закрытие по Escape и по клику мимо.
|
|
|
|
Mutation: убрать отрисовку при загрузке — падает видимость; убрать «Выйти» из меню — падает состав.
|
|
"""
|
|
import functools
|
|
import http.server
|
|
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 не установлен")
|
|
|
|
import ui_smoke_harness # noqa: E402
|
|
from test_password_reset_ui import browser # noqa: E402,F401
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def site(tmp_path_factory):
|
|
d = tmp_path_factory.mktemp("ui-chip")
|
|
ui_smoke_harness.build_stub(d / "index.html", logged_in=True)
|
|
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=str(d))
|
|
|
|
class Quiet(socketserver.ThreadingTCPServer):
|
|
allow_reuse_address = True
|
|
daemon_threads = True
|
|
|
|
srv = Quiet(("127.0.0.1", 0), handler)
|
|
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
|
yield f"http://127.0.0.1:{srv.server_address[1]}/index.html"
|
|
srv.shutdown()
|
|
srv.server_close()
|
|
|
|
|
|
def test_account_menu_shows_email_and_logout(browser, site):
|
|
ctx = browser.new_context(viewport={"width": 1280, "height": 900})
|
|
pg = ctx.new_page()
|
|
pg.set_default_timeout(8000)
|
|
try:
|
|
pg.goto(site)
|
|
pg.wait_for_selector("#chat-screen", state="visible")
|
|
btn = pg.locator("#account-btn")
|
|
assert btn.is_visible(), "в шапке нет меню аккаунта"
|
|
assert "stub@user" in btn.inner_text(), btn.inner_text()
|
|
assert pg.locator("#account-avatar").inner_text().strip() == "S"
|
|
assert pg.get_attribute("#account-btn", "title") == "Вы вошли как stub@user"
|
|
menu = pg.locator("#account-menu")
|
|
assert not menu.is_visible(), "меню открыто до нажатия"
|
|
btn.click()
|
|
assert menu.is_visible(), "меню не открылось"
|
|
текст = menu.inner_text()
|
|
assert "stub@user" in текст and "Выйти" in текст, текст
|
|
pg.keyboard.press("Escape")
|
|
assert not menu.is_visible(), "Escape не закрыл меню"
|
|
btn.click()
|
|
assert menu.is_visible()
|
|
pg.mouse.click(3, 300)
|
|
assert not menu.is_visible(), "клик мимо не закрыл меню"
|
|
finally:
|
|
ctx.close()
|
|
|
|
|
|
def test_account_menu_fits_phone(browser, site):
|
|
"""На телефоне шапка прокручивается вбок — меню обязано открыться целиком, не обрезаясь."""
|
|
ctx = browser.new_context(viewport={"width": 390, "height": 844})
|
|
pg = ctx.new_page()
|
|
pg.set_default_timeout(8000)
|
|
try:
|
|
pg.goto(site)
|
|
pg.wait_for_selector("#chat-screen", state="visible")
|
|
pg.locator("#account-btn").click()
|
|
box = pg.locator("#account-menu").bounding_box()
|
|
assert box, "меню не открылось на телефоне"
|
|
assert box["x"] >= 0 and box["x"] + box["width"] <= 390 + 0.5, box
|
|
finally:
|
|
ctx.close()
|