package config import ( "os" "path/filepath" "testing" ) func TestLoadSeeds(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) cfg, err := Load() if err != nil { t.Fatal(err) } if cfg.DefaultVersion != "pl" || cfg.Offline { t.Errorf("defaults wrong: %+v", cfg) } if cfg.Lectionary != "new" { t.Errorf("lectionary default wrong: %+v", cfg) } if _, err := os.Stat(filepath.Join(dir, "lectio", "config.toml")); err != nil { t.Error("config not seeded") } } func TestLoadOverride(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), []byte("offline = true\ndefault_version = \"wuj\"\n"), 0o644) cfg, _ := Load() if !cfg.Offline || cfg.DefaultVersion != "wuj" { t.Errorf("override not applied: %+v", cfg) } } func TestWebDefaults(t *testing.T) { def := Default() if def.WebTheme != "transfiguration" { t.Errorf("WebTheme default wrong: got %q, want %q", def.WebTheme, "transfiguration") } if def.WebPort != 0 { t.Errorf("WebPort default wrong: got %d, want 0", def.WebPort) } } func TestWebLoadsFromSeed(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) cfg, err := Load() if err != nil { t.Fatal(err) } if cfg.WebTheme != "transfiguration" { t.Errorf("WebTheme from seed wrong: got %q, want %q", cfg.WebTheme, "transfiguration") } if cfg.WebPort != 0 { t.Errorf("WebPort from seed wrong: got %d, want 0", cfg.WebPort) } if cfg.WebDisplay != "horizontal" { t.Errorf("WebDisplay from seed wrong: got %q, want %q", cfg.WebDisplay, "horizontal") } } func TestWebDisplayDefault(t *testing.T) { def := Default() if def.WebDisplay != "horizontal" { t.Errorf("WebDisplay default wrong: got %q, want %q", def.WebDisplay, "horizontal") } } func TestWebDisplayLoadsSetting(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), []byte("web_display = \"vertical\"\n"), 0o644) cfg, err := Load() if err != nil { t.Fatal(err) } if cfg.WebDisplay != "vertical" { t.Errorf("WebDisplay = %q, want %q", cfg.WebDisplay, "vertical") } } func TestWebDisplayNormalizesUnknown(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) os.MkdirAll(filepath.Join(dir, "lectio"), 0o755) os.WriteFile(filepath.Join(dir, "lectio", "config.toml"), []byte("web_display = \"bogus\"\n"), 0o644) cfg, err := Load() if err != nil { t.Fatal(err) } if cfg.WebDisplay != "horizontal" { t.Errorf("WebDisplay = %q, want %q (normalized from bogus)", cfg.WebDisplay, "horizontal") } } func TestPartShown(t *testing.T) { var empty Config if !empty.PartShown("new", "psalm") { t.Error("nil Parts: psalm should be shown") } if !empty.PartShown("new", "ewangelia") { t.Error("nil Parts: ewangelia should be shown") } hidden := Config{Parts: map[string]map[string]bool{ "new": {"psalm": false}, }} if hidden.PartShown("new", "psalm") { t.Error("psalm explicitly false should be hidden") } if !hidden.PartShown("new", "ewangelia") { t.Error("ewangelia not mentioned should still be shown") } }