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