- 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>
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""E2E tests for the cookie consent banner."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
|
|
|
|
def _open_fresh_page(page: Page, url: str) -> None:
|
|
"""Navigate to URL with no existing consent cookie (fresh context guarantees this)."""
|
|
page.goto(url, wait_until="networkidle")
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_banner_visible_on_first_visit(page: Page, base_url: str) -> None:
|
|
_open_fresh_page(page, f"{base_url}/")
|
|
expect(page.locator("#cookie-banner")).to_be_visible()
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_accept_all_dismisses_banner(page: Page, base_url: str) -> None:
|
|
_open_fresh_page(page, f"{base_url}/")
|
|
banner = page.locator("#cookie-banner")
|
|
expect(banner).to_be_visible()
|
|
page.get_by_role("button", name="Accept all").first.click()
|
|
page.wait_for_load_state("networkidle")
|
|
expect(banner).to_have_count(0)
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_reject_all_dismisses_banner(page: Page, base_url: str) -> None:
|
|
_open_fresh_page(page, f"{base_url}/")
|
|
banner = page.locator("#cookie-banner")
|
|
expect(banner).to_be_visible()
|
|
page.get_by_role("button", name="Reject all").first.click()
|
|
page.wait_for_load_state("networkidle")
|
|
expect(banner).to_have_count(0)
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_granular_preferences_save_dismisses_banner(page: Page, base_url: str) -> None:
|
|
_open_fresh_page(page, f"{base_url}/")
|
|
banner = page.locator("#cookie-banner")
|
|
expect(banner).to_be_visible()
|
|
|
|
# Click the <summary> element to expand <details> inside the banner
|
|
banner.locator("details summary").click()
|
|
|
|
# Analytics checkbox is now revealed; check it and save
|
|
analytics_checkbox = banner.locator('input[name="analytics"]')
|
|
expect(analytics_checkbox).to_be_visible()
|
|
analytics_checkbox.check()
|
|
|
|
# Submit granular preferences
|
|
page.get_by_role("button", name="Save preferences").click()
|
|
page.wait_for_load_state("networkidle")
|
|
expect(banner).to_have_count(0)
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_banner_absent_after_consent_cookie_set(page: Page, base_url: str) -> None:
|
|
"""After accepting consent, subsequent page loads must not show the banner."""
|
|
_open_fresh_page(page, f"{base_url}/")
|
|
# Accept consent
|
|
page.get_by_role("button", name="Accept all").first.click()
|
|
page.wait_for_load_state("networkidle")
|
|
|
|
# Navigate to another page in the same context — cookie should persist
|
|
page.goto(f"{base_url}/articles/", wait_until="networkidle")
|
|
expect(page.locator("#cookie-banner")).to_have_count(0)
|