- 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>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""E2E tests for the article index page."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_article_index_loads(page: Page, base_url: str) -> None:
|
|
page.goto(f"{base_url}/articles/", wait_until="networkidle")
|
|
expect(page.get_by_role("heading", level=1)).to_be_visible()
|
|
# At least one article card must be present after seeding
|
|
expect(page.locator("main article").first).to_be_visible()
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_tag_filter_shows_tagged_articles(page: Page, base_url: str) -> None:
|
|
page.goto(f"{base_url}/articles/", wait_until="networkidle")
|
|
# The seeded "AI Tools" tag link must be present
|
|
tag_link = page.get_by_role("link", name="AI Tools")
|
|
expect(tag_link).to_be_visible()
|
|
tag_link.click()
|
|
page.wait_for_load_state("networkidle")
|
|
|
|
# URL should now contain ?tag=ai-tools
|
|
assert "tag=ai-tools" in page.url
|
|
|
|
# The tagged article must appear; no-tag articles may be absent
|
|
expect(page.get_by_text("Tagged Article")).to_be_visible()
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_all_tag_clears_filter(page: Page, base_url: str) -> None:
|
|
# Start with the tag filter applied
|
|
page.goto(f"{base_url}/articles/?tag=ai-tools", wait_until="networkidle")
|
|
|
|
# Clicking "All" should return to unfiltered list
|
|
page.get_by_role("link", name="All").click()
|
|
page.wait_for_load_state("networkidle")
|
|
assert "tag=" not in page.url
|
|
# All seeded articles should now be visible
|
|
expect(page.locator("main article").first).to_be_visible()
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_article_card_navigates_to_detail(page: Page, base_url: str) -> None:
|
|
page.goto(f"{base_url}/articles/", wait_until="networkidle")
|
|
first_link = page.locator("main article a").first
|
|
expect(first_link).to_be_visible()
|
|
|
|
href = first_link.get_attribute("href")
|
|
assert href, "Article card must have an href"
|
|
|
|
first_link.click()
|
|
page.wait_for_load_state("networkidle")
|
|
|
|
# We should be on an article detail page
|
|
expect(page.get_by_role("heading", level=1)).to_be_visible()
|