fix(central-ui): Debug View picker — disabled-while-connected test; drop no-op handler; static label

Task 5 review follow-ups:

- New DebugViewInstancePickerTests.WhileConnected_ThePickerIsDisabled pins that
  a live connection locks the picker: both the input and the chevron carry
  `disabled`. It marks the page connected by reflection, the way the other
  DebugView page tests do (DebugViewAlarmTableTests) — driving the real gRPC
  stream is not available to a bUnit render.
- OnInstanceSelectionChanged() was already a no-op and its comment described the
  @bind that the picker replaced; deleted, and OnInstancePicked now just records
  the id (XML-documented).
- The ItemLabel lambda is hoisted to a private static InstanceLabel(Instance),
  passed as a method group.

Claude-Session: https://claude.ai/code/session_01NcMG6xXdsJbmD2wYAgkK29
This commit is contained in:
Joseph Doherty
2026-09-08 09:48:13 -04:00
parent 1d622f536d
commit a0292d3063
2 changed files with 37 additions and 12 deletions
@@ -83,7 +83,7 @@
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label small">Instance</label> <label class="form-label small">Instance</label>
<InstancePicker Areas="_siteAreas" Instances="_siteInstances" <InstancePicker Areas="_siteAreas" Instances="_siteInstances"
ItemLabel="@(i => $"{i.UniqueName} ({i.State})")" ItemLabel="InstanceLabel"
SelectedInstanceId="_selectedInstanceId" SelectedInstanceIdChanged="OnInstancePicked" SelectedInstanceId="_selectedInstanceId" SelectedInstanceIdChanged="OnInstancePicked"
Disabled="@_connected" DataTestPrefix="debug-instance" /> Disabled="@_connected" DataTestPrefix="debug-instance" />
</div> </div>
@@ -455,17 +455,22 @@
} }
} }
/// <summary>Handles a pick from the <c>InstancePicker</c> combobox.</summary> /// <summary>
private void OnInstancePicked(int id) /// The label the <c>InstancePicker</c> renders on a row and in its field:
{ /// the instance's unique name with its lifecycle state.
_selectedInstanceId = id; /// </summary>
OnInstanceSelectionChanged(); /// <param name="instance">The instance to label.</param>
} /// <returns>The display label, e.g. <c>Line1.Mixer (Enabled)</c>.</returns>
private static string InstanceLabel(Instance instance) =>
$"{instance.UniqueName} ({instance.State})";
private void OnInstanceSelectionChanged() /// <summary>
{ /// Records the instance the operator picked in the <c>InstancePicker</c>.
// No-op; selection is tracked via _selectedInstanceId binding /// Everything downstream (the Connect button's enablement, <c>Connect()</c>
} /// itself) reads <c>_selectedInstanceId</c>, so there is nothing else to do.
/// </summary>
/// <param name="id">Id of the picked instance.</param>
private void OnInstancePicked(int id) => _selectedInstanceId = id;
/// <summary> /// <summary>
/// When the attribute filter changes, expand the tree so any branches holding /// When the attribute filter changes, expand the tree so any branches holding
@@ -1,3 +1,4 @@
using System.Reflection;
using System.Security.Claims; using System.Security.Claims;
using Bunit; using Bunit;
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
@@ -21,7 +22,8 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Deployment;
/// <c>&lt;select&gt;</c> to the shared <c>InstancePicker</c> area-tree combobox /// <c>&lt;select&gt;</c> to the shared <c>InstancePicker</c> area-tree combobox
/// (design 2026-09-08). Pins that the page hands the picker the site's areas and /// (design 2026-09-08). Pins that the page hands the picker the site's areas and
/// its Enabled-only instance list, that drilling down the tree selects an instance, /// its Enabled-only instance list, that drilling down the tree selects an instance,
/// and that the selection still enables <em>Connect</em>. /// that the selection still enables <em>Connect</em>, and that a live connection
/// locks the picker down.
/// </summary> /// </summary>
public class DebugViewInstancePickerTests : BunitContext public class DebugViewInstancePickerTests : BunitContext
{ {
@@ -153,4 +155,22 @@ public class DebugViewInstancePickerTests : BunitContext
.First(b => b.TextContent.Contains("Connect")); .First(b => b.TextContent.Contains("Connect"));
Assert.False(connect.HasAttribute("disabled")); Assert.False(connect.HasAttribute("disabled"));
} }
[Fact]
public void WhileConnected_ThePickerIsDisabled()
{
RegisterServices();
var cut = Render<DebugViewPage>();
cut.Find("[data-test='debug-site-select']").Change(SiteId.ToString());
// Mark the page connected the way the other DebugView page tests do —
// driving the real gRPC stream is not available to a bUnit render.
cut.InvokeAsync(() => typeof(DebugViewPage)
.GetField("_connected", BindingFlags.Instance | BindingFlags.NonPublic)!
.SetValue(cut.Instance, true));
cut.Render();
Assert.True(cut.Find("[data-test='debug-instance-input']").HasAttribute("disabled"));
Assert.True(cut.Find("[data-test='debug-instance-toggle']").HasAttribute("disabled"));
}
} }