Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Sep 28, 2023
1 parent e62317b commit e7ef0bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ async def on_submit(event):
"data-success": bool(user_data.data),
"data-fetch-error": bool(user_data.error),
"data-mutation-error": bool(set_user_data.error),
"data-loading": user_data.loading or set_user_data.loading,
"data-username": "AnonymousUser"
if current_user.is_anonymous
else current_user.username,
Expand Down
17 changes: 9 additions & 8 deletions tests/test_app/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class ComponentTests(ChannelsLiveServerTestCase):
from django.db import DEFAULT_DB_ALIAS
from reactpy_django import config

databases = {"default"}
Expand Down Expand Up @@ -454,7 +455,7 @@ def test_component_errors(self):
new_page.close()

@skipIf(
config.REACTPY_DATABASE != "default",
config.REACTPY_DATABASE != DEFAULT_DB_ALIAS,
"`use_user_data` does not work with database routing.",
)
def test_use_user_data(self):
Expand All @@ -466,48 +467,48 @@ def test_use_user_data(self):

# 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]"
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=true][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=true][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-loading=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]"
"#use-user-data[data-success=false][data-fetch-error=false][data-mutation-error=false][data-loading=false][data-username=AnonymousUser]"
)
self.assertIn(r"Data: None", user_data_div.text_content())

0 comments on commit e7ef0bd

Please sign in to comment.