feat(centralui): protocol selector + MxGateway editor in DataConnectionForm
Adds an OPC UA | MxGateway protocol dropdown (create-time; locked read-only on edit), branches the primary/backup endpoint editors, serializer, and validator by protocol, and persists DataConnection.Protocol accordingly. Updates form tests: protocol dropdown present on create + MxGateway save round-trips typed JSON with Protocol=MxGateway.
This commit is contained in:
@@ -44,12 +44,55 @@ public class DataConnectionFormTests : BunitContext
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoProtocolDropdown_IsRendered()
|
||||
public void ProtocolDropdown_IsRendered_OnCreate_WithBothProtocols()
|
||||
{
|
||||
var cut = RenderForCreateSite(1);
|
||||
Assert.DoesNotContain("Custom", cut.Markup);
|
||||
var labels = cut.FindAll("label").Select(l => l.TextContent.Trim()).ToList();
|
||||
Assert.DoesNotContain(labels, l => l == "Protocol");
|
||||
Assert.Contains(labels, l => l == "Protocol");
|
||||
|
||||
// The protocol select offers OPC UA and MxGateway.
|
||||
var optionTexts = cut.FindAll("option").Select(o => o.TextContent.Trim()).ToList();
|
||||
Assert.Contains("OPC UA", optionTexts);
|
||||
Assert.Contains("MxGateway", optionTexts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Save_MxGateway_PersistsTypedJsonAndProtocolMxGateway()
|
||||
{
|
||||
DataConnection? captured = null;
|
||||
await _siteRepo.AddDataConnectionAsync(
|
||||
Arg.Do<DataConnection>(d => captured = d));
|
||||
|
||||
var cut = RenderForCreateSite(1);
|
||||
|
||||
// Switch protocol to MxGateway — re-renders with the MxGateway editor.
|
||||
cut.FindAll("select")
|
||||
.First(s => s.QuerySelectorAll("option").Any(o => o.TextContent.Trim() == "MxGateway"))
|
||||
.Change("MxGateway");
|
||||
|
||||
// Name (skip readonly Site plaintext input; MxGateway editor inputs carry placeholders).
|
||||
cut.FindAll("input[type='text']")
|
||||
.First(i => !i.HasAttribute("readonly") && i.GetAttribute("placeholder") is null)
|
||||
.Change("MX-1");
|
||||
// Gateway endpoint
|
||||
cut.FindAll("input[type='text']")
|
||||
.First(i => i.GetAttribute("placeholder")?.StartsWith("http://") == true)
|
||||
.Change("http://gw:5000");
|
||||
// API key (password input)
|
||||
cut.FindAll("input[type='password']")
|
||||
.First(i => i.GetAttribute("placeholder")?.Contains("API key") == true)
|
||||
.Change("secret");
|
||||
|
||||
await cut.FindAll("button")
|
||||
.First(b => b.TextContent.Trim() == "Save").ClickAsync(new());
|
||||
|
||||
Assert.NotNull(captured);
|
||||
Assert.Equal("MxGateway", captured!.Protocol);
|
||||
Assert.NotNull(captured.PrimaryConfiguration);
|
||||
|
||||
using var doc = JsonDocument.Parse(captured.PrimaryConfiguration!);
|
||||
Assert.Equal("http://gw:5000",
|
||||
doc.RootElement.GetProperty("endpoint").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user