library.py hält die Regeln der Web-Bibliothek (53-library.js) als reine Funktionen: Status Angefangen/Ungelesen/Gelesen, Ordner (mehrere je Buch, Reihenfolge aus den verschlüsselten Bibliothekseinstellungen, "Ohne Ordner"), Suche ohne Akzente, sechs Sortierungen mit natürlicher Zahlenordnung, Weiterlesen-Karte aus den zuletzt gelesenen, Bücher/Zeitschriften. library_screen.py zeigt sie an (Tasten 1-4, o, /, s, m, c; Chips und Karte klickbar). Metadaten (Ordner, Seitenzahl, Zeitschrift) und die Ordnerreihenfolge kommen beim Abgleich; fehlt die Länge, rechnet die TUI sie für geladene Bücher aus dem Text (1800 Zeichen je Seite). crypto.encrypt für Stufe 3. 54 Tests, Smoke prüft Ordner/Länge/Prefs gegen den lokalen Server. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""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({})
|