feat: add comprehensive Playwright E2E test suite
Some checks failed
CI / nightly-e2e (pull_request) Has been skipped
CI / ci (pull_request) Successful in 1m22s
CI / pr-e2e (pull_request) Failing after 3m28s

- 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>
This commit is contained in:
codex_a
2026-02-28 19:30:43 +00:00
parent aeb0afb2ea
commit 9d323d2040
12 changed files with 643 additions and 8 deletions

View File

@@ -0,0 +1,73 @@
"""E2E tests for article detail pages."""
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_article_title_visible(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
h1 = page.get_by_role("heading", level=1)
expect(h1).to_be_visible()
assert h1.inner_text().strip() != ""
@pytest.mark.e2e
def test_article_read_time_visible(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
# Read time is rendered as "N min read"
expect(page.get_by_text("min read")).to_be_visible()
@pytest.mark.e2e
def test_article_share_section_present(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
share_section = page.get_by_role("region", name="Share this article")
expect(share_section).to_be_visible()
expect(share_section.get_by_role("link", name="Share on X")).to_be_visible()
expect(share_section.get_by_role("link", name="Share on LinkedIn")).to_be_visible()
expect(share_section.get_by_role("button", name="Copy link")).to_be_visible()
@pytest.mark.e2e
def test_article_comments_section_present(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
# The article has comments_enabled=True
expect(page.get_by_role("heading", name="Comments")).to_be_visible()
expect(page.get_by_role("button", name="Post comment")).to_be_visible()
@pytest.mark.e2e
def test_article_newsletter_aside_present(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
# There's a Newsletter aside within the article page
aside = page.locator("aside")
expect(aside).to_be_visible()
expect(aside.locator('input[type="email"]')).to_be_visible()
@pytest.mark.e2e
def test_article_related_section_present(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
# Related section heading
expect(page.get_by_role("heading", name="Related")).to_be_visible()
@pytest.mark.e2e
def test_copy_link_button_updates_text(page: Page, base_url: str) -> None:
_go_to_article(page, base_url)
copy_btn = page.get_by_role("button", name="Copy link")
expect(copy_btn).to_be_visible()
# Grant clipboard permission and click
page.context.grant_permissions(["clipboard-read", "clipboard-write"])
copy_btn.click()
# Button text should change to "Copied" after click
expect(copy_btn).to_have_text("Copied")