test(centralui): fix stale List-override round-trip assertion to mirror the page's real string-row encode cycle (CASE A) (#163)
This commit is contained in:
+15
-5
@@ -82,15 +82,25 @@ public class InstanceConfigureListOverrideTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void EncodedRows_RoundTripThroughCodec_AsThePageDoes()
|
public void EncodedRows_RoundTripThroughCodec_AsThePageDoes()
|
||||||
{
|
{
|
||||||
// Mirrors the load (Decode → rows) / save (Encode → JSON) cycle the page runs.
|
// Mirrors the save (Encode rows → JSON) / load (Decode JSON → rows) cycle
|
||||||
var json = AttributeValueCodec.Encode(new List<string> { "10", "20", "30" });
|
// the page runs. The editor's working rows are always strings
|
||||||
|
// (GetListRows → List<string>), so the page encodes a List<string>; the
|
||||||
|
// element type is fixed by the base attribute (Int32 here).
|
||||||
|
var rows = new List<string> { "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 decoded = AttributeValueCodec.Decode(json, DataType.List, DataType.Int32);
|
||||||
var list = Assert.IsType<List<int>>(decoded);
|
var list = Assert.IsType<List<int>>(decoded);
|
||||||
Assert.Equal(new[] { 10, 20, 30 }, list);
|
Assert.Equal(new[] { 10, 20, 30 }, list);
|
||||||
|
|
||||||
// The re-encoded form is stable, so a clean override round-trips losslessly.
|
// The page reloads by decoding then re-encoding each element back to a
|
||||||
var roundTrip = AttributeValueCodec.Encode(decoded);
|
// string row (DecodeListRows), then re-saves by encoding those string rows.
|
||||||
Assert.Equal(json, roundTrip);
|
// 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]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user