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: the raw-JSON escape hatch in (the /// fallback for an unresolved $ref / unknown-type node) is a Monaco /// json editor wired with the form's RESOLVED schema, so Monaco's /// built-in JSON language gives schema-driven hover + completion. These tests /// assert at the C#/interop boundary that the resolved schema (with /// {"$ref":"lib:Name"} inlined) reaches the editor's JsonSchema /// parameter — 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