test(11-03): E2E tests for theme and language toggle (UIE-04, UIE-05)
- test_theme_cycles_on_click: verifies auto->light->dark cycling via aria-label selector - test_theme_persists_across_reload: verifies localStorage persistence of chosen theme - test_language_toggle_switches_nav_label: verifies FR->EN nav label switch (Imprimantes->Printers) - test_language_persists_across_reload: verifies localStorage persistence of chosen language
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""UIE-04: E2E tests for theme toggle — data-theme cycling and localStorage persistence."""
|
||||
from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
|
||||
def test_theme_cycles_on_click(page, live_server: str) -> None:
|
||||
"""Clicking theme button cycles data-theme attribute: auto -> light -> dark -> auto."""
|
||||
page.goto(f"{live_server}/", wait_until="domcontentloaded")
|
||||
|
||||
# Initial state: auto (default from base.html)
|
||||
initial_theme = page.evaluate("document.documentElement.getAttribute('data-theme')")
|
||||
assert initial_theme == "auto"
|
||||
|
||||
# Click once -> light
|
||||
page.click("button[aria-label='auto']")
|
||||
page.wait_for_function(
|
||||
"document.documentElement.getAttribute('data-theme') === 'light'",
|
||||
timeout=2000,
|
||||
)
|
||||
assert page.evaluate("document.documentElement.getAttribute('data-theme')") == "light"
|
||||
|
||||
# Click again -> dark
|
||||
page.click("button[aria-label='light']")
|
||||
page.wait_for_function(
|
||||
"document.documentElement.getAttribute('data-theme') === 'dark'",
|
||||
timeout=2000,
|
||||
)
|
||||
assert page.evaluate("document.documentElement.getAttribute('data-theme')") == "dark"
|
||||
|
||||
|
||||
def test_theme_persists_across_reload(page, live_server: str) -> None:
|
||||
"""After clicking theme toggle, the chosen theme is restored on reload."""
|
||||
page.goto(f"{live_server}/", wait_until="domcontentloaded")
|
||||
|
||||
# Switch to light mode
|
||||
page.click("button[aria-label='auto']")
|
||||
page.wait_for_function(
|
||||
"document.documentElement.getAttribute('data-theme') === 'light'",
|
||||
timeout=2000,
|
||||
)
|
||||
|
||||
# Reload the page
|
||||
page.reload(wait_until="domcontentloaded")
|
||||
|
||||
# Theme should still be light (from localStorage)
|
||||
theme_after_reload = page.evaluate("document.documentElement.getAttribute('data-theme')")
|
||||
assert theme_after_reload == "light"
|
||||
|
||||
# Cleanup: reset to auto
|
||||
page.evaluate("localStorage.setItem('imptune_theme', 'auto')")
|
||||
Reference in New Issue
Block a user