Skip to content

Commit 3c1946d

Browse files
wip minified state integration test
1 parent 337f4cb commit 3c1946d

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""Integration tests for minified state names."""
2+
3+
from __future__ import annotations
4+
5+
import time
6+
from typing import Generator, Type
7+
8+
import pytest
9+
from selenium.webdriver.common.by import By
10+
from selenium.webdriver.remote.webdriver import WebDriver
11+
from selenium.webdriver.support import expected_conditions as EC
12+
from selenium.webdriver.support.ui import WebDriverWait
13+
14+
from reflex.testing import AppHarness
15+
16+
17+
def TestApp():
18+
"""A test app for minified state names."""
19+
import reflex as rx
20+
21+
class TestAppState(rx.State):
22+
"""State for the TestApp app."""
23+
24+
pass
25+
26+
app = rx.App()
27+
28+
@app.add_page
29+
def index():
30+
return rx.vstack(
31+
rx.input(
32+
value=TestAppState.router.session.client_token,
33+
is_read_only=True,
34+
id="token",
35+
),
36+
)
37+
38+
39+
@pytest.fixture(scope="module")
40+
def test_app(
41+
app_harness_env: Type[AppHarness], tmp_path_factory: pytest.TempPathFactory
42+
) -> Generator[AppHarness, None, None]:
43+
"""Start TestApp app at tmp_path via AppHarness.
44+
45+
Args:
46+
app_harness_env: either AppHarness (dev) or AppHarnessProd (prod)
47+
tmp_path_factory: pytest tmp_path_factory fixture
48+
49+
Yields:
50+
running AppHarness instance
51+
52+
"""
53+
with app_harness_env.create(
54+
root=tmp_path_factory.mktemp("test_app"),
55+
app_name=f"testapp_{app_harness_env.__name__.lower()}",
56+
app_source=TestApp, # type: ignore
57+
) as harness:
58+
yield harness
59+
60+
61+
@pytest.fixture
62+
def driver(test_app: AppHarness) -> Generator[WebDriver, None, None]:
63+
"""Get an instance of the browser open to the test_app app.
64+
65+
Args:
66+
test_app: harness for TestApp app
67+
68+
Yields:
69+
WebDriver instance.
70+
71+
"""
72+
assert test_app.app_instance is not None, "app is not running"
73+
driver = test_app.frontend()
74+
try:
75+
yield driver
76+
finally:
77+
driver.quit()
78+
79+
80+
def test_minified_states(
81+
test_app: AppHarness,
82+
driver: WebDriver,
83+
) -> None:
84+
"""Test minified state names.
85+
86+
Args:
87+
test_app: harness for TestApp
88+
driver: WebDriver instance.
89+
90+
"""
91+
assert test_app.app_instance is not None, "app is not running"
92+
93+
# get a reference to the connected client
94+
token_input = driver.find_element(By.ID, "token")
95+
assert token_input
96+
97+
# wait for the backend connection to send the token
98+
token = test_app.poll_for_value(token_input)
99+
assert token

0 commit comments

Comments
 (0)