44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
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<ToastService>();
|
|
var host = context.Render<ToastHost>();
|
|
var service = context.Services.GetRequiredService<ToastService>();
|
|
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<AmountInput>(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.Contains("nicht übernommen", control.Markup);
|
|
control.Find("input").Input("12.25");
|
|
Assert.Equal("12.25", amount);
|
|
}
|
|
}
|