0.2.77
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user