Files
python-tdd/src/functional_tests/test_applet_palette.py

69 lines
2.5 KiB
Python

from selenium.webdriver.common.by import By
from apps.applets.models import Applet
from apps.lyric.models import User
from .base import FunctionalTest
class PaletteSwapTest(FunctionalTest):
def test_selecting_palette_updates_body_class_without_page_reload(self):
Applet.objects.get_or_create(slug="palette", defaults={
"name": "Palette", "context": "dashboard",
})
user, _ = User.objects.get_or_create(email="swap@test.io")
self.create_pre_authenticated_session("swap@test.io")
self.browser.get(self.live_server_url)
body = self.browser.find_element(By.TAG_NAME, "body")
self.assertIn("palette-default", body.get_attribute("class"))
# Mark the window — this survives JS execution but is wiped on a real reload
self.browser.execute_script("window._no_reload_marker = true;")
# Click OK on a non-active palette
btn = self.wait_for(
lambda: self.browser.find_element(
By.CSS_SELECTOR,
".palette-item:has(.swatch:not(.active)) .btn-confirm",
)
)
btn.click()
# Body palette class swaps without reload
self.wait_for(
lambda: self.assertNotIn(
"palette-default",
self.browser.find_element(By.TAG_NAME, "body").get_attribute("class"),
)
)
# Marker still present — no full page reload occurred
self.assertTrue(
self.browser.execute_script("return window._no_reload_marker === true;")
)
class SiteThemeTest(FunctionalTest):
def test_page_renders_with_earthman_palette(self):
self.browser.get(self.live_server_url)
body = self.browser.find_element(By.TAG_NAME, "body")
self.assertIn("palette-default", body.get_attribute("class"))
class LightPaletteTest(FunctionalTest):
def test_light_palette_tooltip_uses_white_background(self):
user, _ = User.objects.get_or_create(email="light@example.com")
user.palette = "palette-oblivion-light"
user.save()
self.create_pre_authenticated_session("light@example.com")
self.browser.get(self.live_server_url + "/dashboard/wallet/")
body = self.browser.find_element(By.TAG_NAME, "body")
tooltip_bg = self.browser.execute_script(
"return getComputedStyle(arguments[0]).getPropertyValue('--tooltip-bg').trim()",
body,
)
self.assertEqual(tooltip_bg, "255, 255, 255")