Files
john-okeefe 8d65e03555 fix(ui): move theme checkmark when theme changes in Appearance menu
The checkmark in the Appearance theme menu was rendered server-side
(if user.Theme == opt.Name), so it never moved after switching themes
in the browser.

- Always render the check for every theme option, hidden by default,
  using a new themeCheckClass(name, current) helper that returns the
  hidden class unless the option is the active theme.
- Give each theme button a data-theme attribute and add
  updateThemeIndicators() to web/src/theme.ts, which reads the applied
  theme from the body class (theme-<name>) and toggles the hidden class
  on each check accordingly.
- Call updateThemeIndicators() from changeTheme (before the async save
  and on failure), initializeTheme, and loadUserTheme so the menu stays
  in sync with the applied theme.
- Add unit test for themeCheckClass (templates/utils_test.go) and
  regenerate templ output.
2026-08-10 13:43:32 -04:00

57 lines
1.9 KiB
Go

package templates
import "testing"
func TestGroupTunableSettings(t *testing.T) {
entries := []SettingEntry{
{Key: "session_duration_seconds", Group: "Session", RequiresRestart: false},
{Key: "password_min_length", Group: "Password Quality", RequiresRestart: false},
{Key: "password_require_upper", Group: "Password Quality", RequiresRestart: false},
{Key: "opds_default_page_size", Group: "OPDS Catalog", RequiresRestart: false},
{Key: "auth_rate_limit_per_min", Group: "Auth Rate Limiting", RequiresRestart: true},
{Key: "login_max_attempts", Group: "Login Lockout", RequiresRestart: true},
{Key: "login_lockout_minutes", Group: "Login Lockout", RequiresRestart: true},
}
live, restart := GroupTunableSettings(entries)
if len(live) != 3 {
t.Fatalf("expected 3 live groups, got %d", len(live))
}
if live[0].Name != "Session" || len(live[0].Entries) != 1 {
t.Errorf("live[0] = %+v", live[0])
}
if live[1].Name != "Password Quality" || len(live[1].Entries) != 2 {
t.Errorf("live[1] = %+v", live[1])
}
if live[2].Name != "OPDS Catalog" || len(live[2].Entries) != 1 {
t.Errorf("live[2] = %+v", live[2])
}
if len(restart) != 2 {
t.Fatalf("expected 2 restart groups, got %d", len(restart))
}
if restart[0].Name != "Auth Rate Limiting" || len(restart[0].Entries) != 1 {
t.Errorf("restart[0] = %+v", restart[0])
}
if restart[1].Name != "Login Lockout" || len(restart[1].Entries) != 2 {
t.Errorf("restart[1] = %+v", restart[1])
}
}
func TestGroupTunableSettingsEmpty(t *testing.T) {
live, restart := GroupTunableSettings(nil)
if len(live) != 0 || len(restart) != 0 {
t.Errorf("expected empty groups, got live=%d restart=%d", len(live), len(restart))
}
}
func TestThemeCheckClass(t *testing.T) {
if got := themeCheckClass("dracula", "dracula"); got != "" {
t.Errorf("active theme should be visible, got %q", got)
}
if got := themeCheckClass("nord", "dracula"); got != " hidden" {
t.Errorf("inactive theme should be hidden, got %q", got)
}
}