UI updates continue. Focus on Sources

This commit is contained in:
Jim Lancaster
2026-08-02 18:41:09 -05:00
parent 0ab7ad50f2
commit 49e2e48df1
10 changed files with 398 additions and 39 deletions
+2 -1
View File
@@ -218,10 +218,11 @@ class TestDocumentsPageRendering:
return str(target.id)
document_id = asyncio.run(_seed())
response = client.get(f"/ui/documents/{document_id}/sources")
response = client.get(f"/ui/sources?document_id={document_id}")
assert response.status_code == 200
assert "Sources for Target" in response.text
assert "Back to Document" in response.text
assert "target_page.png" in response.text
assert "other_page.png" not in response.text
+2
View File
@@ -14,9 +14,11 @@ class TestPageRegistration:
upload_response = client.get("/ui/upload", follow_redirects=False)
documents_response = client.get("/ui/documents")
people_response = client.get("/ui/people")
sources_response = client.get("/ui/sources")
jobs_response = client.get("/ui/jobs")
assert upload_response.status_code == 307
assert documents_response.status_code == 200
assert people_response.status_code == 200
assert sources_response.status_code == 200
assert jobs_response.status_code == 200
+139
View File
@@ -0,0 +1,139 @@
"""Tests for the sources page routes."""
import asyncio
from pathlib import Path
import pytest
from sqlmodel import select
from transcription.db import session_scope
from transcription.db.models import Document
from transcription.db.models import Job
from transcription.db.models import Source
@pytest.mark.integration
class TestSourcesPageRendering:
"""Verify source list and detail routes render expected states."""
def test_sources_page_renders_empty_state(self, app_client):
_, client = app_client
response = client.get("/ui/sources")
assert response.status_code == 200
assert "Sources" in response.text
assert "No sources added yet." in response.text
def test_sources_page_lists_seeded_sources(self, app_client):
_, client = app_client
async def _seed() -> None:
async with session_scope() as session:
document = Document(name="Source Document", document_type="letter")
session.add(document)
await session.flush()
session.add(
Source(
document_id=document.id,
page_number=1,
upload_name="page_one.png",
filename="stored_page_one.png",
file_path="/tmp/stored_page_one.png",
)
)
await session.commit()
asyncio.run(_seed())
response = client.get("/ui/sources")
assert response.status_code == 200
assert "Page 1: page_one.png" in response.text
assert "stored_page_one.png" in response.text
def test_sources_page_filters_to_document_context(self, app_client):
_, client = app_client
async def _seed() -> str:
async with session_scope() as session:
target = Document(name="Target", document_type="letter")
other = Document(name="Other", document_type="record")
session.add(target)
session.add(other)
await session.flush()
session.add(
Source(
document_id=target.id,
page_number=1,
upload_name="target_page.png",
filename="target_stored.png",
file_path="/tmp/target_stored.png",
)
)
session.add(
Source(
document_id=other.id,
page_number=1,
upload_name="other_page.png",
filename="other_stored.png",
file_path="/tmp/other_stored.png",
)
)
await session.commit()
return str(target.id)
document_id = asyncio.run(_seed())
response = client.get(f"/ui/sources?document_id={document_id}")
assert response.status_code == 200
assert "Sources for Target" in response.text
assert "Back to Document" in response.text
assert "target_page.png" in response.text
assert "other_page.png" not in response.text
def test_sources_page_filters_to_job_context(self, app_client, seed_job):
_, client = app_client
job_id = seed_job(filename="job-page.png", transcription_text="job text")
response = client.get(f"/ui/sources?job_id={job_id}")
assert response.status_code == 200
assert "Sources for Job" in response.text
assert "Back to Job" in response.text
assert "job-page.png" in response.text
def test_source_detail_page_renders_preview_and_revision_box(self, app_client, seed_job):
_, client = app_client
fixture_path = Path(__file__).resolve().parents[1] / "fixtures" / "images" / "valid" / "small_png.png"
job_id = seed_job(
filename="detail-source.png",
transcription_text="original transcription text",
revision_text="human revision text",
source_file=fixture_path,
)
async def _get_source_id() -> str:
async with session_scope() as session:
job = await session.get(Job, job_id)
assert job is not None
source = (
await session.exec(select(Source).where(Source.document_id == job.document_id))
).first()
assert source is not None
return str(source.id)
source_id = asyncio.run(_get_source_id())
response = client.get(f"/ui/sources/{source_id}")
assert response.status_code == 200
assert "Source detail-source.png" in response.text
assert "Transcription text" in response.text
assert "original transcription text" in response.text
assert "Revision text" in response.text
assert "human revision text" in response.text
assert "Page number:" in response.text
assert "Stored filename:" in response.text