refactor(adminui): trim inline-script label + null-case test + helper-proxy note

Code-review nits: trim the seed name so the in-session dropdown label matches
the server-trimmed persisted name; add a null-selectedId test for
ResolveScriptLabel; and note in CreateNewScriptAsync that the ordering
invariant is proxied by the pure helper (AdminUI has no bUnit).
This commit is contained in:
Joseph Doherty
2026-06-19 02:16:59 -04:00
parent 36eb14e88d
commit d8254630bb
2 changed files with 21 additions and 2 deletions
@@ -321,7 +321,10 @@
_scriptCreateError = null;
try
{
var seedName = string.IsNullOrWhiteSpace(_form.Name) ? "New script" : $"{_form.Name} script";
// Trim so the local dropdown label matches what CreateScriptAsync persists (it Trim()s
// the name server-side) — otherwise stray whitespace makes the in-session label drift
// from every later modal open.
var seedName = string.IsNullOrWhiteSpace(_form.Name) ? "New script" : $"{_form.Name.Trim()} script";
var result = await Svc.CreateScriptAsync(seedName);
if (!result.Ok || string.IsNullOrEmpty(result.CreatedId))
{
@@ -331,7 +334,9 @@
// Add the new script to the options list BEFORE setting the selected value so the
// <InputSelect> can resolve the label on first render — if we set ScriptId first the
// dropdown has no matching <option> yet and shows a blank/stale label.
// dropdown has no matching <option> yet and shows a blank/stale label. This ordering
// invariant is unit-tested via VirtualTagModalHelpers.ResolveScriptLabel (the AdminUI
// has no bUnit harness, so the pure helper proxies the render-cycle contract).
if (!_scripts.Any(s => s.Id == result.CreatedId))
{
_scripts.Add((result.CreatedId, $"{seedName} (CSharp)"));
@@ -59,6 +59,20 @@ public sealed class VirtualTagScriptDropdownTests
label.ShouldBeNull();
}
[Fact]
public void ResolveScriptLabel_ReturnsNull_WhenSelectedIdIsNull()
{
// The helper parameter is string? — a null selection resolves to no label, not a throw.
var options = new List<(string Id, string Display)>
{
("SC-existing001", "OldScript (CSharp)"),
};
var label = VirtualTagModalHelpers.ResolveScriptLabel(options, null);
label.ShouldBeNull();
}
[Fact]
public void ResolveScriptLabel_ReturnsNull_WhenOptionsIsEmpty()
{