Files
smeta-web/tests/test_topup_modal_ui.py
T
anorandClaude Code 7bff39fb19 fix(шапка): кнопка-остаток зелёная — та самая, про которую говорил Хозяин
Хозяин 21.11.2026 показал кнопку «Осталось: 4 из 5 вопр.»: просил сделать заметнее.
Она теперь зелёная с белым текстом; предупреждения 75/90 % — янтарная и красная
заливки, текст остаётся белым. Проверка — вычисленный цвет в браузере, мутация краснеет.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-21 01:34:44 +10:00

91 lines
4.4 KiB
Python

"""Окно «Пополнить счёт»: нажатие суммы обязано быть видно и уходить на сервер.
Живой случай 21.11.2026 (Хозяин): нажал «500 ₽» — поле суммы осталось пустым, будто
ничего не выбрано. Сумма запоминалась в переменной и уходила на сервер, но человек
этого не видел. Здесь проверяется настоящая страница чата в браузере.
Mutation: убрать заполнение поля — падает первая проверка; не отправлять сумму —
падает вторая.
"""
import functools
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 не установлен")
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-topup")
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_trial_tells_to_top_up_not_write_email(browser, site):
"""Пробный доступ при открытом приёме: рядом стоит кнопка «Пополнить счёт» — текст не
должен звать писать на почту (Хозяин, 21.11.2026)."""
ctx = browser.new_context(viewport={"width": 1280, "height": 900})
pg = ctx.new_page()
pg.set_default_timeout(8000)
try:
pg.add_init_script("localStorage.setItem('stub_trial','1')")
pg.goto(site)
pg.wait_for_selector("#chat-screen", state="visible")
цвет = pg.evaluate("getComputedStyle(document.getElementById('balance-badge')).backgroundColor")
assert цвет == "rgb(45, 138, 86)", (
f"кнопка-остаток не зелёная, как велел Хозяин: {цвет}")
pg.click("#balance-badge")
подсказка = pg.get_attribute("#balance-badge", "title")
assert "пробн" in подсказка.lower(), (
f"подсказка у остатка говорит не про пробные вопросы: {подсказка!r}")
text = pg.locator("#balance-window").inner_text()
assert "пополните счёт" in text, f"текст не зовёт пополнить счёт: {text!r}"
assert "info@infosmeta.ru" not in text, f"устаревшая почта осталась: {text!r}"
assert pg.locator("#topup-open-btn").is_visible(), "нет кнопки пополнения в окне"
finally:
ctx.close()
def test_preset_shows_amount_and_sends_it(browser, site):
ctx = browser.new_context(viewport={"width": 1280, "height": 900})
pg = ctx.new_page()
pg.set_default_timeout(8000)
try:
pg.add_init_script("localStorage.setItem('stub_topup','1')")
pg.goto(site + "?topup=1")
pg.wait_for_selector("#topup-modal", state="visible")
цвет = pg.evaluate("getComputedStyle(document.getElementById('topup-go')).backgroundColor")
assert цвет == "rgb(45, 138, 86)", (
f"кнопка оплаты не зелёная, как велел Хозяин: {цвет}")
pg.get_by_role("button", name="500 ₽").click()
assert pg.input_value("#topup-amount") == "500", (
"нажатая сумма не видна в поле — человек думает, что выбор не сработал")
pg.get_by_role("button", name="Перейти к оплате").click()
pg.wait_for_function("() => !!window._topupBody")
assert json.loads(pg.evaluate("window._topupBody"))["amount"] == "500"
finally:
ctx.close()