Files
duempelkas/tests/Duempelkas.Tests/ModalDialogTests.cs
T

45 lines
1.8 KiB
C#

using Bunit;
using Duempelkas.App.Components.Dialogs;
using Duempelkas.App.Services;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Duempelkas.Tests;
public class ModalDialogTests
{
[Fact]
public async Task EscapeRequest_ClosesCleanDialog_ButProtectsDirtyInput()
{
using var context = new BunitContext();
context.JSInterop.Mode = JSRuntimeMode.Loose;
context.Services.AddSingleton<ToastService>();
var cancelled = 0;
var modal = context.Render<ModalDialog>(p => p.Add(x => x.Title, "Testdialog").Add(x => x.OnCancel, () => cancelled++));
Assert.NotNull(modal.Find("dialog").GetAttribute("aria-labelledby"));
await modal.InvokeAsync(() => modal.Instance.RequestCloseAsync());
Assert.Equal(1, cancelled);
modal.Render(p => p.Add(x => x.Dirty, true));
await modal.InvokeAsync(() => modal.Instance.RequestCloseAsync());
Assert.Equal(1, cancelled);
Assert.Contains("Ungespeicherte Eingaben", modal.Markup);
modal.Find("[data-discard-continue]").Click();
Assert.Empty(modal.FindAll("[role=alertdialog]"));
await modal.InvokeAsync(() => modal.Instance.RequestCloseAsync());
modal.Find("button.btn-outline-danger").Click();
Assert.Equal(2, cancelled);
}
[Fact]
public async Task BusyDialog_CannotClose()
{
using var context = new BunitContext();
context.JSInterop.Mode = JSRuntimeMode.Loose;
context.Services.AddSingleton<ToastService>();
var cancelled = false;
var modal = context.Render<ModalDialog>(p => p.Add(x => x.Busy, true).Add(x => x.OnCancel, () => cancelled = true));
await modal.InvokeAsync(() => modal.Instance.RequestCloseAsync());
Assert.False(cancelled);
}
}