package templates import "testing" // TestEventTextColorKeepsReadableColorsUnchanged covers the reported bug: // picking white (or any other very light color) for a calendar made its // events unreadable in the month view, since monthDayCell used the same // color for both the (barely tinted) background and the text. Light // colors must be darkened for text use; colors that were already fine // must render exactly as chosen. func TestEventTextColorKeepsReadableColorsUnchanged(t *testing.T) { for _, c := range []string{"#3b82f6", "#ec4899", "#10b981", "#000000"} { if got := eventTextColor(c); got != c { t.Errorf("eventTextColor(%s) = %s, want unchanged", c, got) } } } func TestEventTextColorDarkensLightColors(t *testing.T) { for _, c := range []string{"#ffffff", "#ffff00", "#f0f0f0", "#fefefe"} { got := eventTextColor(c) if got == c { t.Errorf("eventTextColor(%s) = %s, want darkened for readability", c, got) } r, g, b, ok := parseHexColor(got) if !ok { t.Fatalf("eventTextColor(%s) returned unparseable color %s", c, got) } luminance := 0.299*float64(r) + 0.587*float64(g) + 0.114*float64(b) if luminance > 170 { t.Errorf("eventTextColor(%s) = %s still too light (luminance %.1f)", c, got, luminance) } } } func TestEventTextColorFallsBackForInvalidInput(t *testing.T) { if got := eventTextColor(""); got != colorOrDefault("") { t.Errorf("eventTextColor(\"\") = %s, want the same default colorOrDefault returns", got) } if got := eventTextColor("not-a-color"); got != "not-a-color" { t.Errorf("eventTextColor(unparseable) = %s, want passed through unchanged", got) } }