using Bunit; using Microsoft.Extensions.DependencyInjection; using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared; /// A late native activation result belongs to its original presentation. public sealed class DialogHostPresentationIdentityTests : BunitContext { /// Rejecting a closed confirm cannot cancel a prompt that has since opened. [Fact] public async Task LateActivationRejection_DoesNotCancelReplacementPrompt() { var service = new DialogService(); Services.AddSingleton(service); JSInterop.Mode = JSRuntimeMode.Loose; var firstActivation = JSInterop.Setup("sbDialog.activate", call => call.Arguments[1] is null); JSInterop.Setup("sbDialog.activate", call => call.Arguments[1] is not null).SetResult(true); var cut = Render(); Task 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 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); } }