Files
LehrerApp/LehrerApp.Desktop.Tests/StudentWarningEvidenceTests.cs
T
adminandClaude Opus 5.5 aa326cf8b6
CI / build-and-test (push) Canceled after 0s
Add warning detail popup and quick blocks for Vorgänge
Dashboard warnings (attendance, homework, lateness) get a "Details" flyout
with key figures, a list of dates and the compact month calendar from the
class teacher overview, now extracted as a shared control. The calendar
now aligns days under their weekday (Mo-So header, blank leading cells).

Creating Vorgänge and documentation is supported by quick blocks with the
current figures, dated standard phrases (e.g. "Klassenleitung informiert")
and documentation templates (status snapshot, conversation, informing the
class/subject teachers, parent call, parent letter). The class teacher
Vorgänge tab uses WebUntis figures (absences across all subjects, class
register) for the same blocks and templates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 11:16:13 +02:00

168 lines
7.4 KiB
C#

using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels;
using LehrerApp.Desktop.ViewModels.ClassTeacher;
using LehrerApp.Desktop.ViewModels.Students;
using Xunit;
namespace LehrerApp.Desktop.Tests;
/// Tests für die Belege hinter den klassenübergreifenden Dashboard-Warnungen: das Detail-Popup
/// (StudentWarningDetailViewModel), die Schnellbausteine im Vorgang-Dialog und die
/// Dokumentationsvorlagen im schülerbezogenen Vorgänge-Tab. Alle Termine liegen ab
/// Schuljahresbeginn, damit die Tests unabhängig vom Ausführungsdatum im laufenden Schuljahr landen.
public sealed class StudentWarningEvidenceTests
{
private readonly Student _student = new() { FirstName = "Anna", LastName = "Beispiel" };
private readonly LearningGroup _group = new() { Name = "9c Mathe" };
private readonly List<ParticipationSession> _sessions = [];
private readonly FakeEntries _entries = new();
private readonly DateOnly _start;
public StudentWarningEvidenceTests()
{
var sy = new SchoolYearService();
_start = sy.SchoolYearStart(sy.CurrentSchoolYear());
}
private void AddEntry(int dayOffset, AttendanceStatus? attendance = null, HomeworkStatus? homework = null)
{
var session = new ParticipationSession { GroupId = _group.Id, Date = _start.AddDays(dayOffset) };
_sessions.Add(session);
_entries.Add(new ParticipationEntry
{ SessionId = session.Id, StudentId = _student.Id, Attendance = attendance, Homework = homework });
}
private StudentWarningEvidenceService BuildService() => new(new FakeStudents([_student]),
new FakeSessions(_sessions), _entries, new FakeGroups([_group]), new SchoolYearService(),
new AttendanceBalanceService());
[Fact]
public void Build_ZaehltWieDieDashboardWarnungen()
{
AddEntry(0, AttendanceStatus.Present);
AddEntry(1, AttendanceStatus.Excused);
AddEntry(2, AttendanceStatus.Unexcused);
AddEntry(3, AttendanceStatus.ExcusePending);
AddEntry(4, AttendanceStatus.OtherSchoolEvent);
AddEntry(5, AttendanceStatus.Late, HomeworkStatus.MissingOpen);
AddEntry(6, AttendanceStatus.SignificantlyLate, HomeworkStatus.Completed);
var e = BuildService().Build(_student.Id);
Assert.Equal(7, e.Balance.TotalChecked);
Assert.Equal(3, e.Absences.Count); // Schulveranstaltung zählt nicht als Fehlzeit
Assert.Equal(["A", "U", "E"], e.Absences.Select(a => a.Code)); // neueste zuerst
Assert.Equal(2, e.Lateness.Count);
Assert.Equal(1, e.SignificantlyLateCount);
Assert.Equal("9c Mathe", Assert.Single(e.MissingHomework).GroupName);
Assert.Equal("Anna Beispiel", e.StudentNaturalName);
}
[Fact]
public void QuickBlocks_NurBausteineMitInhalt()
{
AddEntry(0, AttendanceStatus.Unexcused);
AddEntry(1, AttendanceStatus.Present);
var blocks = StudentEvidenceText.QuickBlocks(BuildService().Build(_student.Id));
Assert.Equal(["Fehlquote", "Fehltermine"], blocks.Select(b => b.Label));
Assert.Contains("Fehlquote 50 %", blocks[0].Text);
Assert.Contains("9c Mathe", blocks[1].Text);
}
[Fact]
public void VorgangDialog_InsertQuickBlock_HaengtAnStattZuErsetzen()
{
var vm = new VorgangDialogViewModel([new StudentOption(_student.Id, "Anna")], null,
[new VorgangQuickBlock("Fehlquote", "Stand: 25 %")]) { Description = "Eigene Notiz" };
vm.InsertQuickBlockCommand.Execute(vm.QuickBlocks[0]);
Assert.Equal("Eigene Notiz\n\nStand: 25 %", vm.Description);
Assert.Equal("Vorgang anlegen", vm.DialogTitle);
}
[Fact]
public void Vorlage_ElternanrufUebernimmtZahlenPassendZumVorgangsTag()
{
for (var i = 0; i < 3; i++) AddEntry(i, AttendanceStatus.Present, HomeworkStatus.MissingOverdue);
var vorgang = new Vorgang { Title = "Hausaufgaben", StudentIds = [_student.Id], Tags = ["Hausaufgaben"] };
var doc = VorgangDocumentationTemplates.Build(VorgangDocumentationTemplates.ParentCall, vorgang,
BuildService().Build(_student.Id))!;
Assert.Equal(DocumentationType.ParentCall, doc.Type);
Assert.Equal(_student.Id, doc.StudentId);
Assert.StartsWith("Aktueller Stand: 3 nicht bzw. unvollständig erledigte Hausaufgaben", doc.ParentCallData!.Points[0].Text);
Assert.DoesNotContain(doc.ParentCallData.Points, p => p.Text.Contains("Fehlquote"));
}
[Fact]
public void DetailPopup_StartetImMonatDesJuengstenBelegsUndZeigtKuerzel()
{
AddEntry(0, AttendanceStatus.Unexcused);
AddEntry(0, AttendanceStatus.Excused); // zweite Stunde am selben Tag: U gewinnt
AddEntry(1, AttendanceStatus.Late);
var vm = new StudentWarningDetailViewModel(AttentionKind.Attendance, BuildService().Build(_student.Id));
Assert.Equal(new DateOnly(_start.Year, _start.Month, 1), vm.Month);
var first = vm.CalendarDays.Single(d => d.Date == _start);
Assert.Equal("U", first.SignalCode);
Assert.Contains("Krank, entschuldigt", first.Tooltip);
Assert.Equal("V", vm.CalendarDays.Single(d => d.Date == _start.AddDays(1)).SignalCode);
Assert.False(vm.PreviousMonthCommand.CanExecute(null)); // vor Schuljahresbeginn gibt es nichts
Assert.Equal(2, vm.Events.Count);
}
[Fact]
public async Task HandleWarningNavigation_BelegtBeschreibungMitAktuellemStandVor()
{
for (var i = 0; i < 4; i++) AddEntry(i, AttendanceStatus.Unexcused);
var vm = new StudentVorgaengeViewModel(new FakeVorgangRepository(), new FakeDocumentation(),
new FakeStudents([_student]), BuildService());
vm.Load(_student.Id);
vm.OnConfirmCreateForWarning = _ => Task.FromResult(true);
Vorgang? draft = null;
vm.OnEditVorgang = (_, editing) => { draft = editing; return Task.FromResult<Vorgang?>(null); };
await vm.HandleWarningNavigation("Absentismus", "Fehlzeiten");
Assert.Contains("Fehlquote 100 %", draft!.Description);
Assert.Contains("Fehltermine:", draft.Description);
Assert.False(vm.IsPersisted(draft));
}
[Fact]
public async Task VorlageAusVorgangstab_OeffnetEntwurfUndVerknuepftNachSpeichern()
{
AddEntry(0, AttendanceStatus.Unexcused);
var vorgaenge = new FakeVorgangRepository();
var vorgang = new Vorgang { Title = "Fehlzeiten", StudentIds = [_student.Id], Tags = ["Absentismus"] };
vorgaenge.Add(vorgang);
var documentation = new FakeDocumentation();
var vm = new StudentVorgaengeViewModel(vorgaenge, documentation, new FakeStudents([_student]), BuildService());
vm.Load(_student.Id);
var wasDraft = false;
vm.OnEditDocumentation = (_, editing) =>
{
wasDraft = vm.IsNewDocumentationDraft(editing!);
return Task.FromResult(editing);
};
var item = Assert.Single(vm.Cases);
Assert.True(item.HasDocumentationTemplates);
await item.CreateFromTemplateCommand.ExecuteAsync(VorgangDocumentationTemplates.Conversation);
Assert.True(wasDraft);
var saved = Assert.Single(documentation.GetByStudent(_student.Id));
Assert.Equal(DocumentationType.Conversation, saved.Type);
Assert.Contains("Fehlquote 100 %", saved.Content);
Assert.Contains(saved.Id, vorgang.DocumentationIds);
Assert.True(Assert.Single(vm.Cases).IsRevealed);
}
}