Files
email-assistant/tests/test_webui_smoke.py
T
hermes fa9bdae40f
wiki-sync / Publish docs/wiki to Gitea wiki (push) Successful in 45s
feat(home,emails): письма с выполненной задачей уходят из «к исполнению»; обратимый режим «Только письмо»
#5: entities.strip_uid_suffix/completed_task_uids/task_closed_for_email;
index() получает задачи одним REPORT (include_deleted) и не показывает письмо,
если его задача STATUS:COMPLETED или мягко удалена. Письма без задачи, urgent
и entity_task_state:disabled остаются; счётчик после фильтра. 8 тестов.

#6: состояние режима в Alpine (focus/toggleFocus, localStorage ea-focus),
класс f3 ставится биндингом body; кнопка возврата — пункт ⛶ в сайдбаре
(не скрывается при f3), кнопка в тулбаре вызывает тот же toggleFocus;
режим действует только на /emails; \ и Esc; transition ширин c1/c2.

Оба change заархивированы (2026-11-03-*), спеки home-tasks и emails-layout
дополнены; WALKTHROUGH и вики-страница обновлены.
2026-11-03 09:58:21 +00:00

85 lines
2.5 KiB
Python

"""Smoke-тесты веб-интерфейса через FastAPI TestClient.
Запуск: .venv/bin/python -m pytest tests/ -q (или просто python tests/test_webui_smoke.py)
"""
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
os.environ.setdefault("WEBUI_PASSWORD", "test-pass")
from fastapi.testclient import TestClient # noqa: E402
from webui.app import app # noqa: E402
c = TestClient(app)
def _login():
return c.post("/login", data={"password": "test-pass"}, follow_redirects=False)
def test_unauth_redirects():
fresh = TestClient(app) # без cookie от предыдущих тестов
r = fresh.get("/", follow_redirects=False)
assert r.status_code == 303
assert r.headers["location"] == "/login"
def test_bad_password():
r = c.post("/login", data={"password": "nope"}, follow_redirects=False)
assert r.status_code == 200
assert "Неверный пароль" in r.text
def test_login_ok():
r = _login()
assert r.status_code == 303
def test_pages_render():
_login()
for url in ("/", "/emails", "/emails?folder=INBOX", "/search?q=КП"):
r = c.get(url, follow_redirects=False)
assert r.status_code == 200, url
def test_three_columns_and_ai_pane():
_login()
html = c.get("/emails?folder=INBOX").text
assert 'class="c1"' in html and 'class="c2"' in html and 'class="c3"' in html
assert "chatpane" in html
def test_search_body_fallback():
_login()
html = c.get("/search?q=Эвотор").text
assert "res-row" in html or "Ничего не найдено" in html
def test_focus_mode_has_return_button_in_sidebar():
"""Режим «Только письмо» обратим: пункт возврата живёт в сайдбаре."""
_login()
html = c.get("/emails?folder=INBOX").text
assert "toggleFocus" in html
assert 'x-show="page === \'emails\'"' in html
assert "Показать список писем" in html
# старый инлайн-переключатель класса body больше не используется
assert "classList.toggle('f3')" not in html
assert "@keydown.window" in html
def test_ai_unauthenticated_401():
c2 = TestClient(app)
r = c2.post("/api/ai/ask", json={"question": "hi"})
assert r.status_code == 401
if __name__ == "__main__":
for name, fn in sorted(globals().items()):
if name.startswith("test_") and callable(fn):
fn()
print("OK", name)
print("all smoke tests passed")