test(e2e): add InstanceConfigureFixture (template+attr+connection+area+instance on site-a)

Also extends AddAttributeAsync with an optional dataSourceReference parameter
so the fixture attribute appears in both _bindingDataSourceAttrs (bindings UI)
and _overrideAttrs (overrides UI) on the InstanceConfigure page.
This commit is contained in:
Joseph Doherty
2026-06-06 11:41:52 -04:00
parent a8a515ec8a
commit e618137ce7
2 changed files with 115 additions and 4 deletions
@@ -70,14 +70,34 @@ public static partial class CliRunner
/// (<c>Boolean</c>, <c>Int32</c>, <c>Double</c>, <c>String</c>).
/// Defaults to <c>Double</c>.
/// </param>
/// <param name="dataSourceReference">
/// Optional data source reference (tag path). When provided, maps to
/// <c>--data-source</c> on the CLI and sets
/// <c>TemplateAttribute.DataSourceReference</c>. The InstanceConfigure page
/// populates <c>_bindingDataSourceAttrs</c> by filtering attributes to those
/// where <c>DataSourceReference</c> is non-empty, so an attribute that needs
/// to appear in the Connection Bindings panel MUST be created with this set.
/// </param>
/// <exception cref="InvalidOperationException">The CLI failed.</exception>
public static async Task AddAttributeAsync(int templateId, string name, string dataType = "Double")
public static async Task AddAttributeAsync(
int templateId, string name, string dataType = "Double",
string? dataSourceReference = null)
{
await RunAsync(
var inv = System.Globalization.CultureInfo.InvariantCulture;
var args = new List<string>
{
"template", "attribute", "add",
"--template-id", templateId.ToString(System.Globalization.CultureInfo.InvariantCulture),
"--template-id", templateId.ToString(inv),
"--name", name,
"--data-type", dataType);
"--data-type", dataType,
};
if (!string.IsNullOrEmpty(dataSourceReference))
{
args.Add("--data-source");
args.Add(dataSourceReference);
}
await RunAsync([.. args]);
}
/// <summary>
@@ -0,0 +1,91 @@
using System.Text.Json;
using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Deployment;
/// <summary>
/// <see cref="IAsyncLifetime"/> fixture for the InstanceConfigure E2E tests. Provisions, on the real
/// running <c>site-a</c>: a zztest template with a single bindable <c>Double</c> attribute, a zztest
/// data-connection (so the bindings UI has a connection to assign), a zztest area (for the
/// area-reassignment test), and one instance created with no area. The instance is NOT deployed —
/// bindings/overrides/area assignment are pre-deploy configuration operations.
///
/// <para>
/// <b>Why the attribute is created with <c>--data-source "Value"</c>:</b>
/// <c>InstanceConfigure.razor.cs</c> populates <c>_bindingDataSourceAttrs</c> by filtering
/// <c>GetAttributesByTemplateIdAsync</c> to attributes where
/// <c>!string.IsNullOrEmpty(a.DataSourceReference)</c> (line 581 of InstanceConfigure.razor).
/// A plain <c>Double</c> attribute created <em>without</em> <c>--data-source</c> has
/// <c>DataSourceReference = null</c>, so it would not appear in the Connection Bindings panel
/// and the bindings-UI tests would silently see "No data-sourced attributes". The attribute
/// DOES appear unconditionally in <c>_overrideAttrs</c> (filtered only on <c>!IsLocked</c>,
/// line 592), so overrides work with or without a tag path. The fixture therefore sets
/// <c>dataSourceReference: "Value"</c> when adding the attribute so both panels are exercised.
/// </para>
/// </summary>
public sealed class InstanceConfigureFixture : IAsyncLifetime
{
private const string SiteAIdentifier = "site-a";
public int SiteAId { get; private set; }
public int TemplateId { get; private set; }
public int ConnectionId { get; private set; }
public int AreaId { get; private set; }
public int InstanceId { get; private set; }
/// <summary>The single bindable/overridable attribute name on the fixture template.</summary>
public string AttributeName => "Value";
/// <summary>The fixture data-connection name (for locating it in the bindings UI dropdown).</summary>
public string ConnectionName { get; private set; } = string.Empty;
public bool Available { get; private set; }
public async Task InitializeAsync()
{
Available = await ClusterAvailability.IsAvailableAsync();
if (!Available)
{
return;
}
try
{
SiteAId = await CliRunner.ResolveSiteIdAsync(SiteAIdentifier);
TemplateId = await CliRunner.CreateTemplateAsync(CliRunner.UniqueName("cfgtmpl"));
// The attribute must have DataSourceReference set (via --data-source) so it appears
// in _bindingDataSourceAttrs on the InstanceConfigure page. Without it the Connection
// Bindings panel shows "No data-sourced attributes" and binding tests cannot run.
// See the class-level XML doc for the full analysis.
await CliRunner.AddAttributeAsync(TemplateId, AttributeName, "Double", dataSourceReference: AttributeName);
ConnectionName = CliRunner.UniqueName("conn");
ConnectionId = await CliRunner.CreateDataConnectionAsync(SiteAId, ConnectionName);
AreaId = await CliRunner.CreateAreaAsync(SiteAId, CliRunner.UniqueName("cfgarea"));
InstanceId = await CliRunner.CreateInstanceAsync(CliRunner.UniqueName("cfginst"), TemplateId, SiteAId);
}
catch
{
await SafeCleanupAsync();
Available = false;
throw;
}
}
public async Task DisposeAsync()
{
if (!Available)
{
return;
}
await SafeCleanupAsync();
}
private async Task SafeCleanupAsync()
{
await CliRunner.DeleteInstanceAsync(InstanceId);
await CliRunner.DeleteDataConnectionAsync(ConnectionId);
await CliRunner.DeleteAreaAsync(AreaId);
await CliRunner.DeleteTemplateAsync(TemplateId);
}
}