
* WiP * Save the var from get_var_name * flatten StateManagerRedis.get_state algorithm simplify fetching of states and avoid repeatedly fetching the same state * Get all the states in a single redis round-trip * update docstrings in StateManagerRedis * Move computed var dep tracking to separate module * Fix pre-commit issues * ComputedVar.add_dependency: explicitly dependency declaration Allow var dependencies to be added at runtime, for example, when defining a ComponentState that depends on vars that cannot be known statically. Fix more pyright issues. * Fix/ignore more pyright issues from recent merge * handle cleaning out _potentially_dirty_states on reload * ignore accessed attributes missing on state class these might be added dynamically later in which case we recompute the dependency tracking dicts... if not, they'll blow up anyway at runtime. * fix playwright tests, which insist on running an asyncio loop --------- Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
104 lines
3.0 KiB
Python
104 lines
3.0 KiB
Python
"""Integration tests for table and related components."""
|
|
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
|
|
from reflex.testing import AppHarness
|
|
|
|
expected_col_headers = ["Name", "Age", "Location"]
|
|
expected_row_headers = ["John", "Jane", "Joe"]
|
|
expected_cells_data = [
|
|
["30", "New York"],
|
|
["31", "San Fransisco"],
|
|
["32", "Los Angeles"],
|
|
]
|
|
|
|
|
|
def Table():
|
|
"""App using table component."""
|
|
import reflex as rx
|
|
|
|
app = rx.App(_state=rx.State)
|
|
|
|
@app.add_page
|
|
def index():
|
|
return rx.center(
|
|
rx.table.root(
|
|
rx.table.header(
|
|
rx.table.row(
|
|
rx.table.column_header_cell("Name"),
|
|
rx.table.column_header_cell("Age"),
|
|
rx.table.column_header_cell("Location"),
|
|
),
|
|
),
|
|
rx.table.body(
|
|
rx.table.row(
|
|
rx.table.row_header_cell("John"),
|
|
rx.table.cell(30),
|
|
rx.table.cell("New York"),
|
|
),
|
|
rx.table.row(
|
|
rx.table.row_header_cell("Jane"),
|
|
rx.table.cell(31),
|
|
rx.table.cell("San Fransisco"),
|
|
),
|
|
rx.table.row(
|
|
rx.table.row_header_cell("Joe"),
|
|
rx.table.cell(32),
|
|
rx.table.cell("Los Angeles"),
|
|
),
|
|
),
|
|
width="100%",
|
|
),
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def table_app(tmp_path_factory) -> Generator[AppHarness, None, None]:
|
|
"""Start Table app at tmp_path via AppHarness.
|
|
|
|
Args:
|
|
tmp_path_factory: pytest tmp_path_factory fixture
|
|
|
|
Yields:
|
|
running AppHarness instance
|
|
|
|
"""
|
|
with AppHarness.create(
|
|
root=tmp_path_factory.mktemp("table"),
|
|
app_source=Table,
|
|
) as harness:
|
|
assert harness.app_instance is not None, "app is not running"
|
|
yield harness
|
|
|
|
|
|
def test_table(page: Page, table_app: AppHarness):
|
|
"""Test that a table component is rendered properly.
|
|
|
|
Args:
|
|
table_app: Harness for Table app
|
|
page: Playwright page instance
|
|
"""
|
|
assert table_app.frontend_url is not None, "frontend url is not available"
|
|
|
|
page.goto(table_app.frontend_url)
|
|
table = page.get_by_role("table")
|
|
|
|
# Check column headers
|
|
headers = table.get_by_role("columnheader")
|
|
for header, exp_value in zip(headers.all(), expected_col_headers, strict=True):
|
|
expect(header).to_have_text(exp_value)
|
|
|
|
# Check rows headers
|
|
rows = table.get_by_role("rowheader")
|
|
for row, expected_row in zip(rows.all(), expected_row_headers, strict=True):
|
|
expect(row).to_have_text(expected_row)
|
|
|
|
# Check cells
|
|
rows = table.get_by_role("cell").all_inner_texts()
|
|
for i, expected_row in enumerate(expected_cells_data):
|
|
idx = i * 2
|
|
assert [rows[idx], rows[idx + 1]] == expected_row
|