forked from reflex-dev/reflex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_shared_state.py
76 lines (54 loc) · 1.63 KB
/
test_shared_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""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 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