Stundenplan: Wochenend-Flakiness in Unterrichtsmodus-Test behoben

OpenWeekCell_LessonHeuteWaehrendUnterrichtszeit_OeffnetUnterrichtsmodus schlug
an Sa/So fehl, weil today.DayOfWeek dort keiner Kachel im Mo-Fr-Wochenraster
entspricht. TimetableViewModel bekommt dafür eine austauschbare Clock-Property
(Standard: DateTime.Now), sodass der Test "heute" unabhängig vom tatsächlichen
Wochentag simulieren kann.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-29 01:35:16 +02:00
co-authored by Claude Sonnet 5
parent 7fbf035cbb
commit 7d3d021d09
2 changed files with 21 additions and 7 deletions
@@ -109,6 +109,11 @@ public partial class TimetableViewModel : ObservableObject
public Func<Lesson, Task>? OnOpenLessonViewer { get; set; }
public Func<Lesson, Task>? OnOpenTeachingMode { get; set; }
/// Öffentlich statt intern (kein InternalsVisibleTo in dieser Codebasis) - erlaubt Tests, die
/// "heute"-abhängiges Verhalten (Wochenraster-Badges, Unterrichtszeit-Erkennung) prüfen, ohne
/// vom tatsächlichen Wochentag/der Uhrzeit im Testlauf abzuhängen.
public Func<DateTime> Clock { get; set; } = () => DateTime.Now;
public TimetableViewModel(ITimetableSlotRepository slots, IGroupRepository groups,
ISubjectRepository subjects, ILessonRepository lessons, IExamRepository exams,
ISchoolHolidayRepository schoolHolidays, SchoolCalendarSettingsService calendarSettings,
@@ -156,7 +161,7 @@ public partial class TimetableViewModel : ObservableObject
public void Load()
{
var today = DateOnly.FromDateTime(DateTime.Today);
var today = DateOnly.FromDateTime(Clock());
TodayLabel = today.ToString("dddd, dd.MM.yyyy", System.Globalization.CultureInfo.GetCultureInfo("de-DE"));
var publicHolidayDates = new HashSet<DateOnly>();
@@ -399,9 +404,10 @@ public partial class TimetableViewModel : ObservableObject
private static readonly TimeSpan TeachingTimeTolerance = TimeSpan.FromMinutes(10);
private bool IsAroundTeachingTime(DateOnly lessonDate, int periodNumber)
{
if (lessonDate != DateOnly.FromDateTime(DateTime.Today)) return false;
var nowSnapshot = Clock();
if (lessonDate != DateOnly.FromDateTime(nowSnapshot)) return false;
if (_periodSchedule.GetTimes(periodNumber) is not { } times) return false;
var now = TimeOnly.FromDateTime(DateTime.Now);
var now = TimeOnly.FromDateTime(nowSnapshot);
return now >= times.Start.Add(-TeachingTimeTolerance) && now <= times.End.Add(TeachingTimeTolerance);
}