Guard dialog completion by presentation identity
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
using Bunit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
|
||||
|
||||
/// <summary>A late native activation result belongs to its original presentation.</summary>
|
||||
public sealed class DialogHostPresentationIdentityTests : BunitContext
|
||||
{
|
||||
/// <summary>Rejecting a closed confirm cannot cancel a prompt that has since opened.</summary>
|
||||
[Fact]
|
||||
public async Task LateActivationRejection_DoesNotCancelReplacementPrompt()
|
||||
{
|
||||
var service = new DialogService();
|
||||
Services.AddSingleton<IDialogService>(service);
|
||||
JSInterop.Mode = JSRuntimeMode.Loose;
|
||||
var firstActivation = JSInterop.Setup<bool?>("sbDialog.activate", call => call.Arguments[1] is null);
|
||||
JSInterop.Setup<bool?>("sbDialog.activate", call => call.Arguments[1] is not null).SetResult(true);
|
||||
var cut = Render<DialogHost>();
|
||||
Task<bool> first = null!;
|
||||
await cut.InvokeAsync(() => { first = service.ConfirmAsync("First", "Synthetic confirm"); });
|
||||
cut.WaitForAssertion(() => Assert.Single(firstActivation.Invocations));
|
||||
await cut.InvokeAsync(() => service.Resolve(false));
|
||||
Assert.False(await first);
|
||||
Task<string?> second = null!;
|
||||
await cut.InvokeAsync(() => { second = service.PromptAsync("Second", "Synthetic prompt", "retained"); });
|
||||
cut.WaitForAssertion(() => Assert.Equal("retained", cut.Find("input").GetAttribute("value")));
|
||||
firstActivation.SetResult(false);
|
||||
cut.WaitForAssertion(() => Assert.Equal("Second", service.Current?.Title));
|
||||
await cut.InvokeAsync(() => cut.Find("button.btn-close").Click());
|
||||
Assert.Null(await second);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user