a7a88218c3
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/20bbea80-fdfd-42d2-b0c2-756ca25b240b
124 lines
5.2 KiB
Python
124 lines
5.2 KiB
Python
"""Tests for the comments and annotations UI on the file detail page."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.models import FileRecord
|
|
|
|
|
|
def _create_file(db_session, tmp_path) -> FileRecord:
|
|
"""Create a minimal FileRecord with a real file path for the detail page."""
|
|
file_path = tmp_path / "test.pdf"
|
|
file_path.write_bytes(b"%PDF-1.4")
|
|
f = FileRecord(
|
|
filehash="uihash123",
|
|
original_filename="test.pdf",
|
|
local_filename=str(file_path),
|
|
original_file_path=str(file_path),
|
|
file_size=1024,
|
|
mime_type="application/pdf",
|
|
)
|
|
db_session.add(f)
|
|
db_session.commit()
|
|
db_session.refresh(f)
|
|
return f
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestCommentsUIRendering:
|
|
"""Verify the file detail page includes the comments panel HTML."""
|
|
|
|
def test_detail_page_contains_comments_section(self, client: TestClient, db_session, tmp_path):
|
|
"""The detail page should render the comments panel container."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'id="comments-list"' in html
|
|
assert 'id="comment-form"' in html
|
|
assert 'id="comment-input"' in html
|
|
|
|
def test_detail_page_contains_annotations_section(self, client: TestClient, db_session, tmp_path):
|
|
"""The detail page should render the annotations panel container."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'id="annotations-list"' in html
|
|
assert 'id="annotation-form"' in html
|
|
assert 'id="annotation-content-input"' in html
|
|
|
|
def test_detail_page_loads_comments_js(self, client: TestClient, db_session, tmp_path):
|
|
"""The detail page should include the comments JavaScript file."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
assert "js/comments.js" in resp.text
|
|
|
|
def test_detail_page_loads_annotations_js(self, client: TestClient, db_session, tmp_path):
|
|
"""The detail page should include the annotations JavaScript file."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
assert "js/annotations.js" in resp.text
|
|
|
|
def test_detail_page_has_mention_dropdown(self, client: TestClient, db_session, tmp_path):
|
|
"""The mention autocomplete dropdown should be present."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
assert 'id="mention-dropdown"' in resp.text
|
|
|
|
def test_detail_page_has_annotation_form_fields(self, client: TestClient, db_session, tmp_path):
|
|
"""Annotation form should have page, type, and color inputs."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'id="annotation-page-input"' in html
|
|
assert 'id="annotation-type-input"' in html
|
|
assert 'id="annotation-color-input"' in html
|
|
|
|
def test_detail_page_has_collab_grid(self, client: TestClient, db_session, tmp_path):
|
|
"""Comments and annotations should be in a side-by-side grid layout."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
assert "collab-grid" in resp.text
|
|
|
|
def test_detail_page_no_comments_for_missing_file(self, client: TestClient):
|
|
"""When file is not found, no comments section should appear."""
|
|
resp = client.get("/files/99999/detail")
|
|
assert resp.status_code == 200
|
|
# The error block is shown, not the main content
|
|
assert 'id="comments-list"' not in resp.text
|
|
|
|
def test_detail_page_annotation_type_options(self, client: TestClient, db_session, tmp_path):
|
|
"""Annotation type selector should include all four types."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'value="note"' in html
|
|
assert 'value="highlight"' in html
|
|
assert 'value="underline"' in html
|
|
assert 'value="strikethrough"' in html
|
|
|
|
def test_detail_page_comments_panel_accessibility(self, client: TestClient, db_session, tmp_path):
|
|
"""Comments panel should have proper ARIA attributes."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'aria-live="polite"' in html
|
|
assert 'role="listbox"' in html
|
|
|
|
def test_detail_page_init_script(self, client: TestClient, db_session, tmp_path):
|
|
"""The init script should call initComments and initAnnotations."""
|
|
f = _create_file(db_session, tmp_path)
|
|
resp = client.get(f"/files/{f.id}/detail")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert "initComments" in html
|
|
assert "initAnnotations" in html
|