Files
main-site/e2e/test_article_detail.py
codex_a 4992b0cb9d
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 1m32s
fix: resolve 5 E2E test failures from first CI run
- test_homepage_title_contains_brand: to_have_title() requires a string or
  regex, not a lambda; switch to re.compile('No Hype AI')
- test_granular_preferences_save_dismisses_banner: wrong element clicked to
  open <details>; use 'details summary' locator directly
- test_subscribe_invalid_email_shows_error: browser HTML5 email validation
  swallows the submit event before the JS handler fires; add 'novalidate' via
  evaluate() so the fetch still runs and the server returns 400
- test_copy_link_button_updates_text: clipboard API unavailable in headless
  Docker; add polyfill + pre-grant permissions in conftest page fixture so
  the JS success path runs and button text becomes 'Copied'
- test_comments_section_absent_when_disabled: guard against Wagtail's
  add_child() resetting BooleanField defaults by calling an explicit
  .update(comments_enabled=False) + re-setting on the instance before
  save_revision().publish(); also tighten test to assert 200 + correct title

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-28 19:47:13 +00:00

72 lines
2.5 KiB
Python

"""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()
copy_btn.click()
# Clipboard polyfill in conftest ensures writeText resolves; button shows "Copied"
expect(copy_btn).to_have_text("Copied")