|
@@ -41,6 +41,13 @@ def ClientSide():
|
|
l3: str = rx.LocalStorage(name="l3")
|
|
l3: str = rx.LocalStorage(name="l3")
|
|
l4: str = rx.LocalStorage("l4 default")
|
|
l4: str = rx.LocalStorage("l4 default")
|
|
|
|
|
|
|
|
+ # Sync'd local storage
|
|
|
|
+ l5: str = rx.LocalStorage(sync=True)
|
|
|
|
+ l6: str = rx.LocalStorage(sync=True, name="l6")
|
|
|
|
+
|
|
|
|
+ def set_l6(self, my_param: str):
|
|
|
|
+ self.l6 = my_param
|
|
|
|
+
|
|
def set_var(self):
|
|
def set_var(self):
|
|
setattr(self, self.state_var, self.input_value)
|
|
setattr(self, self.state_var, self.input_value)
|
|
self.state_var = self.input_value = ""
|
|
self.state_var = self.input_value = ""
|
|
@@ -93,6 +100,8 @@ def ClientSide():
|
|
rx.box(ClientSideSubState.l2, id="l2"),
|
|
rx.box(ClientSideSubState.l2, id="l2"),
|
|
rx.box(ClientSideSubState.l3, id="l3"),
|
|
rx.box(ClientSideSubState.l3, id="l3"),
|
|
rx.box(ClientSideSubState.l4, id="l4"),
|
|
rx.box(ClientSideSubState.l4, id="l4"),
|
|
|
|
+ rx.box(ClientSideSubState.l5, id="l5"),
|
|
|
|
+ rx.box(ClientSideSubState.l6, id="l6"),
|
|
rx.box(ClientSideSubSubState.c1s, id="c1s"),
|
|
rx.box(ClientSideSubSubState.c1s, id="c1s"),
|
|
rx.box(ClientSideSubSubState.l1s, id="l1s"),
|
|
rx.box(ClientSideSubSubState.l1s, id="l1s"),
|
|
)
|
|
)
|
|
@@ -191,33 +200,44 @@ async def test_client_side_state(
|
|
"""
|
|
"""
|
|
assert client_side.app_instance is not None
|
|
assert client_side.app_instance is not None
|
|
assert client_side.frontend_url is not None
|
|
assert client_side.frontend_url is not None
|
|
- token_input = driver.find_element(By.ID, "token")
|
|
|
|
- assert token_input
|
|
|
|
|
|
|
|
- # wait for the backend connection to send the token
|
|
|
|
- token = client_side.poll_for_value(token_input)
|
|
|
|
- assert token is not None
|
|
|
|
|
|
+ def poll_for_token():
|
|
|
|
+ token_input = driver.find_element(By.ID, "token")
|
|
|
|
+ assert token_input
|
|
|
|
|
|
- # get a reference to the cookie manipulation form
|
|
|
|
- state_var_input = driver.find_element(By.ID, "state_var")
|
|
|
|
- input_value_input = driver.find_element(By.ID, "input_value")
|
|
|
|
- set_sub_state_button = driver.find_element(By.ID, "set_sub_state")
|
|
|
|
- set_sub_sub_state_button = driver.find_element(By.ID, "set_sub_sub_state")
|
|
|
|
|
|
+ # wait for the backend connection to send the token
|
|
|
|
+ token = client_side.poll_for_value(token_input)
|
|
|
|
+ assert token is not None
|
|
|
|
+ return token
|
|
|
|
|
|
def set_sub(var: str, value: str):
|
|
def set_sub(var: str, value: str):
|
|
|
|
+ # Get a reference to the cookie manipulation form.
|
|
|
|
+ state_var_input = driver.find_element(By.ID, "state_var")
|
|
|
|
+ input_value_input = driver.find_element(By.ID, "input_value")
|
|
|
|
+ set_sub_state_button = driver.find_element(By.ID, "set_sub_state")
|
|
AppHarness._poll_for(lambda: state_var_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: state_var_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: input_value_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: input_value_input.get_attribute("value") == "")
|
|
|
|
+
|
|
|
|
+ # Set the values.
|
|
state_var_input.send_keys(var)
|
|
state_var_input.send_keys(var)
|
|
input_value_input.send_keys(value)
|
|
input_value_input.send_keys(value)
|
|
set_sub_state_button.click()
|
|
set_sub_state_button.click()
|
|
|
|
|
|
def set_sub_sub(var: str, value: str):
|
|
def set_sub_sub(var: str, value: str):
|
|
|
|
+ # Get a reference to the cookie manipulation form.
|
|
|
|
+ state_var_input = driver.find_element(By.ID, "state_var")
|
|
|
|
+ input_value_input = driver.find_element(By.ID, "input_value")
|
|
|
|
+ set_sub_sub_state_button = driver.find_element(By.ID, "set_sub_sub_state")
|
|
AppHarness._poll_for(lambda: state_var_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: state_var_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: input_value_input.get_attribute("value") == "")
|
|
AppHarness._poll_for(lambda: input_value_input.get_attribute("value") == "")
|
|
|
|
+
|
|
|
|
+ # Set the values.
|
|
state_var_input.send_keys(var)
|
|
state_var_input.send_keys(var)
|
|
input_value_input.send_keys(value)
|
|
input_value_input.send_keys(value)
|
|
set_sub_sub_state_button.click()
|
|
set_sub_sub_state_button.click()
|
|
|
|
|
|
|
|
+ token = poll_for_token()
|
|
|
|
+
|
|
# get a reference to all cookie and local storage elements
|
|
# get a reference to all cookie and local storage elements
|
|
c1 = driver.find_element(By.ID, "c1")
|
|
c1 = driver.find_element(By.ID, "c1")
|
|
c2 = driver.find_element(By.ID, "c2")
|
|
c2 = driver.find_element(By.ID, "c2")
|
|
@@ -485,6 +505,31 @@ async def test_client_side_state(
|
|
"value": "c5%20value",
|
|
"value": "c5%20value",
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ # Open a new tab to check that sync'd local storage is working
|
|
|
|
+ main_tab = driver.window_handles[0]
|
|
|
|
+ driver.switch_to.new_window("window")
|
|
|
|
+ driver.get(client_side.frontend_url)
|
|
|
|
+
|
|
|
|
+ # New tab should have a different state token.
|
|
|
|
+ assert poll_for_token() != token
|
|
|
|
+
|
|
|
|
+ # Set values and check them in the new tab.
|
|
|
|
+ set_sub("l5", "l5 value")
|
|
|
|
+ set_sub("l6", "l6 value")
|
|
|
|
+ l5 = driver.find_element(By.ID, "l5")
|
|
|
|
+ l6 = driver.find_element(By.ID, "l6")
|
|
|
|
+ assert l5.text == "l5 value"
|
|
|
|
+ assert l6.text == "l6 value"
|
|
|
|
+
|
|
|
|
+ # Switch back to main window.
|
|
|
|
+ driver.switch_to.window(main_tab)
|
|
|
|
+
|
|
|
|
+ # The values should have updated automatically.
|
|
|
|
+ l5 = driver.find_element(By.ID, "l5")
|
|
|
|
+ l6 = driver.find_element(By.ID, "l6")
|
|
|
|
+ assert l5.text == "l5 value"
|
|
|
|
+ assert l6.text == "l6 value"
|
|
|
|
+
|
|
# clear the cookie jar and local storage, ensure state reset to default
|
|
# clear the cookie jar and local storage, ensure state reset to default
|
|
driver.delete_all_cookies()
|
|
driver.delete_all_cookies()
|
|
local_storage.clear()
|
|
local_storage.clear()
|