Observe serialized modal activation through its actual JS invocation

This commit is contained in:
Joseph Doherty
2026-11-14 01:46:16 -05:00
parent 50ab406de7
commit ef1609f523
5 changed files with 920 additions and 6 deletions
@@ -91,10 +91,18 @@ public sealed class ModalAccessibilityTests : BunitContext
/// <summary>A new target queued during activation opens only after the old native generation is cleaned.</summary>
[Fact]
public void Frame_TargetSwitchDuringDeferredActivation_IsSerialized()
public async Task Frame_TargetSwitchDuringDeferredActivation_IsSerialized()
{
var activation = JSInterop.Setup<bool>("otDialog.activate", _ => true);
var openedReplacement = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
long firstGeneration = 0;
var activation = JSInterop.Setup<bool>("otDialog.activate", call =>
{
if (firstGeneration > 0 && Convert.ToInt64(call.Arguments[2]) > firstGeneration)
openedReplacement.TrySetResult(true);
return true;
});
var cut = Render<ModalFrame>(p => p.Add(x => x.Visible, true).Add(x => x.Target, "A"));
firstGeneration = Convert.ToInt64(JSInterop.Invocations["otDialog.activate"][0].Arguments[2]);
try
{
cut.Render(p => p.Add(x => x.Visible, false));
@@ -102,10 +110,16 @@ public sealed class ModalAccessibilityTests : BunitContext
JSInterop.Invocations["otDialog.activate"].Count.ShouldBe(1);
}
finally { activation.SetResult(true); }
cut.WaitForAssertion(() => JSInterop.Invocations["otDialog.activate"].Count.ShouldBe(2));
var generations = JSInterop.Invocations["otDialog.activate"].Select(call => Convert.ToInt64(call.Arguments[2])).ToArray();
generations[1].ShouldBeGreaterThan(generations[0]);
JSInterop.Invocations["otDialog.deactivate"].Count.ShouldBeGreaterThan(0);
// JS-only OnAfterRender continuations do not require another component render. Observe the
// actual replacement invocation, then inspect its recorded calls on the renderer dispatcher.
await openedReplacement.Task.WaitAsync(TimeSpan.FromSeconds(5), Xunit.TestContext.Current.CancellationToken);
await cut.InvokeAsync(() =>
{
JSInterop.Invocations["otDialog.activate"].Count.ShouldBe(2);
var generations = JSInterop.Invocations["otDialog.activate"].Select(call => Convert.ToInt64(call.Arguments[2])).ToArray();
generations[1].ShouldBeGreaterThan(generations[0]);
JSInterop.Invocations["otDialog.deactivate"].Count.ShouldBeGreaterThan(0);
});
}
/// <summary>A stale Escape cannot close a different reopened target.</summary>