using LehrerApp.Core.Models; using LehrerApp.Desktop.ViewModels.Groups; using Xunit; namespace LehrerApp.Desktop.Tests; public sealed class TeachingModeViewModelTests { private static SeatingPlanTabViewModel BuildSeatingPlan(Guid groupId, FakeSessions? sessions = null, List? students = null, List? memberships = null, List? plans = null) => new(new FakeSeatingPlans(plans ?? [new SeatingPlan { GroupId = groupId, Name = "Standard", Rows = 1, Columns = 1 }]), new FakeStudents(students ?? []), new FakeMemberships(memberships ?? []), sessions ?? new FakeSessions([]), new FakeEntries(), new FakeAspects()); [Fact] public void Konstruktor_LaedtVerlaufsplanUndInitialisiertSitzplanFuerDieGruppe() { var group = new LearningGroup { Name = "Q1 Chemie" }; var lesson = new Lesson { GroupId = group.Id, Date = DateOnly.FromDateTime(DateTime.Today), Topic = "Redox", Phases = [new LessonPhaseStep { Name = "Einstieg", DurationMinutes = 10, Activity = "Impuls" }], }; var seatingPlan = BuildSeatingPlan(group.Id); var vm = new TeachingModeViewModel(lesson, group, new FakeAlternativeLessonPaths([]), seatingPlan); Assert.Equal("Q1 Chemie", vm.GroupName); Assert.Equal("Redox", vm.LessonInfo.Topic); Assert.Single(vm.LessonInfo.PhaseGroups.Single().Phases); Assert.True(vm.SeatingPlan.HasSelectedPlan); } [Fact] public void Konstruktor_VerknuepftDieSitzungMitDieserStunde() { var group = new LearningGroup { Name = "Q1 Chemie" }; var lesson = new Lesson { GroupId = group.Id, Date = DateOnly.FromDateTime(DateTime.Today), Topic = "Redox" }; var sessions = new FakeSessions([]); var seatingPlan = BuildSeatingPlan(group.Id, sessions); var vm = new TeachingModeViewModel(lesson, group, new FakeAlternativeLessonPaths([]), seatingPlan); var created = Assert.Single(sessions.GetByGroup(group.Id)); Assert.Equal(lesson.Id, created.LessonId); Assert.Equal(vm.SeatingPlan.SelectedSession?.Id, created.Id); } [Fact] public void Konstruktor_BereitsExistierendeVerknuepfteSitzung_WirdWiederverwendet() { var group = new LearningGroup { Name = "Q1 Chemie" }; var lesson = new Lesson { GroupId = group.Id, Date = DateOnly.FromDateTime(DateTime.Today), Topic = "Redox" }; var existing = new ParticipationSession { GroupId = group.Id, Date = lesson.Date, LessonId = lesson.Id, Comment = "Redox" }; var sessions = new FakeSessions([existing]); var seatingPlan = BuildSeatingPlan(group.Id, sessions); var vm = new TeachingModeViewModel(lesson, group, new FakeAlternativeLessonPaths([]), seatingPlan); Assert.Single(sessions.GetByGroup(group.Id)); Assert.Equal(existing.Id, vm.SeatingPlan.SelectedSession?.Id); } /// Eine archivierte Gruppe darf im Unterrichtsmodus nicht bearbeitbar sein - genau wie in der /// normalen Gruppenansicht (GroupDetailViewModel.IsReadOnly). [Fact] public void Konstruktor_ArchivierteGruppe_InitialisiertSitzplanSchreibgeschuetzt() { var group = new LearningGroup { Name = "Q1 Chemie", IsActive = false }; var lesson = new Lesson { GroupId = group.Id, Date = DateOnly.FromDateTime(DateTime.Today), Topic = "Redox" }; var seatingPlan = BuildSeatingPlan(group.Id); var vm = new TeachingModeViewModel(lesson, group, new FakeAlternativeLessonPaths([]), seatingPlan); Assert.False(vm.SeatingPlan.IsEditable); } }