- Create e2e/ directory with 7 test modules covering: - Home page: title, nav links, theme toggle, newsletter form - Cookie consent: accept all, reject all, granular prefs, persistence - Article index: loads, tag filter, click-through navigation - Article detail: title/read-time, share section, comments, newsletter aside, related - Comments: valid submit → redirect, empty body → error display, disabled check - Newsletter: JS confirmation message, invalid email error, aside form, duplicate - Feeds: RSS/sitemap/robots.txt validity, tag feed, seeded content present - Extend seed_e2e_content management command with tagged article, about page, no-comments article, and legal pages for richer test coverage - Add seed command tests (create + idempotency) to keep coverage ≥ 90% - Add pr-e2e CI job (runs on pull_request): builds image, starts postgres + app, installs playwright, runs pytest e2e/ - Update nightly-e2e to run full e2e/ suite alongside legacy journey test - Add --ignore=e2e to unit-test pytest step (coverage must not include browser tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
"""E2E tests for the comment submission flow."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
|
|
ARTICLE_SLUG = "nightly-playwright-journey"
|
|
|
|
|
|
def _go_to_article(page: Page, base_url: str) -> None:
|
|
page.goto(f"{base_url}/articles/{ARTICLE_SLUG}/", wait_until="networkidle")
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_valid_comment_submission_redirects(page: Page, base_url: str) -> None:
|
|
_go_to_article(page, base_url)
|
|
|
|
# Fill the main comment form (not a reply form)
|
|
form = page.locator("form[action]").filter(has=page.get_by_role("button", name="Post comment"))
|
|
form.locator('input[name="author_name"]').fill("E2E Tester")
|
|
form.locator('input[name="author_email"]').fill("e2e@example.com")
|
|
form.locator('textarea[name="body"]').fill("This is a test comment from Playwright.")
|
|
form.get_by_role("button", name="Post comment").click()
|
|
|
|
# Successful submission redirects back to the article with ?commented=1
|
|
page.wait_for_url(lambda url: "commented=1" in url, timeout=10_000)
|
|
assert "commented=1" in page.url
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_empty_body_shows_form_errors(page: Page, base_url: str) -> None:
|
|
_go_to_article(page, base_url)
|
|
|
|
form = page.locator("form[action]").filter(has=page.get_by_role("button", name="Post comment"))
|
|
form.locator('input[name="author_name"]').fill("E2E Tester")
|
|
form.locator('input[name="author_email"]').fill("e2e@example.com")
|
|
form.locator('textarea[name="body"]').fill(" ") # whitespace-only body
|
|
form.get_by_role("button", name="Post comment").click()
|
|
page.wait_for_load_state("networkidle")
|
|
|
|
# The page re-renders with the error summary visible
|
|
expect(page.locator('[aria-label="Comment form errors"]')).to_be_visible()
|
|
# URL must NOT have ?commented=1 — form was not accepted
|
|
assert "commented=1" not in page.url
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_comments_section_absent_when_disabled(page: Page, base_url: str) -> None:
|
|
"""Article with comments_enabled=False must not show the comments section."""
|
|
page.goto(f"{base_url}/articles/e2e-no-comments/", wait_until="networkidle")
|
|
expect(page.get_by_role("heading", name="Comments")).to_have_count(0)
|
|
expect(page.get_by_role("button", name="Post comment")).to_have_count(0)
|