Skip to content

lazy_tab

django_spire.testing.playwright.components.lazy_tab

LazyTab

Playwright component for django_spire/lazy_tab/lazy_tab.html

Source code in django_spire/testing/playwright/components/lazy_tab.py
def __init__(self, page: Page, container_selector: str, tab_id: str | None = None) -> None:
    self.container_selector = container_selector
    self.page = page
    self.tab_id = tab_id

selected_class = 'tab-item' class-attribute instance-attribute

container_selector = container_selector instance-attribute

page = page instance-attribute

tab_id = tab_id instance-attribute

container property

sections property

triggers property

click_tab

Source code in django_spire/testing/playwright/components/lazy_tab.py
def click_tab(self, index: int) -> None:
    self.get_trigger(index).click()

get_section

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_section(self, index: int) -> Locator:
    return self.sections.nth(index)

get_section_count

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_section_count(self) -> int:
    return self.sections.count()

get_trigger

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_trigger(self, index: int) -> Locator:
    return self.triggers.nth(index)

get_trigger_count

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_trigger_count(self) -> int:
    return self.triggers.count()

get_url_param

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_url_param(self) -> str | None:
    if not self.tab_id:
        return None

    url = self.page.url
    match = re.search(f'{self.tab_id}=([^&]+)', url)

    if match:
        return match.group(1)

    return None

get_visible_section

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_visible_section(self) -> Locator | None:
    for i in range(self.sections.count()):
        section = self.sections.nth(i)

        if section.is_visible():
            return section

    return None

get_visible_section_text

Source code in django_spire/testing/playwright/components/lazy_tab.py
def get_visible_section_text(self) -> str:
    section = self.get_visible_section()

    if section:
        return section.inner_text()

    return ''

is_loading

Source code in django_spire/testing/playwright/components/lazy_tab.py
def is_loading(self, index: int) -> bool:
    section = self.get_section(index)
    spinner = section.locator('.spinner-border')
    return spinner.is_visible()

is_tab_selected

Source code in django_spire/testing/playwright/components/lazy_tab.py
def is_tab_selected(self, index: int) -> bool:
    trigger = self.get_trigger(index)
    classes = trigger.get_attribute('class') or ''
    return self.selected_class in classes

wait_for_section_content

Source code in django_spire/testing/playwright/components/lazy_tab.py
def wait_for_section_content(self, index: int, timeout: int = 5000) -> None:
    section = self.get_section(index)
    section.locator('.spinner-border').wait_for(state='hidden', timeout=timeout)

wait_for_tabs_to_load

Source code in django_spire/testing/playwright/components/lazy_tab.py
def wait_for_tabs_to_load(self) -> None:
    self.triggers.first.wait_for()