using ZB.MOM.WW.ScadaBridge.Commons.Types.Scripts;
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Scripts;
/// Flow Debugger script entry (design 2026-09-08 ยง2): the monitored attribute of a ValueChange/Conditional trigger.
public class ScriptTriggerAttributeTests
{
/// Verifies the case: write Kinds, return The Monitored Attribute.
/// The kind test input.
/// The config test input.
/// The expected test input.
[Theory]
[InlineData("ValueChange", """{"attributeName":"Level"}""", "Level")]
[InlineData("valuechange", """{"attribute":"Level"}""", "Level")]
[InlineData("Conditional", """{"attributeName":"Level","operator":">","threshold":"5"}""", "Level")]
[InlineData("CONDITIONAL", """{"attribute":"Flag"}""", "Flag")]
public void WriteKinds_ReturnTheMonitoredAttribute(string kind, string config, string expected)
{
Assert.True(ScriptTriggerAttribute.TryRead(kind, config, out var attribute));
Assert.Equal(expected, attribute);
Assert.True(ScriptTriggerAttribute.IsWriteKind(kind));
}
/// Verifies the case: other Kinds, return False, even When The Config Names An Attribute.
/// The kind test input.
/// The config test input.
[Theory]
[InlineData("Call", """{"attributeName":"Level"}""")]
[InlineData("Interval", """{"intervalMs":1000}""")]
[InlineData("Expression", """{"expression":"true"}""")]
[InlineData(null, null)]
[InlineData("", "")]
public void OtherKinds_ReturnFalse_EvenWhenTheConfigNamesAnAttribute(string? kind, string? config)
{
Assert.False(ScriptTriggerAttribute.TryRead(kind, config, out var attribute));
Assert.Null(attribute);
Assert.False(ScriptTriggerAttribute.IsWriteKind(kind));
}
/// Verifies the case: write Kind, without AReadable Attribute, returns False, but Is Still AWrite Kind.
/// The kind test input.
/// The config test input.
[Theory]
[InlineData("ValueChange", null)]
[InlineData("ValueChange", "")]
[InlineData("ValueChange", "not json")]
[InlineData("ValueChange", "[1,2]")]
[InlineData("ValueChange", """{"attributeName":""}""")]
[InlineData("ValueChange", """{"other":"x"}""")]
public void WriteKind_WithoutAReadableAttribute_ReturnsFalse_ButIsStillAWriteKind(string kind, string? config)
{
Assert.False(ScriptTriggerAttribute.TryRead(kind, config, out var attribute));
Assert.Null(attribute);
Assert.True(ScriptTriggerAttribute.IsWriteKind(kind));
}
}