using LehrerApp.Core.AiPlanning; using LehrerApp.Desktop.Services; using LehrerApp.Desktop.ViewModels.Groups; using Xunit; namespace LehrerApp.Desktop.Tests; /// Tests für das "Schattenfeld" (4.5.21): didaktischer Hintergrund zu einer KI-Stunde, nur auf /// Klick nachgeladen. Die eigentliche HTTP-Abfrage (AiPlanningService.RequestExplanationAsync) /// wird hier per Delegate ersetzt, da RequestExplanationCommand rein davon abhängt. public sealed class AiLessonReviewItemTests { private static AiLesson Lesson() => new() { Topic = "Elektrolyse", Phases = [] }; [Fact] public async Task RequestExplanation_SetztText_UndVerbirgtButtonDanach() { var item = new AiLessonReviewItem(Lesson(), isNew: true, requestExplanation: _ => Task.FromResult("Didaktischer Hintergrund...")); Assert.True(item.ShowExplanationButton); await item.RequestExplanationCommand.ExecuteAsync(null); Assert.Equal("Didaktischer Hintergrund...", item.Explanation); Assert.False(item.ShowExplanationButton); Assert.False(item.IsLoadingExplanation); Assert.Equal("", item.ExplanationError); } [Fact] public async Task RequestExplanation_BeiFehler_SetztExplanationErrorUndBehaeltButton() { var item = new AiLessonReviewItem(Lesson(), isNew: true, requestExplanation: _ => throw new AiBackendException("Nicht genügend KI-Guthaben.")); await item.RequestExplanationCommand.ExecuteAsync(null); Assert.Equal("Nicht genügend KI-Guthaben.", item.ExplanationError); Assert.Equal("", item.Explanation); Assert.True(item.ShowExplanationButton); } [Fact] public void OhneAbfragefunktion_WirdKeinButtonAngeboten() { var item = new AiLessonReviewItem(Lesson(), isNew: true); Assert.False(item.CanRequestExplanation); Assert.False(item.ShowExplanationButton); } }