using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
///
/// Pins DriverStatusPanel to the /hosts page (Gitea #546). The panel is the only
/// component carrying the Restart/Reconnect driver controls, and it had ZERO references
/// repo-wide — the commands worked end to end over the mesh transport while no user could reach
/// them, and nothing failed to build, test or deploy. Deleting the last <DriverStatusPanel
/// tag would silently restore exactly that state, so it is pinned here.
///
///
/// This is a source scan rather than a rendering assertion because the repo has no bUnit (same
/// technique as MeshRegistrationRoleScopingTests; panel markup is otherwise live-verified).
/// A scan proves reachability of the component, not that it renders correctly.
///
[Trait("Category", "Unit")]
public sealed class HostsPanelWiringTests
{
private static string ReadHostsPageSource()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "ZB.MOM.WW.OtOpcUa.slnx")))
dir = dir.Parent;
dir.ShouldNotBeNull("could not locate the repository root (no ZB.MOM.WW.OtOpcUa.slnx above the test binary)");
return File.ReadAllText(Path.Combine(
dir!.FullName, "src", "Server", "ZB.MOM.WW.OtOpcUa.AdminUI",
"Components", "Pages", "Hosts.razor"));
}
/// THE #546 regression pin: the panel must remain reachable from a routable page.
[Fact]
public void Hosts_page_renders_the_driver_status_panel()
{
ReadHostsPageSource().ShouldContain(
"
/// The panel must be fed the row's real identity and enabled-state, not literals. Hard-coding
/// any of the three would make every expanded row drive the same driver, or claim a disabled
/// instance is live — both of which a source scan for the tag alone would pass.
///
[Fact]
public void The_panel_is_bound_to_the_rows_own_driver_cluster_and_enabled_state()
{
var source = ReadHostsPageSource();
source.ShouldContain("DriverInstanceId=\"@d.DriverInstanceId\"");
source.ShouldContain("ClusterId=\"@g.ClusterId\"");
source.ShouldContain("Enabled=\"@d.Enabled\"");
}
}