reflex/tests/integration/test_shared_state.py
Thomas Brandého 3f538865b5
reorganize all tests in a single top folder (#3981)
* lift node version restraint to allow more recent version if already installed

* add node test for latest version

* change python version

* use purple for debug logs

* update workflow

* add playwright dev dependency

* update workflow

* change test

* oops

* improve test

* update test

* fix tests

* mv units tests to a subfolder

* reorganize tests

* fix install

* update test_state

* revert node changes and only keep new tests organization

* move integration tests in tests/integration

* fix integration workflow

* fix dockerfile workflow

* fix dockerfile workflow 2

* fix shared_state
2024-09-26 01:22:52 +02:00

78 lines
1.6 KiB
Python

"""Test shared state."""
from __future__ import annotations
from typing import Generator
import pytest
from reflex.testing import AppHarness, WebDriver
def SharedStateApp():
"""Test that shared state works as expected."""
import reflex as rx
from tests.integration.shared.state import SharedState
class State(SharedState):
pass
def index() -> rx.Component:
return rx.vstack()
app = rx.App()
app.add_page(index)
@pytest.fixture
def shared_state(
tmp_path_factory,
) -> Generator[AppHarness, None, None]:
"""Start SharedStateApp 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("shared_state"),
app_source=SharedStateApp, # type: ignore
) as harness:
yield harness
@pytest.fixture
def driver(shared_state: AppHarness) -> Generator[WebDriver, None, None]:
"""Get an instance of the browser open to the shared_state app.
Args:
shared_state: harness for SharedStateApp
Yields:
WebDriver instance.
"""
assert shared_state.app_instance is not None, "app is not running"
driver = shared_state.frontend()
try:
yield driver
finally:
driver.quit()
def test_shared_state(
shared_state: AppHarness,
driver: WebDriver,
):
"""Test that 2 AppHarness instances can share a state (f.e. from a library).
Args:
shared_state: harness for SharedStateApp.
driver: WebDriver instance.
"""
assert shared_state.app_instance is not None