61 lines
2.5 KiB
Python
61 lines
2.5 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from review_agent.models import Conversation, Message
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def _browser_path() -> str | None:
|
|
candidates = [
|
|
Path(r"C:\Program Files\Google\Chrome\Application\chrome.exe"),
|
|
Path(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"),
|
|
]
|
|
for candidate in candidates:
|
|
if candidate.exists():
|
|
return str(candidate)
|
|
return None
|
|
|
|
|
|
def test_file_summary_panel_desktop_and_mobile_with_playwright(live_server, django_user_model):
|
|
playwright_api = pytest.importorskip("playwright.sync_api")
|
|
executable_path = _browser_path()
|
|
if not executable_path:
|
|
pytest.skip("No Chrome or Edge executable available for Playwright E2E.")
|
|
|
|
user = django_user_model.objects.create_user(username="e2e_user", password="e2e-pass-123")
|
|
conversation = Conversation.objects.create(user=user, title="E2E 会话")
|
|
Message.objects.create(
|
|
conversation=conversation,
|
|
role=Message.Role.ASSISTANT,
|
|
content=(
|
|
"文件目录与页数汇总已完成。\n\n"
|
|
"| 序号 | 文件名 | 页数 | 状态 |\n"
|
|
"| --- | --- | --- | --- |\n"
|
|
"| 1 | a.pdf | 4 | success |\n\n"
|
|
"[下载 Markdown 报告](/api/review-agent/file-summary/exports/1/download/)"
|
|
),
|
|
)
|
|
|
|
with playwright_api.sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True, executable_path=executable_path)
|
|
page = browser.new_page(viewport={"width": 1440, "height": 900})
|
|
page.goto(f"{live_server.url}/login/")
|
|
page.fill('input[name="username"]', "e2e_user")
|
|
page.fill('input[name="password"]', "e2e-pass-123")
|
|
page.click('button[type="submit"]')
|
|
page.wait_for_url(f"{live_server.url}/")
|
|
|
|
playwright_api.expect(page.locator("#summaryPanel")).to_be_visible()
|
|
playwright_api.expect(page.locator("#uploadDropzone")).to_be_visible()
|
|
playwright_api.expect(page.locator("#workflowCardList")).to_be_visible()
|
|
playwright_api.expect(page.locator(".message.assistant table")).to_be_visible()
|
|
playwright_api.expect(page.locator('.message.assistant a[href="/api/review-agent/file-summary/exports/1/download/"]')).to_be_visible()
|
|
|
|
page.set_viewport_size({"width": 390, "height": 844})
|
|
playwright_api.expect(page.locator("#summaryPanel")).to_be_visible()
|
|
playwright_api.expect(page.locator("#sidebar")).not_to_be_in_viewport()
|
|
browser.close()
|