feat(adminui): tag-path completion inside ctx.GetTag/SetVirtualTag literals

This commit is contained in:
Joseph Doherty
2026-06-09 14:53:15 -04:00
parent d1434933b4
commit 521fb61e44
2 changed files with 71 additions and 2 deletions
@@ -0,0 +1,41 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.ScriptAnalysis;
public sealed class TagPathCompletionTests
{
private sealed class FakeCatalog : IScriptTagCatalog
{
public Task<IReadOnlyList<string>> GetPathsAsync(string? filter, CancellationToken ct)
=> Task.FromResult<IReadOnlyList<string>>(new[] { "Motor.Speed", "Motor.Temp" });
}
private static readonly ScriptAnalysisService Svc = new(new FakeCatalog());
private static async Task<IReadOnlyList<string>> Labels(string code, int line, int col)
=> (await Svc.CompleteAsync(new CompletionsRequest(code, line, col))).Items.Select(i => i.Label).ToList();
[Fact] public async Task Empty_literal_in_GetTag_offers_tag_paths()
{
// caret between the quotes of ctx.GetTag("") — verify/adjust the column so the caret is inside the literal.
(await Labels("""ctx.GetTag("")""", 1, 13)).ShouldContain("Motor.Speed");
}
[Fact] public async Task Partial_literal_in_GetTag_offers_tag_paths()
{
(await Labels("""ctx.GetTag("Mot")""", 1, 15)).ShouldContain("Motor.Speed");
}
[Fact] public async Task SetVirtualTag_literal_also_offers_tag_paths()
{
(await Labels("""ctx.SetVirtualTag("")""", 1, 20)).ShouldContain("Motor.Speed");
}
[Fact] public async Task Outside_a_tag_literal_does_not_offer_tag_paths()
{
// a string literal NOT inside GetTag/SetVirtualTag → no tag-path suggestions
(await Labels("""var s = "";""", 1, 10)).ShouldNotContain("Motor.Speed");
}
}