From 537e667ac406727aa8586632cdac7e3c1f82ad86 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 28 Oct 2026 16:57:06 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5):=20=D0=BD=D0=B0=20/stats=20=D0=B8=D1=81?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=BF=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=D0=BD=D1=81=20=D0=BF=D1=80=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD=D0=BE=D0=BC=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=BE=D1=82=D1=81=D1=8B=D0=BB=D0=B0=D0=B5=D1=82=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D1=87=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Блок «Баланс» говорил «напишите на info@», хотя рядом стояла кнопка пополнения; в чате это уже было исправлено, страница статистики отстала. Co-Authored-By: Claude Opus 5.5 --- static/stats.html | 3 ++- tests/test_topup_pages.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/static/stats.html b/static/stats.html index 5b3893f..3861da8 100644 --- a/static/stats.html +++ b/static/stats.html @@ -183,7 +183,8 @@ function renderBalance(b) { b.read_only ? 'Баланс' : (b.trial ? 'Пробный доступ' : 'Остаток на сутки'); if (b.read_only) { box.append(el('p', 'balance-line', 'Баланс исчерпан: новые вопросы закрыты, диалоги доступны для просмотра. ' + - 'Чтобы продолжить, напишите на info@infosmeta.ru.')); + (b.topup ? 'Чтобы продолжить, нажмите «Пополнить счёт» в блоке «Счёт».' + : 'Чтобы продолжить, напишите на info@infosmeta.ru.'))); return; } if (b.trial) { diff --git a/tests/test_topup_pages.py b/tests/test_topup_pages.py index 9881093..c6b0f5b 100644 --- a/tests/test_topup_pages.py +++ b/tests/test_topup_pages.py @@ -76,3 +76,39 @@ def test_pages_have_no_kitchen_words(): text = _read(name).lower() assert "robokassa" not in text and "комисси" not in text, name assert not re.search(r"webhook|вебхук", _read("payment_result.html").lower()) + + +def _run_stats_balance(limits): + """Run the real renderBalance/el from stats.html in node with a minimal DOM stub.""" + import json + import shutil + import subprocess + import pytest + if not shutil.which("node"): + pytest.skip("нет node") + html = _read("stats.html") + def fn(name): + body = html[html.index(f"function {name}("):] + return body[:body.index("\n}\n") + 3] + js = """ +const nodes = {}; +function mk() { return {textContent: '', className: '', children: [], + append(...xs) { this.children.push(...xs); }, set hidden(v) {}}; } +const document = {createElement: () => mk(), + getElementById: id => (nodes[id] = nodes[id] || mk())}; +""" + fn("el") + fn("renderBalance") + f""" +renderBalance({json.dumps(limits)}); +console.log(nodes.balance.children.map(c => c.textContent).join(' ')); +""" + out = subprocess.run(["node", "-e", js], capture_output=True, text=True, timeout=20) + assert out.returncode == 0, out.stderr + return out.stdout + + +def test_stats_exhausted_with_topup_does_not_send_to_mail(): + """«Баланс исчерпан» на /stats при доступном пополнении зовёт пополнить, а не писать на + почту (как в чате); без пополнения — почта. Порча: оставить почту при topup.""" + with_topup = _run_stats_balance({"read_only": True, "topup": {"enabled": True}}) + assert "Пополнить" in with_topup and "info@infosmeta.ru" not in with_topup + without = _run_stats_balance({"read_only": True}) + assert "info@infosmeta.ru" in without