using Bunit; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared; using ZB.MOM.WW.ScadaBridge.CentralUI.Services; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Design; /// /// M9-T31 (+#261 follow-up): the raw-JSON escape hatch in /// (the fallback for an unresolved $ref / /// unknown-type node) is a Monaco json editor wired with THAT FIELD's own /// sub-schema — not the whole root object schema — so each field's editor /// validates/completes against just its own portion of the type. These tests /// assert at the C#/interop boundary that the correct per-field fragment reaches /// each editor's JsonSchema parameter (and that a sibling field's resolved /// shape never leaks in), using FindComponents when 2+ escape-hatch fields /// are present. The JS hover/completion itself is Monaco-built-in and not /// unit-testable here. /// public class ParameterValueFormMonacoSchemaTests : BunitContext { private readonly ISchemaLibraryQueryService _library = Substitute.For(); public ParameterValueFormMonacoSchemaTests() { // The escape-hatch surface renders a MonacoEditor whose JS interop is not // exercised here — Loose mode lets the unconfigured createEditor call no-op // so the render completes and we can assert on the editor's parameters. JSInterop.Mode = JSRuntimeMode.Loose; _library.GetSchemaMapAsync(Arg.Any()) .Returns(new Dictionary()); Services.AddSingleton(_library); } [Fact] public void EscapeHatch_RendersMonacoJsonEditor_NotPlainTextarea() { // A nested field whose $ref cannot be resolved drops to the raw-JSON // escape hatch. That surface must now be a Monaco json editor. const string schema = """ { "type": "object", "properties": { "payload": { "$ref": "lib:Missing" } } } """; var cut = Render(p => p .Add(x => x.ParameterDefinitions, schema) .Add(x => x.Values, new Dictionary())); var editor = cut.FindComponent(); Assert.Equal("json", editor.Instance.Language); // No plain