TodaysLessons löst je Stunde den Raum über den passenden TimetableSlot auf und die Uhrzeit aus Lesson.StartTime bzw. dem Stundenraster - gleiche Quellen wie im Verlaufsplan-Editor und Stundenplan. Bewusst nicht dupliziert: die Vertretung/Ausfall-Logik der Stundenplan-eigenen "Heute"-Ansicht bleibt dort, das Dashboard zeigt nur die einfache geplante Stunde. Klick auf eine Stunde springt in die Mitarbeitserfassung der Gruppe - bewusst anderes Ziel als der bestehende Stundenplan-Sprung (dort "Planung"), da vom Dashboard aus morgens eher die Mitarbeitserfassung naheliegt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
112 lines
4.4 KiB
C#
112 lines
4.4 KiB
C#
using LehrerApp.Core.Models;
|
|
using LehrerApp.Core.Services;
|
|
using LehrerApp.Desktop.ViewModels;
|
|
using Xunit;
|
|
|
|
namespace LehrerApp.Desktop.Tests;
|
|
|
|
/// Tests für 9.1 (heutige Stunden mit Uhrzeit und Raum im Dashboard) und 9.2 (Absprung von einer
|
|
/// Stunde). Deckt nur die neue Zeit-/Raum-Auflösung ab, nicht die übrigen, unveränderten
|
|
/// Dashboard-Bausteine (Kalender, offene Aufgaben, Fehlzeiten-Warnungen, ...).
|
|
public sealed class DashboardViewModelTests
|
|
{
|
|
private static PeriodScheduleService NewPeriodSchedule()
|
|
{
|
|
var tempPath = System.IO.Path.Combine(
|
|
System.IO.Path.GetTempPath(), $"lehrerapp-dashboardvm-tests-{Guid.NewGuid():N}");
|
|
Directory.CreateDirectory(tempPath);
|
|
return new PeriodScheduleService(tempPath);
|
|
}
|
|
|
|
private static DashboardViewModel BuildVm(LearningGroup group, Lesson lesson,
|
|
FakeTimetableSlots? slots = null, PeriodScheduleService? periodSchedule = null)
|
|
{
|
|
var lessons = new FakeLessons();
|
|
lessons.Add(lesson);
|
|
return new DashboardViewModel(
|
|
new FakeGroups([group]), new FakeSubjects([]), lessons,
|
|
new FakeExams([]), new FakeWorkTasks(), new FakeSessions([]), new FakeEntries(),
|
|
new FakeStudents([]), new FakeDocumentation(),
|
|
slots ?? new FakeTimetableSlots(), periodSchedule ?? NewPeriodSchedule(),
|
|
new AttendanceBalanceService(), new SchoolYearService());
|
|
}
|
|
|
|
[Fact]
|
|
public void TodaysLessons_LoestRaumUeberPassendenStundenplanSlotAuf()
|
|
{
|
|
var group = new LearningGroup { Name = "9c" };
|
|
var today = DateOnly.FromDateTime(DateTime.Today);
|
|
var lesson = new Lesson { GroupId = group.Id, Date = today, LessonNumber = 3, Topic = "Redox" };
|
|
var slots = new FakeTimetableSlots();
|
|
slots.Add(new TimetableSlot { GroupId = group.Id, Weekday = today.DayOfWeek, PeriodNumber = 3, Room = "R204" });
|
|
|
|
var vm = BuildVm(group, lesson, slots: slots);
|
|
|
|
var item = Assert.Single(vm.TodaysLessons);
|
|
Assert.Equal("R204", item.Room);
|
|
Assert.True(item.HasRoom);
|
|
}
|
|
|
|
[Fact]
|
|
public void TodaysLessons_OhnePassendenSlot_HatKeinenRaum()
|
|
{
|
|
var group = new LearningGroup { Name = "9c" };
|
|
var today = DateOnly.FromDateTime(DateTime.Today);
|
|
var lesson = new Lesson { GroupId = group.Id, Date = today, LessonNumber = 3, Topic = "Redox" };
|
|
|
|
var vm = BuildVm(group, lesson);
|
|
|
|
var item = Assert.Single(vm.TodaysLessons);
|
|
Assert.False(item.HasRoom);
|
|
Assert.Equal("", item.Room);
|
|
}
|
|
|
|
[Fact]
|
|
public void TodaysLessons_ZeitKommtAusLessonStartTimeWennGesetzt()
|
|
{
|
|
var group = new LearningGroup { Name = "9c" };
|
|
var today = DateOnly.FromDateTime(DateTime.Today);
|
|
var lesson = new Lesson
|
|
{
|
|
GroupId = group.Id, Date = today, LessonNumber = 3, Topic = "Redox",
|
|
StartTime = new TimeOnly(9, 15),
|
|
};
|
|
var periodSchedule = NewPeriodSchedule();
|
|
periodSchedule.SetPeriods([new PeriodTimeEntry { PeriodNumber = 3, Start = new TimeOnly(10, 0), End = new TimeOnly(10, 45) }]);
|
|
|
|
var vm = BuildVm(group, lesson, periodSchedule: periodSchedule);
|
|
|
|
Assert.Equal("09:15", Assert.Single(vm.TodaysLessons).TimeDisplay);
|
|
}
|
|
|
|
[Fact]
|
|
public void TodaysLessons_OhneStartTime_FaelltAufStundenrasterZurueck()
|
|
{
|
|
var group = new LearningGroup { Name = "9c" };
|
|
var today = DateOnly.FromDateTime(DateTime.Today);
|
|
var lesson = new Lesson { GroupId = group.Id, Date = today, LessonNumber = 3, Topic = "Redox" };
|
|
var periodSchedule = NewPeriodSchedule();
|
|
periodSchedule.SetPeriods([new PeriodTimeEntry { PeriodNumber = 3, Start = new TimeOnly(10, 0), End = new TimeOnly(10, 45) }]);
|
|
|
|
var vm = BuildVm(group, lesson, periodSchedule: periodSchedule);
|
|
|
|
Assert.Equal("10:00", Assert.Single(vm.TodaysLessons).TimeDisplay);
|
|
}
|
|
|
|
[Fact]
|
|
public void OpenLesson_RuftNavigationMitGruppenIdAuf()
|
|
{
|
|
var group = new LearningGroup { Name = "9c" };
|
|
var today = DateOnly.FromDateTime(DateTime.Today);
|
|
var lesson = new Lesson { GroupId = group.Id, Date = today, LessonNumber = 3, Topic = "Redox" };
|
|
var vm = BuildVm(group, lesson);
|
|
|
|
Guid? navigatedTo = null;
|
|
vm.OnNavigateToLesson = id => navigatedTo = id;
|
|
|
|
vm.OpenLessonCommand.Execute(vm.TodaysLessons[0]);
|
|
|
|
Assert.Equal(group.Id, navigatedTo);
|
|
}
|
|
}
|