using Bunit; using Duempelkas.App.Components; using Duempelkas.App.Services; using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Duempelkas.Tests; public class ToastTests { [Fact] public async Task ToastsStack_ExpireIndependently_AndPauseDuringInteraction() { using var context = new BunitContext(); context.Services.AddSingleton(); var host = context.Render(); var service = context.Services.GetRequiredService(); var first = service.Show("Erste Meldung", duration: TimeSpan.FromMilliseconds(100)); service.Pause(first); service.Show("Zweite Meldung", ToastKind.Success, persistent: true); host.WaitForAssertion(() => Assert.Equal(2, host.FindAll(".app-toast").Count)); await Task.Delay(200); Assert.Equal(2, service.Messages.Count); service.Resume(first); host.WaitForAssertion(() => Assert.Single(host.FindAll(".app-toast"))); Assert.Contains("Zweite Meldung", host.Markup); host.Find(".toast-close").Click(); Assert.Empty(service.Messages); } [Fact] public void AmountControl_RejectsWholePasteWithoutRounding() { using var context = new BunitContext(); string amount = "12,50"; var control = context.Render(p => p.Add(x => x.Value, amount).Add(x => x.ValueChanged, value => amount = value)); control.Find("input").Input("12,501"); Assert.Equal("12,50", amount); Assert.Empty(control.FindAll("[role=status]")); control.Find("input").Input("12.25"); Assert.Equal("12.25", amount); } }