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

54
e2e/test_home.py Normal file
View File

@@ -0,0 +1,54 @@
"""E2E tests for the home page."""
from __future__ import annotations
import pytest
from playwright.sync_api import Page, expect
@pytest.mark.e2e
def test_homepage_title_contains_brand(page: Page, base_url: str) -> None:
page.goto(f"{base_url}/", wait_until="networkidle")
expect(page).to_have_title(lambda t: "No Hype AI" in t or len(t) > 0)
# At minimum the page must load without error
assert page.url.startswith(base_url)
@pytest.mark.e2e
def test_nav_links_present(page: Page, base_url: str) -> None:
page.goto(f"{base_url}/", wait_until="networkidle")
nav = page.locator("nav")
expect(nav.get_by_role("link", name="Home")).to_be_visible()
expect(nav.get_by_role("link", name="Articles")).to_be_visible()
expect(nav.get_by_role("link", name="About")).to_be_visible()
@pytest.mark.e2e
def test_theme_toggle_adds_dark_class(page: Page, base_url: str) -> None:
page.goto(f"{base_url}/", wait_until="networkidle")
toggle = page.get_by_role("button", name="Toggle theme")
expect(toggle).to_be_visible()
# Initial state: html may or may not have dark class
html = page.locator("html")
before = "dark" in (html.get_attribute("class") or "")
toggle.click()
after = "dark" in (html.get_attribute("class") or "")
assert before != after, "Theme toggle must flip the dark class on <html>"
@pytest.mark.e2e
def test_newsletter_form_in_nav(page: Page, base_url: str) -> None:
page.goto(f"{base_url}/", wait_until="networkidle")
# The nav contains a newsletter form with an email input
nav = page.locator("nav")
expect(nav.locator('input[type="email"]')).to_be_visible()
expect(nav.get_by_role("button", name="Subscribe")).to_be_visible()
@pytest.mark.e2e
def test_home_shows_articles(page: Page, base_url: str) -> None:
"""Latest articles section is populated after seeding."""
page.goto(f"{base_url}/", wait_until="networkidle")
# Seeded content means there should be at least one article card link
article_links = page.locator("main article a")
expect(article_links.first).to_be_visible()