feat(centralui): TemplatePathFormatter — folder-path label for template pickers

Claude-Session: https://claude.ai/code/session_01G2GHPnbbKGvyyfbr2XBRVH
This commit is contained in:
Joseph Doherty
2026-08-21 06:53:40 -04:00
parent 22468c1548
commit 9261fa09fa
2 changed files with 76 additions and 0 deletions
@@ -0,0 +1,43 @@
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Services;
public class TemplatePathFormatterTests
{
private static Dictionary<int, TemplateFolder> Folders(params TemplateFolder[] f) => f.ToDictionary(x => x.Id);
[Fact]
public void RootTemplate_IsNameOnly()
{
var t = new Template("Motor Controller") { Id = 1, FolderId = null };
Assert.Equal("Motor Controller", TemplatePathFormatter.Format(t, Folders()));
}
[Fact]
public void NestedTemplate_JoinsFolderChainWithSlashes()
{
var controllers = new TemplateFolder("Controllers") { Id = 10, ParentFolderId = null };
var conveyor = new TemplateFolder("Conveyor") { Id = 11, ParentFolderId = 10 };
var t = new Template("MES Line Controller") { Id = 1, FolderId = 11 };
Assert.Equal("Controllers / Conveyor / MES Line Controller",
TemplatePathFormatter.Format(t, Folders(controllers, conveyor)));
}
[Fact]
public void UnknownFolderId_FallsBackToNameOnly_WithoutThrowing()
{
var t = new Template("Orphan") { Id = 1, FolderId = 999 };
Assert.Equal("Orphan", TemplatePathFormatter.Format(t, Folders()));
}
[Fact]
public void FolderCycle_Terminates()
{
var a = new TemplateFolder("A") { Id = 1, ParentFolderId = 2 };
var b = new TemplateFolder("B") { Id = 2, ParentFolderId = 1 };
var t = new Template("T") { Id = 1, FolderId = 1 };
var s = TemplatePathFormatter.Format(t, Folders(a, b));
Assert.EndsWith("T", s); // no hang, no exception
}
}