Guard and name Raw manual entry and browsing workflows
This commit is contained in:
+333
@@ -0,0 +1,333 @@
|
||||
using System.Reflection;
|
||||
using Bunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Browsing;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Browsing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Raw;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Raw workflow modal naming and presentation-owned mutations.</summary>
|
||||
[Trait("Category","Unit")]
|
||||
public sealed class RawWorkflowModalAccessibilityTests:BunitContext
|
||||
{
|
||||
public RawWorkflowModalAccessibilityTests()
|
||||
{
|
||||
JSInterop.Setup<bool>("otDialog.activate",_=>true).SetResult(true);
|
||||
JSInterop.SetupVoid("otDialog.update",_=>true).SetVoidResult();
|
||||
JSInterop.SetupVoid("otDialog.deactivate",_=>true).SetVoidResult();
|
||||
Services.AddSingleton(DispatchProxy.Create<IRawTreeService,ManualService>());
|
||||
}
|
||||
private ManualService Service=>(ManualService)Services.GetRequiredService<IRawTreeService>();
|
||||
private IRenderedComponent<RawManualTagEntryModal> Manual(string device="A")=>Render<RawManualTagEntryModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,device).Add(c=>c.DriverType,"Unmapped"));
|
||||
[Fact]
|
||||
public void Manual_HasNamedModalScopedFieldsAndSafeEntry()
|
||||
{
|
||||
var a=Manual();var b=Manual();
|
||||
foreach(var cut in new[]{a,b})
|
||||
{
|
||||
var dialog=cut.Find("[role=dialog]");dialog.GetAttribute("aria-modal").ShouldBe("true");
|
||||
cut.Find("#"+dialog.GetAttribute("aria-labelledby")).TextContent.ShouldContain("manual entry");
|
||||
cut.Find("[data-initial-focus]").TextContent.ShouldContain("Cancel");
|
||||
foreach(var field in cut.FindAll("input,select,textarea"))
|
||||
{field.Id.ShouldNotBeNullOrWhiteSpace();field.GetAttribute("aria-labelledby").ShouldNotBeNullOrWhiteSpace();foreach(var id in field.GetAttribute("aria-labelledby")!.Split(' '))cut.Find("#"+id).ShouldNotBeNull();}
|
||||
}
|
||||
var ids=a.FindAll("[id]").Concat(b.FindAll("[id]")).Select(e=>e.Id).ToArray();ids.Distinct().Count().ShouldBe(ids.Length);
|
||||
}
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task Manual_PendingWriteIsSingleFlightAndCannotModifyReplacement(bool exception)
|
||||
{
|
||||
var cut=Manual();cut.Find("input").Change("Original");
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Service.Entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
Task? duplicate=null;
|
||||
try
|
||||
{
|
||||
duplicate=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Task.Yield();
|
||||
Service.Inputs.Count.ShouldBe(1);
|
||||
cut.Render(p=>p.Add(c=>c.DeviceId,"B"));
|
||||
cut.Find("input").Change("Queued edit while pending");
|
||||
cut.Find("input").GetAttribute("value").ShouldBe("");
|
||||
}
|
||||
finally {if(exception) Service.Reply.SetException(new IOException("Retired write failure"));else Service.Reply.SetResult(new(false,"Synthetic refusal"));await Task.WhenAll(saving,duplicate??Task.CompletedTask);}
|
||||
cut.Find("input").Change("Replacement");
|
||||
cut.Find("input").GetAttribute("value").ShouldBe("Replacement");
|
||||
cut.Markup.ShouldNotContain("Synthetic refusal");
|
||||
Service.Inputs.Single().Device.ShouldBe("A");Service.Inputs.Single().Input.Name.ShouldBe("Original");
|
||||
}
|
||||
[Fact]
|
||||
public void Manual_InvalidNameReportsLinkedErrorWithoutDispatch()
|
||||
{
|
||||
var cut=Manual();cut.Find(".modal-footer .btn-primary").Click();
|
||||
var field=cut.Find("input");field.GetAttribute("aria-invalid").ShouldBe("true");
|
||||
cut.Find("#"+field.GetAttribute("aria-describedby")).TextContent.ShouldNotBeNullOrWhiteSpace();
|
||||
Service.Inputs.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Manual_AllInputsAreFrozenBeforeFirstWriteAndPartialFailureRetainsOnlyFailedRow()
|
||||
{
|
||||
var cut=Manual();cut.Find("button.btn-outline-primary").Click();
|
||||
cut.FindAll("input[placeholder=TagName]")[0].Change("First");
|
||||
cut.FindAll("input[placeholder=TagName]")[1].Change("Second");
|
||||
cut.Find("button[aria-label='Configure tag row 1']").Click();
|
||||
cut.Find("textarea").Change("{\"unknown\":\"first-extension\"}");
|
||||
cut.Find("button[aria-label='Configure tag row 2']").Click();
|
||||
cut.FindAll("textarea")[1].Change("{\"unknown\":\"second-extension\"}");
|
||||
Service.Write=(_,input)=>input.Name=="First"?Service.Reply.Task:Task.FromResult(new UnsMutationResult(false,"Second refused"));
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Service.Entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
cut.FindAll("input[placeholder=TagName]")[1].Change("Queued replacement");
|
||||
Service.Reply.SetResult(new(true,null));await saving;
|
||||
Service.Inputs.Select(x=>x.Input.Name).ShouldBe(new[]{"First","Second"});
|
||||
Service.Inputs.Select(x=>x.Input.TagConfig).ShouldBe(new[]{"{\"unknown\":\"first-extension\"}","{\"unknown\":\"second-extension\"}"});
|
||||
cut.FindAll("input[placeholder=TagName]").Count.ShouldBe(1);
|
||||
cut.Find("input[placeholder=TagName]").GetAttribute("value").ShouldBe("Second");
|
||||
cut.Markup.ShouldContain("1 tag(s) created; 1 failed");
|
||||
Service.Write=(_,_)=>Task.FromResult(new UnsMutationResult(true,null));
|
||||
cut.Find(".modal-footer .btn-primary").Click();
|
||||
Service.Inputs.Count.ShouldBe(3);Service.Inputs.Last().Input.Name.ShouldBe("Second");
|
||||
cut.FindAll("[role=dialog]").Count.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Manual_RetargetDuringSavedCallbackCannotCloseNewPresentation()
|
||||
{
|
||||
var saved=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var entered=new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var closed=0;Service.Write=(_,_)=>Task.FromResult(new UnsMutationResult(true,null));
|
||||
var cut=Render<RawManualTagEntryModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"Unmapped")
|
||||
.Add(c=>c.OnSaved,async()=>{entered.TrySetResult();await saved.Task;}).Add(c=>c.VisibleChanged,_=>closed++));
|
||||
cut.Find("input").Change("First");
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
cut.Render(p=>p.Add(c=>c.DeviceId,"B"));saved.SetResult();await saving;
|
||||
cut.FindAll("[role=dialog]").Count.ShouldBe(1);closed.ShouldBe(0);
|
||||
cut.Find("input").GetAttribute("value").ShouldBe("");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task Manual_DisposalDoesNotReplayOrCancelDispatchedWrite(bool exception)
|
||||
{
|
||||
var cut=Manual();cut.Find("input").Change("First");
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Service.Entered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
var service=Service;await DisposeComponentsAsync();if(exception)service.Reply.SetException(new IOException("Retired write failure"));else service.Reply.SetResult(new(true,null));await saving;
|
||||
service.Inputs.Count.ShouldBe(1);Renderer.UnhandledException.IsCompletedSuccessfully.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Manual_TypedConfigErrorNamesAndDescribesCompositeAndCanRecover()
|
||||
{
|
||||
var cut=Render<RawManualTagEntryModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"S7"));
|
||||
cut.Find("input[placeholder=TagName]").Change("TypedTag");
|
||||
cut.Find("button[aria-label='Configure tag row 1']").Click();
|
||||
cut.Find(".modal-footer .btn-primary").Click();
|
||||
var group=cut.Find("[role=group][aria-invalid=true]");
|
||||
foreach(var id in group.GetAttribute("aria-labelledby")!.Split(' '))cut.Find("#"+id).TextContent.ShouldNotBeNullOrWhiteSpace();
|
||||
cut.Find("#"+group.GetAttribute("aria-describedby")).TextContent.ShouldNotBeNullOrWhiteSpace();
|
||||
Service.Inputs.ShouldBeEmpty();
|
||||
Service.Write=(_,_)=>Task.FromResult(new UnsMutationResult(true,null));
|
||||
cut.Find("input[placeholder^='e.g. DB1']").Change("DB1.DBW0");
|
||||
cut.Find(".modal-footer .btn-primary").Click();
|
||||
Service.Inputs.Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
private BrowserService ConfigureBrowse()
|
||||
{
|
||||
var auth=AddAuthorization();auth.SetAuthorized("fixture");auth.SetPolicies(ZB.MOM.WW.OtOpcUa.Security.Auth.AdminUiPolicies.DriverOperator);
|
||||
var browser=DispatchProxy.Create<IBrowserSessionService,BrowserService>();
|
||||
Services.AddSingleton(browser);
|
||||
Services.AddSingleton(new RawTagCsvExportReader(RawTreeTestDb.Factory("raw-workflow-"+Guid.NewGuid().ToString("N"))));
|
||||
return (BrowserService)browser;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Browse_HasNamedModalAndSafeEntry()
|
||||
{
|
||||
ConfigureBrowse();var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A"));
|
||||
var modal=cut.Find("[role=dialog]");modal.GetAttribute("aria-modal").ShouldBe("true");
|
||||
cut.Find("#"+modal.GetAttribute("aria-labelledby")).TextContent.ShouldContain("Browse device");
|
||||
cut.Find("[data-initial-focus]").TextContent.ShouldContain("Cancel");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task Browse_RetiredOwnerLookupCannotStartAProbe(bool dispose)
|
||||
{
|
||||
var browser=ConfigureBrowse();
|
||||
var owner=new TaskCompletionSource<string?>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Service.Owner=()=>owner.Task;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A"));
|
||||
var opening=cut.Find(".modal-body button").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Service.OwnerEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
if(dispose)await DisposeComponentsAsync();else cut.Render(p=>p.Add(c=>c.DeviceId,"B"));
|
||||
owner.SetResult("A-owner");await opening;browser.OpenCalls.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_PendingOpenRetainsFocusableControlBlocksReentryAndClosesOrphan()
|
||||
{
|
||||
var browser=ConfigureBrowse();
|
||||
var reply=new TaskCompletionSource<BrowseOpenResult>(TaskCreationOptions.RunContinuationsAsynchronously);browser.OpenReply=()=>reply.Task;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A"));
|
||||
var opening=cut.Find(".modal-body button").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await browser.OpenEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
cut.Find(".modal-body button").HasAttribute("disabled").ShouldBeFalse();
|
||||
cut.Find(".modal-body button").GetAttribute("aria-disabled").ShouldBe("true");
|
||||
await cut.Find(".modal-body button").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
browser.OpenCalls.ShouldBe(1);
|
||||
await cut.Find(".modal-footer .btn-outline-secondary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
var token=Guid.NewGuid();reply.SetResult(new(true,null,token));await opening;
|
||||
browser.ClosedTokens.ShouldBe(new[]{token});cut.FindAll("[role=dialog]").Count.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_LateLeafAndRetainedChildCallbackCannotSelectUnderReplacement()
|
||||
{
|
||||
var browser=ConfigureBrowse();browser.Success=true;
|
||||
var attrs=new TaskCompletionSource<IReadOnlyList<AttributeInfo>>(TaskCreationOptions.RunContinuationsAsynchronously);browser.Attributes=()=>attrs.Task;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"AbCip"));
|
||||
cut.Find(".modal-body button").Click();
|
||||
var callback=cut.FindComponent<DriverBrowseTree>().Instance.OnLeafToggled;
|
||||
var selection=new BrowseLeafSelection(new("Tag1","Tag1",BrowseNodeKind.Leaf,false),[]);
|
||||
var selecting=cut.InvokeAsync(()=>callback.InvokeAsync(selection));
|
||||
await browser.AttributesEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
cut.Render(p=>p.Add(c=>c.DeviceId,"B"));attrs.SetResult([]);await selecting;
|
||||
await cut.InvokeAsync(()=>callback.InvokeAsync(selection));
|
||||
browser.AttributesCalls.ShouldBe(1);cut.Find(".modal-footer .btn-primary").HasAttribute("disabled").ShouldBeTrue();
|
||||
cut.Find(".modal-body button").Click();
|
||||
await cut.InvokeAsync(()=>cut.FindComponent<DriverBrowseTree>().Instance.OnLeafToggled.InvokeAsync(selection));
|
||||
browser.AttributesCalls.ShouldBe(2);cut.Find(".modal-footer .btn-primary").HasAttribute("disabled").ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("failure")]
|
||||
[InlineData("success")]
|
||||
[InlineData("exception")]
|
||||
public async Task Browse_PendingImportDoesNotDispatchTwiceOrAlterReplacement(string outcome)
|
||||
{
|
||||
var browser=ConfigureBrowse();browser.Success=true;var saved=0;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"AbCip").Add(c=>c.OnSaved,()=>saved++));
|
||||
cut.Find(".modal-body button").Click();
|
||||
await cut.InvokeAsync(()=>cut.FindComponent<DriverBrowseTree>().Instance.OnLeafToggled.InvokeAsync(new(new("Tag1","Tag1",BrowseNodeKind.Leaf,false),[])));
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await Service.ImportEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
await cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await cut.Find(".modal-footer .btn-outline-secondary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
Service.ImportCalls.ShouldBe(1);
|
||||
cut.Render(p=>p.Add(c=>c.DeviceId,"B"));if(outcome=="exception")Service.ImportReply.SetException(new IOException("Retired import failure"));else Service.ImportReply.SetResult(new(outcome=="success"?1:0,outcome=="success"?[]:["Retired refusal"]));await saving;
|
||||
cut.FindAll("[role=dialog]").Count.ShouldBe(1);cut.Markup.ShouldNotContain("Retired refusal");saved.ShouldBe(0);
|
||||
Service.ImportDevice.ShouldBe("A");Service.ImportRows.Single().Tag.Name.ShouldBe("Tag1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_DisposedImportExceptionCannotEscapeIntoRetiredRenderer()
|
||||
{
|
||||
var browser=ConfigureBrowse();browser.Success=true;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"AbCip"));
|
||||
cut.Find(".modal-body button").Click();
|
||||
await cut.InvokeAsync(()=>cut.FindComponent<DriverBrowseTree>().Instance.OnLeafToggled.InvokeAsync(new(new("Tag1","Tag1",BrowseNodeKind.Leaf,false),[])));
|
||||
var saving=cut.Find(".modal-footer .btn-primary").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
var service=Service;await service.ImportEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
await DisposeComponentsAsync();service.ImportReply.SetException(new IOException("Retired import failure"));await saving;
|
||||
service.ImportCalls.ShouldBe(1);Renderer.UnhandledException.IsCompletedSuccessfully.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_CurrentImportNotifiesAndCloses()
|
||||
{
|
||||
var browser=ConfigureBrowse();browser.Success=true;var saved=0;
|
||||
Service.ImportReply.SetResult(new(1,[]));
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"AbCip").Add(c=>c.OnSaved,()=>saved++));
|
||||
cut.Find(".modal-body button").Click();
|
||||
await cut.InvokeAsync(()=>cut.FindComponent<DriverBrowseTree>().Instance.OnLeafToggled.InvokeAsync(new(new("Tag1","Tag1",BrowseNodeKind.Leaf,false),[])));
|
||||
cut.Find(".modal-footer .btn-primary").Click();
|
||||
saved.ShouldBe(1);cut.FindAll("[role=dialog]").Count.ShouldBe(0);Service.ImportCalls.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_PendingRebirthPublishesOnceAndCannotReportIntoReplacement()
|
||||
{
|
||||
var browser=ConfigureBrowse();browser.Success=true;browser.Rebirth=true;
|
||||
var cut=Render<RawBrowseModal>(p=>p.Add(c=>c.Visible,true).Add(c=>c.DeviceId,"A").Add(c=>c.DriverType,"Mqtt"));
|
||||
cut.Find(".modal-body button").Click();
|
||||
cut.Find("input[placeholder='group/edgeNode']").Input("Group/Edge");
|
||||
cut.FindAll("button").Single(b=>b.TextContent.Trim()=="Use this scope").Click();
|
||||
cut.FindAll("button").Single(b=>b.TextContent.Trim()=="Request rebirth…").Click();
|
||||
var publishing=cut.Find("button.btn-warning").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
await browser.RebirthEntered.Task.WaitAsync(TimeSpan.FromSeconds(10),Xunit.TestContext.Current.CancellationToken);
|
||||
await cut.Find("button.btn-warning").TriggerEventAsync("onclick",new Microsoft.AspNetCore.Components.Web.MouseEventArgs());
|
||||
browser.RebirthCalls.ShouldBe(1);
|
||||
cut.Render(p=>p.Add(c=>c.DeviceId,"B"));browser.RebirthReply.SetResult(1);await publishing;
|
||||
cut.Markup.ShouldNotContain("command published");cut.FindAll("[role=dialog]").Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
public class BrowserService:DispatchProxy
|
||||
{
|
||||
public int OpenCalls {get;private set;}
|
||||
public Func<Task<BrowseOpenResult>>? OpenReply {get;set;}
|
||||
public TaskCompletionSource OpenEntered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public List<Guid> ClosedTokens {get;}=[];
|
||||
public bool Success {get;set;}
|
||||
public bool Rebirth {get;set;}
|
||||
public int AttributesCalls {get;private set;}
|
||||
public Func<Task<IReadOnlyList<AttributeInfo>>>? Attributes {get;set;}
|
||||
public TaskCompletionSource AttributesEntered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public TaskCompletionSource RebirthEntered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public TaskCompletionSource<int> RebirthReply {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public int RebirthCalls {get;private set;}
|
||||
protected override object? Invoke(MethodInfo? method,object?[]? args)
|
||||
{
|
||||
return method!.Name switch
|
||||
{
|
||||
"CanBrowse"=>true,
|
||||
"CanRequestRebirth"=>Rebirth,
|
||||
"AttributesAsync"=>GetAttributes(),
|
||||
"RequestRebirthAsync"=>RequestRebirth(),
|
||||
"OpenAsync"=>Open(),
|
||||
"CloseAsync"=>Close((Guid)args![0]!),
|
||||
"RootAsync"=>Task.FromResult<IReadOnlyList<BrowseNode>>([]),
|
||||
_=>throw new NotSupportedException(method.Name)
|
||||
};
|
||||
}
|
||||
private Task<IReadOnlyList<AttributeInfo>> GetAttributes(){AttributesCalls++;AttributesEntered.TrySetResult();return Attributes?.Invoke()??Task.FromResult<IReadOnlyList<AttributeInfo>>([]);}
|
||||
private Task<int> RequestRebirth(){RebirthCalls++;RebirthEntered.TrySetResult();return RebirthReply.Task;}
|
||||
private Task Close(Guid token){ClosedTokens.Add(token);return Task.CompletedTask;}
|
||||
private Task<BrowseOpenResult> Open(){OpenCalls++;OpenEntered.TrySetResult();return OpenReply?.Invoke()??Task.FromResult(new BrowseOpenResult(Success,Success?null:"Synthetic no session",Success?Guid.NewGuid():Guid.Empty));}
|
||||
}
|
||||
|
||||
public class ManualService:DispatchProxy
|
||||
{
|
||||
public TaskCompletionSource ImportEntered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public TaskCompletionSource<RawTagImportResult> ImportReply {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public int ImportCalls {get;private set;}
|
||||
public string? ImportDevice {get;private set;}
|
||||
public IReadOnlyList<RawTagImportRow> ImportRows {get;private set;}=[];
|
||||
public Func<Task<string?>>? Owner {get;set;}
|
||||
public TaskCompletionSource OwnerEntered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public TaskCompletionSource Entered {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public TaskCompletionSource<UnsMutationResult> Reply {get;}=new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
public List<(string Device,RawTagInput Input)> Inputs {get;}=[];
|
||||
public Func<string,RawTagInput,Task<UnsMutationResult>>? Write {get;set;}
|
||||
protected override object? Invoke(MethodInfo? method,object?[]? args)
|
||||
{
|
||||
if(method!.Name=="ImportTagsAsync"){ImportCalls++;ImportDevice=(string)args![0]!;ImportRows=(IReadOnlyList<RawTagImportRow>)args[1]!;ImportEntered.TrySetResult();return ImportReply.Task;}
|
||||
if(method.Name=="LoadDeviceDriverInstanceIdAsync"){OwnerEntered.TrySetResult();return Owner?.Invoke()??Task.FromResult<string?>(null);}
|
||||
if(method.Name=="LoadMergedProbeConfigAsync")return Task.FromResult<(string DriverType,string MergedConfigJson)?>(null);
|
||||
if(method.Name=="CreateTagAsync"){Inputs.Add(((string)args![0]!, (RawTagInput)args[2]!));Entered.TrySetResult();return Write?.Invoke((string)args[0]!, (RawTagInput)args[2]!)??Reply.Task;}
|
||||
throw new NotSupportedException(method.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
@@ -366,8 +367,20 @@ public sealed class RawBrowseModalStaleOpenTests : IDisposable
|
||||
/// throws without one, and this modal calls it on the open path. Renders are built and then
|
||||
/// discarded — the tests read the modal's state, not its markup.
|
||||
/// </summary>
|
||||
// The migrated ModalFrame requires JS even in this existing inert renderer.
|
||||
// This double only supplies its focus adapter; actual keyboard behavior is browser-tested.
|
||||
private sealed class DialogOnlyRuntime:IJSRuntime
|
||||
{
|
||||
public ValueTask<T> InvokeAsync<T>(string name,object?[]? args)=>InvokeAsync<T>(name,CancellationToken.None,args);
|
||||
public ValueTask<T> InvokeAsync<T>(string name,CancellationToken ct,object?[]? args)
|
||||
{
|
||||
if (!name.StartsWith("otDialog.",StringComparison.Ordinal)) throw new NotSupportedException(name);
|
||||
return ValueTask.FromResult(name=="otDialog.activate"?(T)(object)true:default!);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InertRenderer()
|
||||
: Renderer(new ServiceCollection().BuildServiceProvider(), NullLoggerFactory.Instance)
|
||||
: Renderer(new ServiceCollection().AddSingleton<IJSRuntime, DialogOnlyRuntime>().BuildServiceProvider(), NullLoggerFactory.Instance)
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override Dispatcher Dispatcher { get; } = new InlineDispatcher();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
@@ -59,7 +60,7 @@ public sealed class RawBrowseRebirthRefreshTests : IDisposable
|
||||
await confirm;
|
||||
|
||||
Get<int>(modal, "_treeGeneration").ShouldBe(before);
|
||||
Get<string?>(modal, "_rebirthOutcome")!.ShouldNotContain("refreshed");
|
||||
Get<string?>(modal, "_rebirthOutcome").ShouldBeNull();
|
||||
// Positive control: the publish itself was still made and reported.
|
||||
svc.Scopes.ShouldBe(["Grp/EdgeA"]);
|
||||
}
|
||||
@@ -106,12 +107,15 @@ public sealed class RawBrowseRebirthRefreshTests : IDisposable
|
||||
typeof(RawBrowseModal).GetProperty("Visible")!.SetValue(modal, true);
|
||||
Set(modal, "_token", Guid.NewGuid());
|
||||
Set(modal, "_canRebirth", true);
|
||||
Set(modal, "_open", true);
|
||||
Set(modal, "_canBrowse", true);
|
||||
Set(modal, "_canOperate", true);
|
||||
|
||||
var targetType = typeof(RawBrowseModal).GetNestedType("RebirthTarget", BindingFlags.NonPublic)!;
|
||||
Set(modal, "_rebirthTarget", Activator.CreateInstance(targetType, "Grp/EdgeA", "edge node EdgeA", "detail", false));
|
||||
Set(modal, "_rebirthConfirming", true);
|
||||
|
||||
var renderer = new InertRenderer();
|
||||
var renderer = new InertRenderer(svc);
|
||||
_renderers.Add(renderer);
|
||||
renderer.Attach(modal);
|
||||
return modal;
|
||||
@@ -158,8 +162,20 @@ public sealed class RawBrowseRebirthRefreshTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InertRenderer()
|
||||
: Renderer(new ServiceCollection().BuildServiceProvider(), NullLoggerFactory.Instance)
|
||||
// The migrated ModalFrame requires JS even in this existing inert renderer.
|
||||
// This double only supplies its focus adapter; actual keyboard behavior is browser-tested.
|
||||
private sealed class DialogOnlyRuntime:IJSRuntime
|
||||
{
|
||||
public ValueTask<T> InvokeAsync<T>(string name,object?[]? args)=>InvokeAsync<T>(name,CancellationToken.None,args);
|
||||
public ValueTask<T> InvokeAsync<T>(string name,CancellationToken ct,object?[]? args)
|
||||
{
|
||||
if (!name.StartsWith("otDialog.",StringComparison.Ordinal)) throw new NotSupportedException(name);
|
||||
return ValueTask.FromResult(name=="otDialog.activate"?(T)(object)true:default!);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InertRenderer(IBrowserSessionService browser)
|
||||
: Renderer(new ServiceCollection().AddSingleton(browser).AddSingleton<IJSRuntime, DialogOnlyRuntime>().BuildServiceProvider(), NullLoggerFactory.Instance)
|
||||
{
|
||||
public override Dispatcher Dispatcher { get; } = new InlineDispatcher();
|
||||
public void Attach(IComponent component) => AssignRootComponentId(component);
|
||||
|
||||
+12
-15
@@ -69,29 +69,26 @@ public sealed class RawManualTagEntryModalMergedConfigTests
|
||||
{
|
||||
const string merged = """{"endpoint":"10.0.0.1:44818","slot":0}""";
|
||||
|
||||
(string DriverType, string MergedConfigJson)? answer = null;
|
||||
var svc = new FakeRawTreeService { OnLoadMergedProbeConfig = _ => answer };
|
||||
|
||||
var ready = new TaskCompletionSource<(string DriverType, string MergedConfigJson)?>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var svc = new FakeRawTreeService { OnLoadMergedProbeConfigAsync = _ => ready.Task };
|
||||
var modal = new RawManualTagEntryModal();
|
||||
SetParameters(modal, visible: true, deviceId: "dev-1", driverType: "AbCip");
|
||||
InjectService(modal, svc);
|
||||
|
||||
await OpenAsync(modal);
|
||||
|
||||
// The delegate an already-rendered editor is holding. It must read the field on every call, not a
|
||||
// value captured when the parameters were built — the resolve is awaited AFTER the rows are
|
||||
// seeded, so a snapshot taken at build time is permanently "{}".
|
||||
SetParameters(modal, visible: true, deviceId: "dev-1", driverType: "AbCip");
|
||||
var opening = OpenAsync(modal);
|
||||
var accessor = GetAccessor(modal);
|
||||
accessor().ShouldBe("{}");
|
||||
ready.SetResult(("AbCip", merged));
|
||||
await opening;
|
||||
accessor().ShouldBe(merged); // current presentation stays live through its initial resolve
|
||||
|
||||
SetParameters(modal, visible: false, deviceId: "dev-1", driverType: "AbCip");
|
||||
await OpenAsync(modal);
|
||||
|
||||
answer = ("AbCip", merged);
|
||||
SetParameters(modal, visible: true, deviceId: "dev-1", driverType: "AbCip");
|
||||
const string next = """{"endpoint":"10.0.0.2:44818","slot":1}""";
|
||||
svc.OnLoadMergedProbeConfigAsync = _ => Task.FromResult<(string DriverType, string MergedConfigJson)?>(("AbCip", next));
|
||||
SetParameters(modal, visible: true, deviceId: "dev-2", driverType: "AbCip");
|
||||
await OpenAsync(modal);
|
||||
|
||||
accessor().ShouldBe(merged);
|
||||
accessor().ShouldBe(merged); // retired A never starts a probe using B's config
|
||||
GetAccessor(modal)().ShouldBe(next);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user