This commit is contained in:
ponzischeme89
2026-08-19 06:57:59 +12:00
parent 8c847c59b8
commit 2b43b9ef12
94 changed files with 6359 additions and 778 deletions
+32
View File
@@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"reflect"
"strings"
"testing"
)
@@ -41,6 +42,37 @@ func TestNormalizePreferencesBoundsAndNormalisesProfileInitials(t *testing.T) {
}
}
// A short name is a person's name, so unlike the initials beside it in the catalogue it
// keeps the case it was typed in. Folding it would have the launcher greeting somebody as
// MATT, which is the whole reason Uppercase is per-definition rather than per-kind.
func TestNormalizePreferencesKeepsShortNameCaseAndBoundsIt(t *testing.T) {
if got := normalizePreferences(map[string]any{"shortName": " Matt "})["shortName"]; got != "Matt" {
t.Errorf("shortName = %v, want Matt", got)
}
long := strings.Repeat("a", shortNameMaxLength+1)
for _, value := range []any{long, "Ma\ntt", 12} {
if got := normalizePreferences(map[string]any{"shortName": value})["shortName"]; got != "" {
t.Errorf("shortName for %v = %v, want the account-name fallback", value, got)
}
}
if got := normalizePreferences(nil)["shortName"]; got != "" {
t.Errorf("default shortName = %v, want blank", got)
}
}
// The short name is admin-owned like the initials, so a television saving an unrelated
// setting must not be what quietly clears it.
func TestDevicePreferenceWritePreservesAdminShortName(t *testing.T) {
stored, err := json.Marshal(normalizePreferences(map[string]any{"shortName": "Matt"}))
if err != nil {
t.Fatal(err)
}
merged := preserveAdminPreferences(map[string]any{"showTitleLogo": false}, stored)
if normalizePreferences(merged)["shortName"] != "Matt" {
t.Errorf("shortName = %v, want preserved Matt", normalizePreferences(merged)["shortName"])
}
}
func TestDevicePreferenceWritePreservesAdminInitials(t *testing.T) {
stored, err := json.Marshal(normalizePreferences(map[string]any{"profileInitials": "MC"}))
if err != nil {