diora-web/tui/tests/test_app_smoke.py

67 lines
2.1 KiB
Python
Raw Normal View History

"""The Textual app starts, lists a library, opens a book and leaves it again."""
import asyncio
import pytest
from diora_tui.app import DioraTuiApp
from diora_tui.reader_screen import ReaderScreen
@pytest.fixture
def store_fresh(tmp_path, monkeypatch):
from diora_tui import progress
st = progress.ProgressStore(tmp_path / "p.json")
monkeypatch.setattr(progress, "_default", st)
return st
def test_open_read_and_leave(epub, tmp_path):
lib = tmp_path / "lib"
lib.mkdir()
path = epub(["<h1>Anfang</h1>" + "".join(f"<p>Absatz {i} " + "wort " * 40 + "</p>" for i in range(60))])
path.rename(lib / path.name)
async def run():
app = DioraTuiApp(lib)
async with app.run_test(size=(100, 30)) as pilot:
await pilot.pause()
await pilot.press("enter")
for _ in range(50):
await pilot.pause(0.1)
if isinstance(app.screen, ReaderScreen):
break
assert isinstance(app.screen, ReaderScreen)
await pilot.pause(0.5)
await pilot.press("j", "j", "j", "n")
await pilot.press("escape")
await pilot.pause()
assert not isinstance(app.screen, ReaderScreen)
asyncio.run(run())
def test_server_books_are_listed_before_they_are_downloaded(tmp_path, store_fresh):
from textual.widgets import Label, ListView
from diora_tui import library_meta
lib = tmp_path / "lib"
lib.mkdir()
library_meta.set_remote({"s9": {"server_id": 9, "title": "Cloud-Buch", "author": "", "is_read": False, "uploaded_at": "2026-10-01"}})
async def run():
app = DioraTuiApp(lib)
async with app.run_test(size=(100, 30)) as pilot:
await pilot.pause()
text = " | ".join(str(i.render()) for i in app.screen.query_one(ListView).query(Label))
assert "☁ Cloud-Buch" in text
await pilot.press("enter") # not signed in here: says so instead of failing
await pilot.pause()
assert not isinstance(app.screen, ReaderScreen)
try:
asyncio.run(run())
finally:
library_meta.set_remote({})