test(file-summary): 增加 Playwright 端到端测试

This commit is contained in:
2026-06-06 10:32:18 +08:00
parent 77db0d978a
commit 311eb1b129
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
from pathlib import Path
import pytest
from review_agent.models import Conversation
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.objects.create(user=user, title="E2E 会话")
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()
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()