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) } } } // TestEventRangeText pins the human-readable "When" strings shown on the // event detail view so any change to date formatting is intentional. func TestEventRangeText(t *testing.T) { cases := []struct { name string form EventFormData want string }{ { name: "single allday date", form: EventFormData{AllDay: true, StartDate: "2026-08-05", EndDate: "2026-08-05"}, want: "August 5, 2026", }, { name: "all-day multi-day same month", form: EventFormData{AllDay: true, StartDate: "2026-08-05", EndDate: "2026-08-07"}, want: "Aug 5 – 7, 2026", }, { name: "all-day multi-day different months", form: EventFormData{AllDay: true, StartDate: "2026-08-30", EndDate: "2026-09-02"}, want: "Aug 30, 2026 – Sep 2, 2026", }, { name: "timed same day", form: EventFormData{AllDay: false, StartDate: "2026-08-05", StartTime: "14:00", EndDate: "2026-08-05", EndTime: "15:00"}, want: "August 5, 2026, 14:00 – 15:00", }, { name: "timed different days same month", form: EventFormData{AllDay: false, StartDate: "2026-08-05", StartTime: "23:30", EndDate: "2026-08-06", EndTime: "01:00"}, want: "Aug 5, 23:30 – 01:00, 2026", }, { name: "timed different months", form: EventFormData{AllDay: false, StartDate: "2026-08-31", StartTime: "10:00", EndDate: "2026-09-01", EndTime: "11:00"}, want: "Aug 31, 2026, 10:00 – Sep 1, 2026, 11:00", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := eventRangeText(c.form); got != c.want { t.Errorf("eventRangeText(%+v) = %q, want %q", c.form, got, c.want) } }) } } 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) } }