Skip to content

theme_selector

django_spire.testing.playwright.components.theme_selector

ThemeSelector

Playwright component for django_spire/theme/element/theme_selector.html

Source code in django_spire/testing/playwright/components/theme_selector.py
def __init__(self, page: Page) -> None:
    self.page = page

page = page instance-attribute

icon property

click

Source code in django_spire/testing/playwright/components/theme_selector.py
def click(self) -> None:
    self.icon.click()

get_current_mode

Source code in django_spire/testing/playwright/components/theme_selector.py
def get_current_mode(self) -> str:
    html = self.page.locator('html')
    return html.get_attribute('data-theme') or 'light'

get_current_theme_family

Source code in django_spire/testing/playwright/components/theme_selector.py
def get_current_theme_family(self) -> str:
    html = self.page.locator('html')
    return html.get_attribute('data-theme-family') or ''

is_dark_mode

Source code in django_spire/testing/playwright/components/theme_selector.py
def is_dark_mode(self) -> bool:
    return self.get_current_mode() == 'dark'

is_light_mode

Source code in django_spire/testing/playwright/components/theme_selector.py
def is_light_mode(self) -> bool:
    return self.get_current_mode() == 'light'

is_visible

Source code in django_spire/testing/playwright/components/theme_selector.py
def is_visible(self) -> bool:
    return self.icon.is_visible()

toggle

Source code in django_spire/testing/playwright/components/theme_selector.py
def toggle(self) -> None:
    self.click()

wait_for_theme_change

Source code in django_spire/testing/playwright/components/theme_selector.py
def wait_for_theme_change(self, expected_mode: str, timeout: int = 5000) -> None:
    self.page.wait_for_function(
        f'() => document.documentElement.getAttribute("data-theme") === "{expected_mode}"',
        timeout=timeout
    )