test(ui/design): roundtrip tests + normalization notice for IO editors
Editors now set a _normalized flag when ParseFromJson coalesces a
legacy type name (lowercase "string", "Int32", "Double", etc.) to the
canonical set. When flagged, render a small alert-info inline:
"Some parameter types were normalized... Save to persist the
canonical form." The flag clears on any user edit so the notice
doesn't linger after Emit overwrites the JSON.
31 new bUnit tests in tests/.../Shared/:
- ParameterListEditorTests: null/empty rendering, row count per
JSON entry, legacy type normalization across .NET names +
lowercase, the normalized notice trigger, add/remove emission,
List/non-List item-type column visibility, required-flag round
trip, invalid JSON + non-array error paths.
- ReturnTypeEditorTests: null vs simple vs List shape, legacy type
normalization, change-type / clear-type emission, invalid JSON
+ non-object error paths.
Total CentralUI test count: 82 -> 113.
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
<button class="btn btn-link btn-sm p-0 ms-2" type="button" @onclick="StartFresh">Start fresh</button>
|
||||
</div>
|
||||
}
|
||||
@if (_normalized)
|
||||
{
|
||||
<div class="alert alert-info py-2 small mb-2">
|
||||
Some parameter types were normalized to the current type set. Save to persist the canonical form.
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (_rows.Count > 0)
|
||||
{
|
||||
@@ -87,6 +93,7 @@ else if (_parseError == null)
|
||||
|
||||
private List<ParamRow> _rows = new();
|
||||
private string? _parseError;
|
||||
private bool _normalized;
|
||||
private string? _lastSeenJson;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
@@ -101,6 +108,7 @@ else if (_parseError == null)
|
||||
private void ParseFromJson()
|
||||
{
|
||||
_parseError = null;
|
||||
_normalized = false;
|
||||
_rows = new();
|
||||
if (string.IsNullOrWhiteSpace(Json)) return;
|
||||
|
||||
@@ -119,11 +127,17 @@ else if (_parseError == null)
|
||||
var rawType = el.TryGetProperty("type", out var t) ? t.GetString() ?? "String" : "String";
|
||||
var rawItem = el.TryGetProperty("itemType", out var it) ? it.GetString() ?? "String" : "String";
|
||||
var required = !el.TryGetProperty("required", out var rq) || rq.ValueKind != JsonValueKind.False;
|
||||
var normType = NormalizeType(rawType);
|
||||
var normItem = NormalizeType(rawItem);
|
||||
if (normType != rawType || (rawType == "List" && normItem != rawItem))
|
||||
{
|
||||
_normalized = true;
|
||||
}
|
||||
_rows.Add(new ParamRow
|
||||
{
|
||||
Name = name,
|
||||
Type = NormalizeType(rawType),
|
||||
ItemType = NormalizeType(rawItem),
|
||||
Type = normType,
|
||||
ItemType = normItem,
|
||||
Required = required
|
||||
});
|
||||
}
|
||||
@@ -172,6 +186,7 @@ else if (_parseError == null)
|
||||
{
|
||||
var json = SerializeToJson();
|
||||
_lastSeenJson = json;
|
||||
_normalized = false;
|
||||
await JsonChanged.InvokeAsync(json);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
<button class="btn btn-link btn-sm p-0 ms-2" type="button" @onclick="StartFresh">Start fresh</button>
|
||||
</div>
|
||||
}
|
||||
@if (_normalized)
|
||||
{
|
||||
<div class="alert alert-info py-2 small mb-2">
|
||||
Return type was normalized to the current type set. Save to persist the canonical form.
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="row g-2 align-items-end">
|
||||
<div class="col-md-3">
|
||||
@@ -44,6 +50,7 @@
|
||||
private string _type = "";
|
||||
private string _itemType = "String";
|
||||
private string? _parseError;
|
||||
private bool _normalized;
|
||||
private string? _lastSeenJson;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
@@ -58,6 +65,7 @@
|
||||
private void ParseFromJson()
|
||||
{
|
||||
_parseError = null;
|
||||
_normalized = false;
|
||||
_type = "";
|
||||
_itemType = "String";
|
||||
if (string.IsNullOrWhiteSpace(Json)) return;
|
||||
@@ -70,8 +78,14 @@
|
||||
_parseError = "Expected a JSON object with a type field.";
|
||||
return;
|
||||
}
|
||||
_type = doc.RootElement.TryGetProperty("type", out var t) ? NormalizeType(t.GetString() ?? "") : "";
|
||||
_itemType = doc.RootElement.TryGetProperty("itemType", out var it) ? NormalizeType(it.GetString() ?? "String") : "String";
|
||||
var rawType = doc.RootElement.TryGetProperty("type", out var t) ? t.GetString() ?? "" : "";
|
||||
var rawItem = doc.RootElement.TryGetProperty("itemType", out var it) ? it.GetString() ?? "String" : "String";
|
||||
_type = NormalizeType(rawType);
|
||||
_itemType = NormalizeType(rawItem);
|
||||
if (_type != rawType || (rawType == "List" && _itemType != rawItem))
|
||||
{
|
||||
_normalized = true;
|
||||
}
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
@@ -112,6 +126,7 @@
|
||||
json = JsonSerializer.Serialize(obj);
|
||||
}
|
||||
_lastSeenJson = json;
|
||||
_normalized = false;
|
||||
await JsonChanged.InvokeAsync(json);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user