2026-03-04 15:13:16 -05:00
|
|
|
from selenium.common.exceptions import NoSuchElementException
|
2026-03-04 00:07:10 -05:00
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
|
|
|
|
|
|
from .base import FunctionalTest
|
2026-03-09 16:08:28 -04:00
|
|
|
from apps.applets.models import Applet
|
2026-03-04 00:07:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DashboardMaintenanceTest(FunctionalTest):
|
2026-03-05 16:08:40 -05:00
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
2026-03-07 15:05:49 -05:00
|
|
|
Applet.objects.get_or_create(slug="new-list", defaults={"name": "New List"})
|
2026-03-05 16:08:40 -05:00
|
|
|
Applet.objects.get_or_create(slug="username", defaults={"name": "Username"})
|
|
|
|
|
Applet.objects.get_or_create(slug="palette", defaults={"name": "Palette"})
|
|
|
|
|
|
2026-03-04 00:07:10 -05:00
|
|
|
def test_user_without_username_can_claim_unclaimed_username(self):
|
|
|
|
|
# 1. Create a pre-authenticated session for discoman@example.com
|
|
|
|
|
self.create_pre_authenticated_session("discoman@example.com")
|
|
|
|
|
# 2. Navigate to self.live_server_url + "/"
|
|
|
|
|
self.browser.get(self.live_server_url)
|
|
|
|
|
# 3. Find the username applet on the page; look for a <section> or <div> with id="id_username_applet"
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_username")
|
|
|
|
|
# 5. Find the username input field inside the applet & type a username
|
|
|
|
|
username_input = self.browser.find_element(By.CSS_SELECTOR, "#id_new_username")
|
2026-03-06 22:31:10 -05:00
|
|
|
# 4. Assert it shows the current display name (truncated email: di…an@e…e.com) NOPE the username value itself now
|
|
|
|
|
self.assertEqual("", username_input.get_attribute("value"))
|
2026-03-04 00:07:10 -05:00
|
|
|
# 6. Type a username, e.g., discoman
|
|
|
|
|
username_input.send_keys("discoman")
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_new_username:valid")
|
|
|
|
|
)
|
|
|
|
|
# 7. Submit the form (click a btn or press Enter)
|
|
|
|
|
username_input.send_keys(Keys.ENTER)
|
|
|
|
|
# 8. Without a page reload, wait for the navbar to update; user wait_for() to check that the navbar text now contains "discoman"
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertIn(
|
|
|
|
|
"discoman",
|
|
|
|
|
self.browser.find_element(By.CLASS_NAME, "navbar-text").text
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
# 9. Also assert the applet input now shows "discoman" as its value
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertEqual(
|
|
|
|
|
"discoman",
|
|
|
|
|
self.browser.find_element(By.CSS_SELECTOR, "#id_new_username").get_attribute("value")
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-03-04 15:13:16 -05:00
|
|
|
|
|
|
|
|
def test_user_can_toggle_applet_visibility_via_gear_menu(self):
|
|
|
|
|
# 1. Auth as discoman@example.com, navigate home
|
|
|
|
|
self.create_pre_authenticated_session("discoman@example.com")
|
|
|
|
|
self.browser.get(self.live_server_url)
|
2026-03-05 14:45:55 -05:00
|
|
|
# 2. Assert both applets present on page (id_applet_username, id_applet_palette)
|
2026-03-04 15:13:16 -05:00
|
|
|
self.browser.find_element(By.ID, "id_applet_username")
|
2026-03-05 14:45:55 -05:00
|
|
|
self.browser.find_element(By.ID, "id_applet_palette")
|
2026-03-04 15:13:16 -05:00
|
|
|
# 3. Click el w. id="id_dash_gear"
|
|
|
|
|
dash_gear = self.browser.find_element(By.ID, "id_dash_gear")
|
|
|
|
|
dash_gear.click()
|
|
|
|
|
# 4. A menu appears; wait_for el w. id="id_applet_menu"
|
|
|
|
|
self.wait_for(
|
2026-03-05 16:08:40 -05:00
|
|
|
lambda: self.assertTrue(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
2026-03-04 15:13:16 -05:00
|
|
|
)
|
2026-03-05 14:45:55 -05:00
|
|
|
# 5. Find two checkboxes in menu, name="username" & name="palette"; assert both .is_selected()
|
2026-03-04 15:13:16 -05:00
|
|
|
menu = self.browser.find_element(By.ID, "id_applet_menu")
|
2026-03-05 16:08:40 -05:00
|
|
|
username_cb = menu.find_element(By.CSS_SELECTOR, '[name="applets"][value="username"]')
|
|
|
|
|
palette_cb = menu.find_element(By.CSS_SELECTOR, '[name="applets"][value="palette"]')
|
2026-03-04 15:13:16 -05:00
|
|
|
self.assertTrue(username_cb.is_selected())
|
2026-03-05 14:45:55 -05:00
|
|
|
self.assertTrue(palette_cb.is_selected())
|
|
|
|
|
# 6. Click palette box to uncheck it
|
|
|
|
|
palette_cb.click()
|
|
|
|
|
self.assertFalse(palette_cb.is_selected())
|
2026-03-05 16:08:40 -05:00
|
|
|
self.browser.execute_script("window.__no_reload_marker = true")
|
2026-03-04 15:13:16 -05:00
|
|
|
# 7. Submit the menu form via [type="submit"] btn inside menu
|
|
|
|
|
menu.find_element(By.CSS_SELECTOR, '[type="submit"]').click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertFalse(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
2026-03-05 14:45:55 -05:00
|
|
|
# 8. wait_for palette applet to be gone
|
2026-03-04 15:13:16 -05:00
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertRaises(
|
|
|
|
|
NoSuchElementException,
|
|
|
|
|
self.browser.find_element,
|
2026-03-05 14:45:55 -05:00
|
|
|
By.ID, "id_applet_palette"
|
2026-03-04 15:13:16 -05:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
# 9. assert id_applet_username remains
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_username")
|
2026-03-05 14:45:55 -05:00
|
|
|
# 10. Click gear again, find menu, find palette checkbox; assert now NOT selected
|
2026-03-04 15:13:16 -05:00
|
|
|
dash_gear.click()
|
2026-03-05 16:08:40 -05:00
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertTrue(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
menu = self.browser.find_element(By.ID, "id_applet_menu")
|
|
|
|
|
palette_cb = menu.find_element(By.CSS_SELECTOR, '[name="applets"][value="palette"]')
|
2026-03-05 14:45:55 -05:00
|
|
|
self.assertFalse(palette_cb.is_selected())
|
2026-03-04 15:13:16 -05:00
|
|
|
# 11. Click it to re-check box; submit
|
2026-03-05 14:45:55 -05:00
|
|
|
palette_cb.click()
|
|
|
|
|
self.assertTrue(palette_cb.is_selected())
|
2026-03-04 15:13:16 -05:00
|
|
|
menu.find_element(By.CSS_SELECTOR, '[type="submit"]').click()
|
2026-03-05 14:45:55 -05:00
|
|
|
# 12. wait_for id_applet_palette to reappear
|
2026-03-04 15:13:16 -05:00
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertFalse(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertTrue(
|
2026-03-05 14:45:55 -05:00
|
|
|
self.browser.find_element(By.ID, "id_applet_palette")
|
2026-03-04 15:13:16 -05:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.assertTrue(self.browser.execute_script("return window.__no_reload_marker === true"))
|
2026-03-07 15:05:49 -05:00
|
|
|
|
|
|
|
|
class AppletMenuDismissTest(FunctionalTest):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
Applet.objects.get_or_create(slug="username", defaults={"name": "Username"})
|
|
|
|
|
Applet.objects.get_or_create(slug="palette", defaults={"name": "Palette"})
|
|
|
|
|
self.create_pre_authenticated_session("discoman@example.com")
|
|
|
|
|
self.browser.get(self.live_server_url)
|
|
|
|
|
|
|
|
|
|
def _open_menu(self):
|
|
|
|
|
self.browser.find_element(By.ID, "id_dash_gear").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertTrue(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_gear_click_toggles_menu_closed(self):
|
|
|
|
|
self._open_menu()
|
|
|
|
|
self.browser.find_element(By.ID, "id_dash_gear").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertFalse(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_nvm_btn_closes_menu(self):
|
|
|
|
|
self._open_menu()
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu_cancel").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertFalse(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_click_outside_closes_menu(self):
|
|
|
|
|
self._open_menu()
|
|
|
|
|
self.browser.find_element(By.TAG_NAME, "h2").click()
|
|
|
|
|
self.wait_for(
|
|
|
|
|
lambda: self.assertFalse(
|
|
|
|
|
self.browser.find_element(By.ID, "id_applet_menu").is_displayed()
|
|
|
|
|
)
|
|
|
|
|
)
|