namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Design;
///
/// Regression tests for the Test Run side-effect warning. Test Run wires External,
/// Database, and Notify to central's real services, so a Test Run
/// has production-equivalent side effects. The finding asked, at minimum, that
/// this blast radius be surfaced to the user. The Test Run panels in
/// SharedScriptForm and TemplateEdit carry a prominent
/// Real I/O badge and an alert-warning block stating the side
/// effects are real and permanent; ApiMethodForm (Inbound API kind) has
/// no real-I/O surface at all and correctly omits the badge. These tests pin
/// that warning so it cannot silently regress.
///
public class TestRunWarningTests
{
private static string SrcRoot
{
get
{
// tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/bin/Debug/net10.0 → repo root.
var dir = AppContext.BaseDirectory;
for (var i = 0; i < 6 && dir is not null; i++)
dir = Directory.GetParent(dir)?.FullName;
return Path.Combine(dir!, "src", "ZB.MOM.WW.ScadaBridge.CentralUI",
"Components", "Pages", "Design");
}
}
private static string Read(string fileName)
=> File.ReadAllText(Path.Combine(SrcRoot, fileName));
// The template Test Run panel moved out of TemplateEdit.razor
// into TemplateScriptDialog.razor when the page-embedded script modal was
// migrated to the IDialogService host. The warning travelled with it.
/// Verifies that a Test Run panel with a real I/O surface shows the real I/O badge and warning.
/// The Razor file containing the Test Run panel.
[Theory]
[InlineData("SharedScriptForm.razor")]
[InlineData("TemplateScriptDialog.razor")]
public void TestRunPanel_WithRealIoSurface_ShowsRealIoBadgeAndWarning(string razorFile)
{
var markup = Read(razorFile);
// The "Real I/O" badge on the Test Run panel header.
Assert.Contains("Real I/O", markup);
// The explicit warning that side effects hit real systems and are permanent.
Assert.Contains("alert-warning", markup);
Assert.Contains("fire for real", markup);
Assert.Contains("Side effects are permanent", markup);
}
/// Verifies that the API method form Test Run shows no real I/O badge because the inbound API has no side-effect surface.
[Fact]
public void ApiMethodForm_TestRun_HasNoRealIoBadge_BecauseInboundApiHasNoSideEffectSurface()
{
// The Inbound API sandbox host exposes only Parameters / Route (Route
// throws) — there is no External/Database/Notify, so no "Real I/O".
var markup = Read("ApiMethodForm.razor");
Assert.DoesNotContain("Real I/O", markup);
// It still warns that Route calls throw.
Assert.Contains("alert-warning", markup);
}
}