Expose complete diagnostic text through native disclosures
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Bunit;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Critical diagnostics remain complete, native-keyboard discoverable and Razor escaped.</summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class DiagnosticDetailsTests : BunitContext
|
||||
{
|
||||
[Fact]
|
||||
public void FullDiagnostic_IsAvailableWithoutHoverAndEscaped()
|
||||
{
|
||||
var text = "<script>bad()</script>\n" + new string('x',5000);
|
||||
var cut = Render<DiagnosticDetails>(p => p.Add(x => x.Summary,"Failure reason")
|
||||
.Add(x => x.Text,text));
|
||||
cut.Find("details summary").TextContent.ShouldBe("Failure reason");
|
||||
cut.Find("pre").TextContent.ShouldBe(text);
|
||||
cut.FindAll("script").ShouldBeEmpty();
|
||||
cut.Find("pre").GetAttribute("role").ShouldBe("region");
|
||||
cut.Find("pre").GetAttribute("tabindex").ShouldBe("0");
|
||||
cut.Find("pre").GetAttribute("aria-label").ShouldBe("Failure reason");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void MissingDiagnostic_IsNotAnEmptyDisclosure(string? text)
|
||||
{
|
||||
var cut = Render<DiagnosticDetails>(p => p.Add(x => x.Summary,"Failure reason")
|
||||
.Add(x => x.Text,text));
|
||||
cut.FindAll("details").ShouldBeEmpty();
|
||||
cut.Markup.ShouldContain("No detail recorded");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Reflection;
|
||||
using Bunit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||
using ZB.MOM.WW.OtOpcUa.Security.Auth;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
||||
|
||||
/// <summary>Driver control errors remain complete and accessible without hover.</summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class DriverStatusDiagnosticsTests : BunitContext
|
||||
{
|
||||
private static string FullError => "Synthetic local failure <script>ignored()</script> " + new string('x',2000) + " END-ERROR";
|
||||
|
||||
private void Configure(bool storeFails)
|
||||
{
|
||||
var auth = AddAuthorization();
|
||||
auth.SetAuthorized("fixture");
|
||||
auth.SetPolicies(AdminUiPolicies.DriverOperator);
|
||||
var status = DispatchProxy.Create<IDriverStatusSnapshotStore, StatusProxy>();
|
||||
((StatusProxy)(object)status).Error = storeFails ? FullError : null;
|
||||
Services.AddSingleton(status);
|
||||
Services.AddSingleton<IDriverResilienceStatusStore>(new InMemoryDriverResilienceStatusStore());
|
||||
Services.AddSingleton(DispatchProxy.Create<IAdminOperationsClient, OperationsProxy>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatusReadError_ExposesCompleteEscapedDiagnostic()
|
||||
{
|
||||
Configure(true);
|
||||
var cut = Render<DriverStatusPanel>(p => p.Add(x => x.DriverInstanceId,"driver-local"));
|
||||
cut.WaitForAssertion(() => cut.Find("details pre").TextContent.ShouldBe(FullError));
|
||||
cut.FindAll("details script").ShouldBeEmpty();
|
||||
cut.Find("summary").TextContent.ShouldContain("Status read error");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailedOperation_ExposesFullReasonAlongsideExistingOutcome()
|
||||
{
|
||||
Configure(false);
|
||||
var cut = Render<DriverStatusPanel>(p => p.Add(x => x.DriverInstanceId,"driver-local"));
|
||||
cut.FindAll("button").Single(x => x.TextContent.Trim()=="Reconnect").Click();
|
||||
cut.WaitForAssertion(() => cut.Find("details pre").TextContent.ShouldBe(FullError));
|
||||
cut.Find("summary").TextContent.ShouldBe("Operation details");
|
||||
cut.FindAll("details script").ShouldBeEmpty();
|
||||
}
|
||||
|
||||
public class StatusProxy : DispatchProxy
|
||||
{
|
||||
public string? Error { get; set; }
|
||||
private readonly InMemoryDriverStatusSnapshotStore _store = new();
|
||||
protected override object? Invoke(MethodInfo? method, object?[]? args)
|
||||
{
|
||||
if (method?.Name==nameof(IDriverStatusSnapshotStore.GetAllWithReceiveTime) && Error is not null)
|
||||
throw new IOException(Error);
|
||||
return method!.Invoke(_store,args);
|
||||
}
|
||||
}
|
||||
|
||||
public class OperationsProxy : DispatchProxy
|
||||
{
|
||||
protected override object? Invoke(MethodInfo? method, object?[]? args) =>
|
||||
method?.Name==nameof(IAdminOperationsClient.AskAsync) && method.GetGenericArguments().Single()==typeof(ReconnectDriverResult)
|
||||
? Task.FromResult(new ReconnectDriverResult(false,FullError,Guid.Empty))
|
||||
: throw new NotSupportedException("Synthetic fixture rejects other operations.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user