Files
cthulhu/internal/config/window_titles_test.go

59 lines
1.8 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package config
import (
"os"
"path/filepath"
"testing"
)
func TestTitleChangePreferenceDefaultsForExistingSettings(t *testing.T) {
settings, err := Load(filepath.Join("testdata", "settings-v2.toml"))
if err != nil {
t.Fatal(err)
}
if !settings.Reading.AutomaticallyReadTitleChanges {
t.Fatal("omitted title preference defaults off")
}
}
func TestTitleChangePreferenceRoundTripAndInheritance(t *testing.T) {
path := filepath.Join(t.TempDir(), "settings.toml")
store, err := NewStore(path)
if err != nil {
t.Fatal(err)
}
global := DefaultSettings()
if err = store.Save(global); err != nil {
t.Fatal(err)
}
application := global
application.Reading.AutomaticallyReadTitleChanges = false
if err = store.SaveForApplication("Noisy Application", application); err != nil {
t.Fatal(err)
}
contents, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
_, loaded, err := decodeDocument(contents)
if err != nil || !loaded.Reading.AutomaticallyReadTitleChanges {
t.Fatalf("global = %t, %v", loaded.Reading.AutomaticallyReadTitleChanges, err)
}
restored, found, err := store.LoadForApplication("Noisy Application")
if err != nil || !found || restored.Reading.AutomaticallyReadTitleChanges {
t.Fatalf("override = %t, found %t, %v", restored.Reading.AutomaticallyReadTitleChanges, found, err)
}
global.Reading.AutomaticallyReadTitleChanges = false
if err = store.Save(global); err != nil {
t.Fatal(err)
}
inherited, _, err := store.LoadForApplication("Other Application")
if err != nil || inherited.Reading.AutomaticallyReadTitleChanges {
t.Fatalf("inheritance = %t, %v", inherited.Reading.AutomaticallyReadTitleChanges, err)
}
}