using Elternbeirat.Contracts; using Elternbeirat.Web.Features.Events; namespace Elternbeirat.Web.Tests; /// /// Unit tests for the calendar sheet texts and the time line beside it. Pure logic, /// no PocketBase needed. All times are Berlin wall-clock, as the contract delivers them. /// public class EventDateFormatTests { private static Event Event(DateTime start, DateTime? end = null) => new() { Id = "test", Title = "Termin", Start = start, End = end }; [Theory] [InlineData(1, "Jan")] [InlineData(3, "März")] [InlineData(5, "Mai")] [InlineData(10, "Okt")] [InlineData(12, "Dez")] public void Sheet_month_is_the_German_short_month_without_period(int month, string expected) => EventDateFormat.SheetMonth(new DateTime(2026, month, 1)).ShouldBe(expected); [Fact] public void Sheet_day_has_no_leading_zero() => EventDateFormat.SheetDay(new DateTime(2026, 10, 8, 19, 30, 0)).ShouldBe("8"); [Theory] [InlineData(8, "Do")] // Thursday, 8 October 2026 [InlineData(11, "So")] // Sunday public void Sheet_weekday_is_the_German_short_weekday_without_period(int day, string expected) => EventDateFormat.SheetWeekday(new DateTime(2026, 10, day)).ShouldBe(expected); [Fact] public void Past_all_day_event_shows_the_day_and_no_time() { var allDay = Event(new DateTime(2026, 11, 13)); EventDateFormat.PastDays(allDay).ShouldBe("13. November"); EventDateFormat.PastTime(allDay).ShouldBe(""); } [Fact] public void Past_timed_event_shows_the_day_and_its_start_time() { var timed = Event(new DateTime(2026, 9, 1, 19, 0, 0)); EventDateFormat.PastDays(timed).ShouldBe("1. September"); // no leading zero EventDateFormat.PastTime(timed).ShouldBe("19:00 Uhr"); } [Fact] public void Past_timed_event_ending_the_same_day_shows_the_time_range() { var evening = Event(new DateTime(2026, 11, 13, 19, 0, 0), new DateTime(2026, 11, 13, 21, 0, 0)); EventDateFormat.PastDays(evening).ShouldBe("13. November"); EventDateFormat.PastTime(evening).ShouldBe("19:00–21:00 Uhr"); } [Fact] public void Past_multi_day_event_in_one_month_names_the_month_once() => EventDateFormat.PastDays(Event(new DateTime(2026, 2, 8), new DateTime(2026, 2, 9))).ShouldBe("8.–9. Februar"); [Fact] public void Past_multi_day_event_across_a_month_names_both_months() => EventDateFormat.PastDays(Event(new DateTime(2026, 1, 30), new DateTime(2026, 2, 2))) .ShouldBe("30. Januar – 2. Februar"); [Fact] public void Past_multi_day_event_across_a_year_names_the_end_year() => // The list is grouped by the start year, so only the end needs its year. EventDateFormat.PastDays(Event(new DateTime(2026, 12, 30), new DateTime(2027, 1, 2))) .ShouldBe("30. Dezember – 2. Januar 2027"); [Fact] public void Past_timed_multi_day_event_shows_only_the_start_time() => // A range here would read as the daily hours. EventDateFormat.PastTime(Event(new DateTime(2026, 2, 8, 9, 0, 0), new DateTime(2026, 2, 9, 13, 0, 0))) .ShouldBe("09:00 Uhr"); [Fact] public void Span_of_a_timed_event_without_end_is_its_start_time() => EventDateFormat.Span(Event(new DateTime(2026, 10, 8, 19, 30, 0))).ShouldBe("19:30 Uhr"); [Fact] public void Span_of_a_same_day_event_is_the_time_range() => EventDateFormat.Span(Event(new DateTime(2026, 10, 8, 19, 30, 0), new DateTime(2026, 10, 8, 21, 0, 0))) .ShouldBe("19:30–21:00 Uhr"); [Fact] public void Span_of_a_multi_day_event_names_the_last_day() => EventDateFormat.Span(Event(new DateTime(2026, 10, 9, 9, 0, 0), new DateTime(2026, 10, 11, 13, 0, 0))) .ShouldBe("09:00 Uhr bis Sonntag, 11. Oktober 2026, 13:00 Uhr"); [Fact] public void Span_of_a_multi_day_all_day_event_has_no_times() => EventDateFormat.Span(Event(new DateTime(2026, 10, 9), new DateTime(2026, 10, 11))) .ShouldBe("bis Sonntag, 11. Oktober 2026"); [Fact] public void Span_of_a_single_all_day_event_is_empty() => // The sheet already shows the day; there is nothing left to say. EventDateFormat.Span(Event(new DateTime(2026, 10, 8))).ShouldBe(""); }