- 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>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
"""E2E tests for the home page."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
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(re.compile("No Hype AI"))
|
|
|
|
|
|
@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()
|