From 99153d8e3284696c15ab1bd28b25627ac948ace8 Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Wed, 27 Nov 2024 22:33:45 +0100 Subject: [PATCH 1/5] test #4445 --- tests/integration/test_input.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index c718749aaa8..93a0ecc6842 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -11,10 +11,15 @@ def FullyControlledInput(): """App using a fully controlled input with implicit debounce wrapper.""" + from typing import Optional + import reflex as rx class State(rx.State): - text: str = "initial" + text: Optional[str] = "initial" + + def set_none(self): + self.text = None app = rx.App(state=rx.State) @@ -48,6 +53,7 @@ def index(): rx.button( "CLEAR", on_click=rx.set_value("on_change_input", ""), id="clear" ), + rx.button("SET NONE", on_click=State.set_none, id="set_none"), ) @@ -186,3 +192,8 @@ async def get_state_text(): # assert backend_state.text == "" # assert debounce_input.get_attribute("value") == "" # assert value_input.get_attribute("value") == "" + + set_none_button = driver.find_element(By.ID, "set_none") + set_none_button.click() + assert await get_state_text() is None + assert AppHarness._poll_for(lambda: debounce_input.get_attribute("value") == "") From 872c0e535db9c7595c5f24347a933bc7d5e0b798 Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Sat, 14 Dec 2024 21:51:30 +0100 Subject: [PATCH 2/5] currently only rx.Field is working, waiting for #4528 to add tests without rx.Field --- tests/integration/test_input.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index b300130b9d1..3a6e0bdb7f2 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -16,7 +16,7 @@ def FullyControlledInput(): import reflex as rx class State(rx.State): - text: Optional[str] = "initial" + text: rx.Field[Optional[str]] = rx.field("initial") def set_none(self): self.text = None @@ -195,5 +195,5 @@ async def get_state_text(): set_none_button = driver.find_element(By.ID, "set_none") set_none_button.click() - assert await get_state_text() is None assert AppHarness._poll_for(lambda: debounce_input.get_attribute("value") == "") + assert await get_state_text() is None From e70f3803761977a51e60c45cf1ae30b5b6eae27f Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Tue, 14 Jan 2025 10:57:54 +0100 Subject: [PATCH 3/5] wip updating test --- tests/integration/test_input.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index 3a6e0bdb7f2..073af564b1f 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -16,10 +16,11 @@ def FullyControlledInput(): import reflex as rx class State(rx.State): - text: rx.Field[Optional[str]] = rx.field("initial") + text: str = "initial" + optional: rx.Field[Optional[str]] = rx.field("initial") def set_none(self): - self.text = None + self.optional = None app = rx.App(state=rx.State) @@ -53,6 +54,11 @@ def index(): rx.button( "CLEAR", on_click=rx.set_value("on_change_input", ""), id="clear" ), + rx.input( + value=State.optional | "", + # value=State.optional.to_string(), + id="optional_input", + ), rx.button("SET NONE", on_click=State.set_none, id="set_none"), ) @@ -127,6 +133,7 @@ async def get_state_text(): # find the input and wait for it to have the initial state value debounce_input = driver.find_element(By.ID, "debounce_input_input") + optional_input = driver.find_element(By.ID, "optional_input") value_input = driver.find_element(By.ID, "value_input") on_change_input = driver.find_element(By.ID, "on_change_input") plain_value_input = driver.find_element(By.ID, "plain_value_input") @@ -195,5 +202,5 @@ async def get_state_text(): set_none_button = driver.find_element(By.ID, "set_none") set_none_button.click() - assert AppHarness._poll_for(lambda: debounce_input.get_attribute("value") == "") + assert AppHarness._poll_for(lambda: optional_input.get_attribute("value") == "") assert await get_state_text() is None From 447f2e9d84731761f8253e93a6c487eb6c5c7988 Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Tue, 14 Jan 2025 10:59:14 +0100 Subject: [PATCH 4/5] adjust test to fully use new optional var --- tests/integration/test_input.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index 073af564b1f..9269f2cea26 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -105,6 +105,10 @@ async def get_state_text(): state = await fully_controlled_input.get_state(f"{token}_{full_state_name}") return state.substates[state_name].text + async def get_state_optional(): + state = await fully_controlled_input.get_state(f"{token}_{full_state_name}") + return state.substates[state_name].optional + # ensure defaults are set correctly assert ( fully_controlled_input.poll_for_value( @@ -203,4 +207,4 @@ async def get_state_text(): set_none_button = driver.find_element(By.ID, "set_none") set_none_button.click() assert AppHarness._poll_for(lambda: optional_input.get_attribute("value") == "") - assert await get_state_text() is None + assert await get_state_optional() is None From 460d395f984180b8246ede6eed4ed47b9368a8a9 Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Tue, 14 Jan 2025 11:02:18 +0100 Subject: [PATCH 5/5] drop commented out code --- tests/integration/test_input.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/test_input.py b/tests/integration/test_input.py index 9269f2cea26..b9c4c8464d9 100644 --- a/tests/integration/test_input.py +++ b/tests/integration/test_input.py @@ -56,7 +56,6 @@ def index(): ), rx.input( value=State.optional | "", - # value=State.optional.to_string(), id="optional_input", ), rx.button("SET NONE", on_click=State.set_none, id="set_none"),