Skip to content

scroll_component

django_spire.testing.playwright.components.scroll_component

SCROLL_SELECTOR = '[data-scroll-component]' module-attribute

ScrollComponent

Playwright component for django_spire/component/scroll/scroll.html, the scroll a BaseScrollComponent renders.

Row markup belongs to the consumer, so pass the selector matching one row of the page under test. The first scroll on the page is used unless root_selector names the element that carries a particular scroll's x-data:

scroll = ScrollComponent(page, row_selector='tbody tr[data-scroll-key]')
scroll.scroll_until_row_count(60)
assert scroll.state()['hasMore'] is False
Source code in django_spire/testing/playwright/components/scroll_component.py
def __init__(
    self,
    page: Page,
    row_selector: str,
    root_selector: str | None = None,
) -> None:
    self.page = page
    self.row_selector = row_selector
    self.root_selector = root_selector

page = page instance-attribute

row_selector = row_selector instance-attribute

root_selector = root_selector instance-attribute

data_expression property

rows property

state_expression property

JavaScript for the scroll's state, to embed in an evaluate that must read it in the same turn as something else.

reload_items

Reload the list and return its state before it loads any further batch.

Source code in django_spire/testing/playwright/components/scroll_component.py
def reload_items(self) -> dict[str, Any]:
    """Reload the list and return its state before it loads any further batch."""
    return self.page.evaluate(f"""
        async () => {{
            await {self.data_expression}.reloadItems()

            return {self.state_expression}
        }}
    """)

row_count

Source code in django_spire/testing/playwright/components/scroll_component.py
def row_count(self) -> int:
    return self.rows.count()

scroll_to_bottom

Source code in django_spire/testing/playwright/components/scroll_component.py
def scroll_to_bottom(self) -> None:
    self.page.mouse.wheel(0, 100_000)

scroll_until_row_count

Source code in django_spire/testing/playwright/components/scroll_component.py
def scroll_until_row_count(self, count: int) -> None:
    self.rows.first.wait_for()
    shown = self.row_count()

    while shown < count:
        self.scroll_to_bottom()
        self.wait_for_row_count_above(shown)
        shown = self.row_count()

    self.wait_until_idle()

state

Source code in django_spire/testing/playwright/components/scroll_component.py
def state(self) -> dict[str, Any]:
    return self.page.evaluate(f'() => {self.state_expression}')

wait_for_row_count

Source code in django_spire/testing/playwright/components/scroll_component.py
def wait_for_row_count(self, count: int) -> None:
    expect(self.rows).to_have_count(count)

wait_for_row_count_above

Source code in django_spire/testing/playwright/components/scroll_component.py
def wait_for_row_count_above(self, count: int) -> None:
    self.rows.nth(count).wait_for(state='attached')

wait_until_idle

Source code in django_spire/testing/playwright/components/scroll_component.py
def wait_until_idle(self) -> None:
    self.page.wait_for_function(f'() => !{self.data_expression}.isLoading')