using System.Text.RegularExpressions;
using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
///
/// R04 H1 source pin (no bUnit): every destructive button on the equipment page and the script editor
/// opens a confirm dialog instead of deleting on the first click. The live check (each delete confirms)
/// is in the Wave 4 docker-dev pass.
///
[Trait("Category", "Unit")]
public sealed class DeleteConfirmationWiringTests
{
[Fact]
public void Equipment_page_routes_every_destructive_row_action_through_the_confirm()
{
var src = AdminUiSource.Read("Components", "Pages", "Uns", "EquipmentPage.razor");
src.ShouldContain(" ConfirmRemoveReference(r)\"");
src.ShouldContain("@onclick=\"() => ConfirmDeleteVirtualTag(v.VirtualTagId, v.Name)\"");
src.ShouldContain("@onclick=\"() => ConfirmDeleteAlarm(a.ScriptedAlarmId, a.Name)\"");
// No danger button may call a delete handler directly.
Regex.Matches(src, @"btn-outline-danger[^>]*@onclick=""\(\) => (Delete|Remove)\w*\(").Count.ShouldBe(0);
// Positive control: the page still has its three danger buttons.
Regex.Matches(src, "btn-outline-danger").Count.ShouldBe(3);
}
[Fact]
public void Script_editor_delete_confirms()
{
var src = AdminUiSource.Read("Components", "Pages", "ScriptEdit.razor");
src.ShouldContain("@onclick=\"() => _confirmDeleteVisible = true\"");
src.ShouldContain("OnConfirm=\"DeleteAsync\"");
src.ShouldNotContain("@onclick=\"DeleteAsync\"");
}
}