"""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 " @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()