Add animated classroom grouping with saved editable plans
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
admin committed 2026-09-29 22:17:49 +02:00
1 parent d4b1419f9a
commit f0462bd2a1
27 files changed
+775 -46

No files matched your search

+16
View File
@@ -179,6 +179,22 @@ public class FakeSeatingPlans(List<SeatingPlan>? initial = null) : ISeatingPlanR
public void Restore(Guid trashId) { }
}
public class FakeStudentGroupPlans : IStudentGroupPlanRepository
{
private readonly List<StudentGroupPlan> _plans = [];
public StudentGroupPlan? GetById(Guid id) => _plans.FirstOrDefault(p => p.Id == id);
public List<StudentGroupPlan> GetByGroup(Guid groupId) =>
_plans.Where(p => p.GroupId == groupId).ToList();
public List<StudentGroupPlan> GetByStudent(Guid studentId) =>
_plans.Where(p => p.Groups.Any(g => g.StudentIds.Contains(studentId))).ToList();
public void Save(StudentGroupPlan plan)
{
_plans.RemoveAll(p => p.Id == plan.Id);
_plans.Add(plan);
}
public void Delete(Guid id) => _plans.RemoveAll(p => p.Id == id);
}
public class FakeTrash(List<TrashedItem>? initial = null) : ITrashRepository
{
private readonly List<TrashedItem> _all = initial ?? [];
@@ -31,8 +31,14 @@ public sealed class PersonalDataExportServiceTests
Assignments = [new SeatAssignment { Row = 1, Column = 2, StudentId = studentId }],
},
]);
var groupPlans = new FakeStudentGroupPlans();
groupPlans.Save(new StudentGroupPlan
{
GroupId = groupId, Name = "Projektwoche",
Groups = [new StudentGroupPlanGroup { StudentIds = [studentId] }],
});
var service = new PersonalDataExportService(students, groups, memberships, grades, results, entries,
documentation, seatingPlans);
documentation, seatingPlans, groupPlans);
var json = service.ExportAsJson(studentId);
@@ -41,6 +47,7 @@ public sealed class PersonalDataExportServiceTests
Assert.Contains("\"Value\": \"2\"", json);
Assert.Contains("\"Sitzplan\": \"Standard\"", json);
Assert.Contains("\"Reihe\": 2", json);
Assert.Contains("Projektwoche", json);
}
[Fact]
@@ -53,4 +60,23 @@ public sealed class PersonalDataExportServiceTests
Assert.Throws<InvalidOperationException>(() => service.ExportAsJson(Guid.NewGuid()));
}
[Fact]
public void ExportAsJson_EnthaeltGespeichertenPlanAuchNachEndeDerMitgliedschaft()
{
var student = new Student { FirstName = "Anna", LastName = "Beispiel" };
var groupId = Guid.NewGuid();
var plans = new FakeStudentGroupPlans();
plans.Save(new StudentGroupPlan
{
GroupId = groupId, Name = "Alte Projektgruppe",
Groups = [new StudentGroupPlanGroup { StudentIds = [student.Id] }],
});
var service = new PersonalDataExportService(
new FakeStudents([student]), new FakeGroups([]), new FakeMemberships([]),
new FakeGrades(), new FakeResults(), new FakeEntries(), new FakeDocumentation(),
new FakeSeatingPlans(), plans);
Assert.Contains("Alte Projektgruppe", service.ExportAsJson(student.Id));
}
}
@@ -7,7 +7,8 @@ namespace LehrerApp.Desktop.Tests;
public sealed class StudentGroupGeneratorViewModelTests
{
private static (StudentGroupGeneratorViewModel Vm, List<Student> Students, LearningGroup Group,
FakeSessions Sessions, FakeEntries Entries) Build(int studentCount = 10)
FakeSessions Sessions, FakeEntries Entries) Build(int studentCount = 10,
FakeStudentGroupPlans? savedPlans = null)
{
var group = new LearningGroup { Name = "8a", GradingSystem = GradingSystem.Grades1To6 };
var students = Enumerable.Range(1, studentCount).Select(i => new Student
@@ -22,10 +23,77 @@ public sealed class StudentGroupGeneratorViewModelTests
var entries = new FakeEntries();
var vm = new StudentGroupGeneratorViewModel(
new FakeStudents(students), new FakeGroups([group]), new FakeMemberships(memberships),
sessions, entries, new FakeGrades(), group.Id, new Random(7));
sessions, entries, new FakeGrades(), group.Id, new Random(7), savedPlans);
return (vm, students, group, sessions, entries);
}
[Fact]
public void ManuelleUmverteilung_WirdGespeichertUndSpaeterWiederGeladen()
{
var plans = new FakeStudentGroupPlans();
var (vm, students, group, _, _) = Build(6, plans);
vm.TargetGroupCount = 2;
vm.CountPriority = 100;
vm.GenerateCommand.Execute(null);
var source = vm.GeneratedGroups[0];
var target = vm.GeneratedGroups[1];
var member = source.Members[0];
Assert.True(vm.MoveStudent(member, target));
Assert.False(vm.MoveStudent(member, target));
Assert.DoesNotContain(member, source.Members);
vm.PlanName = "Projektwoche";
vm.SavePlanCommand.Execute(null);
var saved = Assert.Single(plans.GetByGroup(group.Id));
Assert.Equal("Projektwoche", saved.Name);
Assert.Contains(member.Id, saved.Groups[1].StudentIds);
Assert.False(vm.HasUnsavedChanges);
vm.GenerateCommand.Execute(null);
vm.SelectedSavedPlan = Assert.Single(vm.SavedPlans);
vm.LoadSavedPlanCommand.Execute(null);
Assert.Contains(vm.GeneratedGroups[1].Members, m => m.Id == member.Id);
Assert.DoesNotContain(vm.GeneratedGroups[0].Members, m => m.Id == member.Id);
Assert.False(vm.HasUnsavedChanges);
Assert.Equal("Projektwoche", vm.PlanName);
var reopened = new StudentGroupGeneratorViewModel(
new FakeStudents(students), new FakeGroups([group]),
new FakeMemberships(students.Select(s => new GroupMembership
{
GroupId = group.Id, StudentId = s.Id,
}).ToList()),
new FakeSessions([]), new FakeEntries(), new FakeGrades(), group.Id,
savedPlans: plans);
reopened.SelectedSavedPlan = Assert.Single(reopened.SavedPlans);
reopened.LoadSavedPlanCommand.Execute(null);
Assert.Contains(reopened.GeneratedGroups[1].Members, m => m.Id == member.Id);
reopened.PlanName = "Projektwoche aktualisiert";
reopened.SavePlanCommand.Execute(null);
Assert.Equal("Projektwoche aktualisiert", Assert.Single(plans.GetByGroup(group.Id)).Name);
}
[Fact]
public void SpeichernUeberschreibtAusgewaehltenPlanErstNachDemLaden()
{
var plans = new FakeStudentGroupPlans();
var (vm, _, group, _, _) = Build(6, plans);
vm.GenerateCommand.Execute(null);
vm.PlanName = "Alter Plan";
vm.SavePlanCommand.Execute(null);
vm.GenerateCommand.Execute(null);
vm.SelectedSavedPlan = Assert.Single(vm.SavedPlans);
vm.PlanName = "Neuer Plan";
vm.SavePlanCommand.Execute(null);
Assert.Equal(2, plans.GetByGroup(group.Id).Count);
Assert.Contains(plans.GetByGroup(group.Id), p => p.Name == "Alter Plan");
Assert.Contains(plans.GetByGroup(group.Id), p => p.Name == "Neuer Plan");
}
[Fact]
public void FesteZielgroesse_ErzeugtPassendeAnzahlMitKleinerAusnahme()
{