From 311eb1b129f92a0e6599673ad339ec6a266b606b Mon Sep 17 00:00:00 2001 From: bruce Date: Sat, 6 Jun 2026 10:32:18 +0800 Subject: [PATCH] =?UTF-8?q?test(file-summary):=20=E5=A2=9E=E5=8A=A0=20Play?= =?UTF-8?q?wright=20=E7=AB=AF=E5=88=B0=E7=AB=AF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + requirements.txt | 1 + tests/test_file_summary_e2e.py | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/test_file_summary_e2e.py diff --git a/.gitignore b/.gitignore index e652b65..28c1048 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ db.sqlite3 staticfiles/ media/ .pytest_cache/ +.tmp/ .idea/ diff --git a/requirements.txt b/requirements.txt index f26a954..f257506 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ openpyxl>=3.1 xlrd>=2.0 olefile>=0.47 py7zr>=0.21 +playwright>=1.60 diff --git a/tests/test_file_summary_e2e.py b/tests/test_file_summary_e2e.py new file mode 100644 index 0000000..4275e4b --- /dev/null +++ b/tests/test_file_summary_e2e.py @@ -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()