feat(интерфейс): светлая тема при первом визите, тёмная — по выбору
Первый визит больше не уходит в тёмную тему из-за системной настройки: без сохранённого выбора страница светлая. Переключатель по-прежнему главнее системы, выбор остаётся после перезагрузки. Проверка на первую страницу смотрит системную тёмную настройку и повторный визит. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -53,8 +53,11 @@ def site(tmp_path_factory):
|
||||
srv.server_close()
|
||||
|
||||
|
||||
def _страница(browser, site, width=1280, height=900):
|
||||
ctx = browser.new_context(viewport={"width": width, "height": height})
|
||||
def _страница(browser, site, width=1280, height=900, color_scheme=None):
|
||||
opts = {"viewport": {"width": width, "height": height}}
|
||||
if color_scheme:
|
||||
opts["color_scheme"] = color_scheme
|
||||
ctx = browser.new_context(**opts)
|
||||
pg = ctx.new_page()
|
||||
pg.set_default_timeout(8000)
|
||||
pg._errors = []
|
||||
@@ -240,3 +243,23 @@ def test_витрина_следует_теме_и_помнит_выбор(brows
|
||||
assert not pg._errors, pg._errors
|
||||
finally:
|
||||
ctx.close()
|
||||
|
||||
|
||||
def test_первый_визит_светлый_даже_при_тёмной_системе(browser, site):
|
||||
"""Первый визит без сохранённого выбора — светлая тема, даже если система тёмная.
|
||||
Выбор пользователя по-прежнему главнее: переключил в тёмную — она и останется."""
|
||||
pg, ctx = _страница(browser, site, color_scheme="dark")
|
||||
try:
|
||||
assert pg.evaluate("() => localStorage.getItem('theme')") is None
|
||||
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "light"
|
||||
фон = pg.evaluate("() => getComputedStyle(document.getElementById('login-screen')).backgroundColor")
|
||||
assert фон == "rgb(246, 241, 234)", f"первый визит не в светлой палитре: {фон}"
|
||||
pg.click("#login-fab")
|
||||
assert pg.evaluate("() => localStorage.getItem('theme')") == "dark"
|
||||
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "dark"
|
||||
pg.reload()
|
||||
pg.wait_for_selector("#login-screen", state="visible")
|
||||
assert pg.evaluate("() => document.documentElement.getAttribute('data-theme')") == "dark"
|
||||
assert not pg._errors, pg._errors
|
||||
finally:
|
||||
ctx.close()
|
||||
|
||||
Reference in New Issue
Block a user