feat(интерфейс): полоса «сайт в разработке» и адрес для обратной связи
Распоряжения Хозяина 08.09.2026: на странице входа добавить полосу о том, что сайт ещё в разработке (не заменяя страницу), а внизу чата — адрес info@infosmeta.ru. Полоса стоит над посадочной частью и уходит вместе с экраном входа; адрес живёт вне ленты сообщений, поэтому не стирается при создании нового диалога. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RuEU1u9Rz24zmoy9TuvWc2
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
"""Адрес для обратной связи глазами браузера: экран чата.
|
||||
|
||||
Стенд собирается с ключом входа (в хранилище лежит пропуск), поэтому сразу виден чат,
|
||||
а не экран входа.
|
||||
|
||||
Red-green: написано ДО правки static/chat.html.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import http.server
|
||||
import os
|
||||
import socketserver
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if ROOT not in sys.path:
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
pytest.importorskip("playwright.sync_api", reason="playwright не установлен")
|
||||
|
||||
import ui_smoke_harness # noqa: E402
|
||||
from test_password_reset_ui import _launch, browser # noqa: E402,F401
|
||||
|
||||
ADDRESS = "info@infosmeta.ru"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def site_in(tmp_path_factory):
|
||||
"""Стенд с пропуском в хранилище — открывается сразу экран чата."""
|
||||
d = tmp_path_factory.mktemp("ui_chat")
|
||||
ui_smoke_harness.build_stub(d / "index.html")
|
||||
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()
|
||||
|
||||
|
||||
def _open(browser, site_in, width=1280, height=900):
|
||||
ctx = browser.new_context(viewport={"width": width, "height": height})
|
||||
pg = ctx.new_page()
|
||||
pg.set_default_timeout(5000)
|
||||
pg.goto(site_in)
|
||||
pg.wait_for_selector("#chat-screen", state="visible")
|
||||
return ctx, pg
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def page(browser, site_in):
|
||||
ctx, pg = _open(browser, site_in)
|
||||
yield pg
|
||||
ctx.close()
|
||||
|
||||
|
||||
def _box(page, selector):
|
||||
return page.locator(selector).bounding_box()
|
||||
|
||||
|
||||
def _contrast(fg, bg):
|
||||
def lum(css):
|
||||
r, g, b = [int(v) / 255 for v in css[css.index("(") + 1:css.index(")")].split(",")[:3]]
|
||||
f = lambda c: c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4 # noqa: E731
|
||||
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b)
|
||||
a, b = sorted((lum(fg), lum(bg)), reverse=True)
|
||||
return (a + 0.05) / (b + 0.05)
|
||||
|
||||
|
||||
def test_contact_visible_under_input_row(page):
|
||||
"""Строка видна, стоит ниже строки ввода и помещается в окно.
|
||||
Порча: убрать строку или поднять её над полем ввода → проверка упадёт."""
|
||||
assert page.is_visible("#contact-line")
|
||||
c, row = _box(page, "#contact-line"), _box(page, "#input-row")
|
||||
assert c["y"] >= row["y"] + row["height"] - 1, "адрес оказался выше строки ввода"
|
||||
assert c["y"] + c["height"] <= 900
|
||||
assert ADDRESS in page.inner_text("#contact-line")
|
||||
|
||||
|
||||
def test_contact_link_is_clickable_and_not_covered(page):
|
||||
"""Ссылку ничем не перекрывает и она ведёт на почту.
|
||||
Порча: накрыть подвал чем-нибудь висящим поверх → точка попадёт не в ссылку."""
|
||||
assert page.get_attribute("#contact-email", "href") == f"mailto:{ADDRESS}"
|
||||
b = _box(page, "#contact-email")
|
||||
hit = page.evaluate(
|
||||
"([x, y]) => { const e = document.elementFromPoint(x, y);"
|
||||
" return e && e.closest('#contact-email') !== null; }",
|
||||
[b["x"] + b["width"] / 2, b["y"] + b["height"] / 2])
|
||||
assert hit, "ссылку что-то перекрывает"
|
||||
|
||||
|
||||
def test_contact_stays_put_in_long_chat_and_after_new_chat(page):
|
||||
"""Адрес не уезжает с перепиской и не пропадает при создании нового диалога — он вне
|
||||
ленты сообщений. Порча: перенести строку внутрь ленты → уедет и исчезнет."""
|
||||
before = _box(page, "#contact-line")
|
||||
page.evaluate("for (let i = 0; i < 80; i++) addMsg('ai', 'Строка ' + i)")
|
||||
page.wait_for_timeout(200)
|
||||
assert page.evaluate("const m = document.getElementById('messages');"
|
||||
" m.scrollHeight > m.clientHeight + 200"), "лента не прокручивается"
|
||||
after = _box(page, "#contact-line")
|
||||
assert abs(after["y"] - before["y"]) <= 1, "строка уехала вместе с перепиской"
|
||||
assert after["height"] >= 12
|
||||
page.evaluate("newChat()")
|
||||
page.wait_for_timeout(300)
|
||||
assert page.locator("#contact-line").count() == 1 and page.is_visible("#contact-line")
|
||||
|
||||
|
||||
def test_contact_visible_on_phone_no_sideways_scroll(browser, site_in):
|
||||
"""На телефоне адрес виден, поле ввода над ним, страница не уезжает вбок — в том числе
|
||||
при открытой боковой колонке. Порча: запретить перенос строки → появится прокрутка."""
|
||||
ctx, pg = _open(browser, site_in, 360, 740)
|
||||
c, inp = _box(pg, "#contact-line"), _box(pg, "#msg-input")
|
||||
over = pg.evaluate(
|
||||
"document.documentElement.scrollWidth - document.documentElement.clientWidth")
|
||||
pg.evaluate("toggleSidebar()")
|
||||
pg.wait_for_timeout(300)
|
||||
over_open = pg.evaluate(
|
||||
"document.documentElement.scrollWidth - document.documentElement.clientWidth")
|
||||
ctx.close()
|
||||
assert c["y"] + c["height"] <= 740, "адрес не помещается в экран телефона"
|
||||
assert inp["y"] + inp["height"] <= c["y"] + 1, "поле ввода уехало под адрес"
|
||||
assert over <= 1 and over_open <= 1, f"страница шире экрана: {over} и {over_open}"
|
||||
|
||||
|
||||
def test_contact_readable_in_both_themes(browser, site_in):
|
||||
"""Адрес читается в обеих темах: цвет меняется вместе с темой, прозрачности нет,
|
||||
контраст не ниже 4,5. Порча: задать цвет числом или вписать opacity → проверка упадёт."""
|
||||
ctx, pg = _open(browser, site_in)
|
||||
seen = {}
|
||||
for theme in ("light", "dark"):
|
||||
pg.evaluate(f"document.documentElement.setAttribute('data-theme','{theme}')")
|
||||
seen[theme] = (
|
||||
pg.evaluate("getComputedStyle(document.getElementById('contact-email')).color"),
|
||||
pg.evaluate("getComputedStyle(document.getElementById('input-area')).backgroundColor"),
|
||||
pg.evaluate("getComputedStyle(document.getElementById('contact-line')).opacity"),
|
||||
)
|
||||
ctx.close()
|
||||
for theme, (fg, bg, op) in seen.items():
|
||||
assert float(op) == 1.0, f"{theme}: прозрачность {op}"
|
||||
assert _contrast(fg, bg) >= 4.5, f"{theme}: контраст {_contrast(fg, bg):.1f}"
|
||||
assert seen["light"][0] != seen["dark"][0], "цвет не меняется вместе с темой"
|
||||
Reference in New Issue
Block a user