feat(central-ui): add Min time between runs field to the script form

The template script editor had no input for MinTimeBetweenRuns, so a
WhileTrue trigger configured through the UI always saved a null interval
and degraded to a single edge fire. The Add/Edit Script modal now has a
"Min time between runs" number+unit (ms/sec/min) field.

- Visible only for ValueChange / Conditional / Expression triggers — the
  auto-firing triggers MinTimeBetweenRuns throttles. Hidden for Interval
  (its own period is the cadence), Call (invoked explicitly, never
  throttled), and None.
- For a WhileTrue Conditional/Expression trigger the field is labelled as
  the re-fire interval and shows a warning while it is blank.
- Wired through the new-script and edit-script save paths (edit previously
  only preserved the existing value, never let the user change it).

New DurationInput helper does the TimeSpan <-> number+unit conversion;
ScriptTriggerConfigCodec.SupportsMinTimeBetweenRuns classifies trigger
types. Both TDD'd — 21 new tests. CentralUI suite 316 green; verified
end-to-end in the browser (visibility per trigger type, WhileTrue warning,
save/reload round-trip).
This commit is contained in:
Joseph Doherty
2026-05-18 16:44:15 -04:00
parent 437fe154e7
commit 01509a045f
5 changed files with 241 additions and 2 deletions

View File

@@ -0,0 +1,98 @@
using ScadaLink.CentralUI.Components.Shared;
namespace ScadaLink.CentralUI.Tests.Shared;
/// <summary>
/// Coverage for <see cref="DurationInput"/>, the number+unit codec behind the
/// script form's "Min time between runs" field.
/// </summary>
public class DurationInputTests
{
// ── Split: TimeSpan -> (value, unit) ───────────────────────────────────
[Fact]
public void Split_Null_ReturnsBlankWithSecondsUnit()
{
var (value, unit) = DurationInput.Split(null);
Assert.Null(value);
Assert.Equal("sec", unit);
}
[Fact]
public void Split_Zero_ReturnsBlank()
{
var (value, _) = DurationInput.Split(TimeSpan.Zero);
Assert.Null(value);
}
[Fact]
public void Split_WholeMinutes_UsesMinuteUnit()
{
var (value, unit) = DurationInput.Split(TimeSpan.FromMinutes(5));
Assert.Equal("5", value);
Assert.Equal("min", unit);
}
[Fact]
public void Split_WholeSeconds_UsesSecondUnit()
{
var (value, unit) = DurationInput.Split(TimeSpan.FromSeconds(30));
Assert.Equal("30", value);
Assert.Equal("sec", unit);
}
[Fact]
public void Split_SubSecond_UsesMillisecondUnit()
{
var (value, unit) = DurationInput.Split(TimeSpan.FromMilliseconds(250));
Assert.Equal("250", value);
Assert.Equal("ms", unit);
}
// ── Compose: (value, unit) -> TimeSpan? ────────────────────────────────
[Fact]
public void Compose_Blank_ReturnsNull() =>
Assert.Null(DurationInput.Compose(null, "sec"));
[Fact]
public void Compose_Zero_ReturnsNull() =>
Assert.Null(DurationInput.Compose("0", "sec"));
[Fact]
public void Compose_Negative_ReturnsNull() =>
Assert.Null(DurationInput.Compose("-5", "sec"));
[Fact]
public void Compose_SecondsValue_BuildsDuration() =>
Assert.Equal(TimeSpan.FromSeconds(30), DurationInput.Compose("30", "sec"));
[Fact]
public void Compose_MinutesValue_BuildsDuration() =>
Assert.Equal(TimeSpan.FromMinutes(5), DurationInput.Compose("5", "min"));
[Fact]
public void Compose_MillisecondsValue_BuildsDuration() =>
Assert.Equal(TimeSpan.FromMilliseconds(250), DurationInput.Compose("250", "ms"));
// ── Round-trip ─────────────────────────────────────────────────────────
[Theory]
[InlineData(250)]
[InlineData(30000)]
[InlineData(300000)]
public void RoundTrip_PreservesDuration(long milliseconds)
{
var original = TimeSpan.FromMilliseconds(milliseconds);
var (value, unit) = DurationInput.Split(original);
var reparsed = DurationInput.Compose(value, unit);
Assert.Equal(original, reparsed);
}
}