Skip to content

Commit

Permalink
use_user_data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Sep 28, 2023
1 parent de70662 commit e62317b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/test_app/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,62 @@ def test_component_errors(self):
self.assertIn("ViewNotRegisteredError:", broken_component.text_content())
finally:
new_page.close()

@skipIf(
config.REACTPY_DATABASE != "default",
"`use_user_data` does not work with database routing.",
)
def test_use_user_data(self):
input = self.page.wait_for_selector("#use-user-data input")
login_1 = self.page.wait_for_selector("#login-1")
login_2 = self.page.wait_for_selector("#login-2")
logout = self.page.wait_for_selector("#logout")
clear = self.page.wait_for_selector("#clear")

# Test AnonymousUser data
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-username=AnonymousUser]"
)
self.assertIn("Data: None", user_data_div.text_content())

# Test first user's data
login_1.click()
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-username=user_1]"
)
self.assertIn(r"Data: {}", user_data_div.text_content())
input.type("test", delay=CLICK_DELAY)
input.press("Enter", delay=CLICK_DELAY)
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=true][data-fetch-error=false][data-mutation-error=false][data-username=user_1]"
)
self.assertIn("Data: {'test': 'test'}", user_data_div.text_content())

# Test second user's data
login_2.click()
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-username=user_2]"
)
self.assertIn(r"Data: {}", user_data_div.text_content())
input.press("Control+A", delay=CLICK_DELAY)
input.press("Backspace", delay=CLICK_DELAY)
input.type("test 2", delay=CLICK_DELAY)
input.press("Enter", delay=CLICK_DELAY)
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=true][data-fetch-error=false][data-mutation-error=false][data-username=user_2]"
)
self.assertIn("Data: {'test 2': 'test 2'}", user_data_div.text_content())

# Attempt to clear data
clear.click()
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-username=user_2]"
)
self.assertIn(r"Data: {}", user_data_div.text_content())

# Attempt to logout
logout.click()
user_data_div = self.page.wait_for_selector(
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-username=AnonymousUser]"
)
self.assertIn(r"Data: None", user_data_div.text_content())

0 comments on commit e62317b

Please sign in to comment.