Files
nidus/internal/web/templates/calendar_test.go
T
arnefandCopilot 28c55804d8 Fix unreadable event text when a calendar's color is white/very light
The month view rendered each event's text (and its little leading dot)
in the calendar's own color, on a very lightly tinted (~13% opacity)
background of that same color. For a light color like white or pale
yellow, the text ended up effectively invisible against its own
near-white background.

internal/web/templates/calendar.templ: add eventTextColor(hex), which
darkens colors above a perceived-luminance threshold (keeping the hue,
e.g. white -> a mid gray, pale yellow -> olive) while leaving already-
legible colors untouched; used for both the event text and its leading
dot. Also add a subtle ring to the event dot and to the calendar legend's
color swatch so a white/near-white swatch stays visible against the
page's white background, independent of the text-color fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-20 23:27:19 +02:00

44 lines
1.6 KiB
Go

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)
}
}