Skip to content

Commit 9e4ce1b

Browse files
adjust tests
1 parent a3bc40a commit 9e4ce1b

1 file changed

Lines changed: 42 additions & 17 deletions

File tree

tests/integration/test_hybrid_properties.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ def has_last_name(cls) -> Var[str]:
5757
"""
5858
return rx.cond(cls.last_name, "yes", "no")
5959

60+
@rx.var
61+
def full_name_backend(self) -> str:
62+
"""Expose the backend value of the `full_name` hybrid property.
63+
64+
Returns:
65+
str: The full name as evaluated by the backend property getter.
66+
"""
67+
return self.full_name
68+
69+
@rx.var
70+
def has_last_name_backend(self) -> str:
71+
"""Expose the backend value of the `has_last_name` hybrid property.
72+
73+
Returns:
74+
str: The has_last_name value as evaluated by the backend property getter.
75+
"""
76+
return self.has_last_name
77+
6078
def index() -> rx.Component:
6179
return rx.center(
6280
rx.vstack(
@@ -69,7 +87,15 @@ def index() -> rx.Component:
6987
f"python_full_name: {State.python_full_name}", id="python_full_name"
7088
),
7189
rx.text(f"full_name: {State.full_name}", id="full_name"),
90+
rx.text(
91+
f"full_name_backend: {State.full_name_backend}",
92+
id="full_name_backend",
93+
),
7294
rx.text(f"has_last_name: {State.has_last_name}", id="has_last_name"),
95+
rx.text(
96+
f"has_last_name_backend: {State.has_last_name_backend}",
97+
id="has_last_name_backend",
98+
),
7399
rx.el.input(
74100
value=State.last_name,
75101
on_change=State.setvar("last_name"),
@@ -142,8 +168,7 @@ def token(hybrid_properties: AppHarness, driver: WebDriver) -> str:
142168
return token
143169

144170

145-
@pytest.mark.asyncio
146-
async def test_hybrid_properties(
171+
def test_hybrid_properties(
147172
hybrid_properties: AppHarness,
148173
driver: WebDriver,
149174
token: str,
@@ -153,28 +178,26 @@ async def test_hybrid_properties(
153178
Args:
154179
hybrid_properties: harness for HybridProperties app.
155180
driver: WebDriver instance.
156-
token: The token for the connected client.
181+
token: The token for the connected client (used to wait for backend connection).
157182
"""
158183
assert hybrid_properties.app_instance is not None
159-
160-
state_name = hybrid_properties.get_state_name("_state")
161-
full_state_name = hybrid_properties.get_full_state_name(["_state"])
162-
token = f"{token}_{full_state_name}"
163-
164-
state = (await hybrid_properties.get_state(token)).substates[state_name]
165-
assert state is not None
166-
assert state.full_name == "John Doe" # pyright: ignore[reportAttributeAccessIssue]
167-
assert state.has_last_name == "yes" # pyright: ignore[reportAttributeAccessIssue]
184+
assert token
168185

169186
full_name = driver.find_element(By.ID, "full_name")
170187
assert full_name.text == "full_name: John Doe"
171188

189+
full_name_backend = driver.find_element(By.ID, "full_name_backend")
190+
assert full_name_backend.text == "full_name_backend: John Doe"
191+
172192
python_full_name = driver.find_element(By.ID, "python_full_name")
173193
assert "<property object at 0x" in python_full_name.text
174194

175195
has_last_name = driver.find_element(By.ID, "has_last_name")
176196
assert has_last_name.text == "has_last_name: yes"
177197

198+
has_last_name_backend = driver.find_element(By.ID, "has_last_name_backend")
199+
assert has_last_name_backend.text == "has_last_name_backend: yes"
200+
178201
set_last_name = driver.find_element(By.ID, "set_last_name")
179202
# clear the input
180203
set_last_name.send_keys(Keys.CONTROL + "a")
@@ -186,10 +209,12 @@ async def test_hybrid_properties(
186209
)
187210
== "has_last_name: no"
188211
)
212+
assert (
213+
hybrid_properties.poll_for_content(
214+
has_last_name_backend, exp_not_equal="has_last_name_backend: yes"
215+
)
216+
== "has_last_name_backend: no"
217+
)
189218

190219
assert full_name.text == "full_name: John"
191-
192-
state = (await hybrid_properties.get_state(token)).substates[state_name]
193-
assert state is not None
194-
assert state.full_name == "John " # pyright: ignore[reportAttributeAccessIssue]
195-
assert state.has_last_name == "no" # pyright: ignore[reportAttributeAccessIssue]
220+
assert full_name_backend.text == "full_name_backend: John "

0 commit comments

Comments
 (0)