From 48dfb875bd354392eff258b31972fce5391c9841 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 19 Jun 2026 00:38:06 -0400 Subject: [PATCH] test(centralui): fix stale List-override round-trip assertion to mirror the page's real string-row encode cycle (CASE A) (#163) --- .../InstanceConfigureListOverrideTests.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Deployment/InstanceConfigureListOverrideTests.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Deployment/InstanceConfigureListOverrideTests.cs index 12f97735..1f959912 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Deployment/InstanceConfigureListOverrideTests.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Deployment/InstanceConfigureListOverrideTests.cs @@ -82,15 +82,25 @@ public class InstanceConfigureListOverrideTests [Fact] public void EncodedRows_RoundTripThroughCodec_AsThePageDoes() { - // Mirrors the load (Decode → rows) / save (Encode → JSON) cycle the page runs. - var json = AttributeValueCodec.Encode(new List { "10", "20", "30" }); + // Mirrors the save (Encode rows → JSON) / load (Decode JSON → rows) cycle + // the page runs. The editor's working rows are always strings + // (GetListRows → List), so the page encodes a List; the + // element type is fixed by the base attribute (Int32 here). + var rows = new List { "10", "20", "30" }; + var json = AttributeValueCodec.Encode(rows); + + // Decode validates the rows against the element type and yields a typed list. var decoded = AttributeValueCodec.Decode(json, DataType.List, DataType.Int32); var list = Assert.IsType>(decoded); Assert.Equal(new[] { 10, 20, 30 }, list); - // The re-encoded form is stable, so a clean override round-trips losslessly. - var roundTrip = AttributeValueCodec.Encode(decoded); - Assert.Equal(json, roundTrip); + // The page reloads by decoding then re-encoding each element back to a + // string row (DecodeListRows), then re-saves by encoding those string rows. + // That full page round-trip is stable, so a clean override is lossless. + var reloadedRows = list.Select(x => AttributeValueCodec.Encode(x) ?? string.Empty).ToList(); + Assert.Equal(rows, reloadedRows); + var reEncoded = AttributeValueCodec.Encode(reloadedRows); + Assert.Equal(json, reEncoded); } [Fact]