add(ui/ux): show file formats in the scan and filter by them

This commit is contained in:
Steppenstreuner
2026-08-31 08:33:24 +02:00
parent f08417cdc0
commit 2e84bc8aca
8 changed files with 134 additions and 1 deletions
+42
View File
@@ -6,6 +6,8 @@ from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from wordarr import config as config_module
@pytest.fixture
def client(tmp_path, monkeypatch):
@@ -1093,3 +1095,43 @@ def test_scan_does_not_loop_on_a_symlink_cycle(client):
(d / "back").symlink_to(client.downloads, target_is_directory=True)
items = scanner.scan(client.downloads)
assert [i["name"] for i in items] == ["book"]
def test_scan_reports_the_format_of_every_ebook(client):
"""A Calibre export is the same book a dozen times; the rows differ only in
their extension, so the scan has to name it."""
book = "Der Lehrer - Will er dir helfen - McFadden, Freida"
for ext, size in ((".epub", 1200), (".azw3", 1300), (".pdf", 2100)):
(client.downloads / f"{book}{ext}").write_bytes(b"x" * size)
items = client.get("/api/import/scan").json()["items"]
assert {i["formats"][0]: i["size"] for i in items} == {
"epub": 1200, "azw3": 1300, "pdf": 2100,
}
assert all(len(i["formats"]) == 1 for i in items)
def test_scan_lists_every_format_of_an_audiobook_folder(client):
got = client.downloads / "Ein Hoerbuch"
got.mkdir()
(got / "01 Teil.mp3").write_bytes(b"x" * 10)
(got / "02 Teil.m4b").write_bytes(b"x" * 20)
item = client.get("/api/import/scan").json()["items"][0]
assert item["formats"] == ["m4b", "mp3"]
assert item["size"] == 30
def test_extra_ebook_extensions_are_configurable(client, monkeypatch):
"""The exotic Calibre formats stay out of the scan until they are asked for."""
(client.downloads / "Der Lehrer.kepub").write_bytes(b"x")
assert client.get("/api/import/scan").json()["items"] == []
monkeypatch.setenv("WORDARR_EXTRA_EBOOK_EXTENSIONS", ".kepub")
importlib.reload(config_module)
try:
items = client.get("/api/import/scan").json()["items"]
assert [i["formats"] for i in items] == [["kepub"]]
finally:
monkeypatch.delenv("WORDARR_EXTRA_EBOOK_EXTENSIONS")
importlib.reload(config_module)
+18
View File
@@ -28,6 +28,9 @@ def server(tmp_path_factory):
(downloads / "Eine Folge").mkdir(parents=True)
for i in (1, 2):
(downloads / "Eine Folge" / f"{i:02d}.mp3").write_bytes(b"")
# one book in three formats, the case the format column exists for
for ext in (".epub", ".azw3", ".pdf"):
(downloads / f"Der Lehrer{ext}").write_bytes(b"x" * 2048)
port = _free_port()
proc = subprocess.Popen(
[sys.executable, "-m", "uvicorn", "wordarr.main:app", "--port", str(port)],
@@ -106,3 +109,18 @@ def test_import_dialog_opens_and_closes(page):
page.keyboard.press("Escape")
page.wait_for_timeout(150)
assert not page.locator("#quick-dialog").is_visible()
def test_format_tags_and_the_format_filter(page):
page.click("nav button[data-view=import]")
page.click("#scan-btn")
page.wait_for_selector("[data-quick]")
tags = page.locator("#import-table .tag.fmt").all_text_contents()
assert "azw3 · 2,0 KB" in tags
assert "mp3" in " ".join(tags) # the audiobook folder is labelled too
page.select_option("#import-filter-format", "epub")
rows = page.locator("#import-table tbody tr")
assert rows.count() == 1
assert "epub" in rows.first.locator(".tag.fmt").text_content()