perf(centralui): load template stubs/analysis projections instead of the full tracked graph (review 2026-10-21 07/P-1, 08/P1)
This commit is contained in:
+4
-2
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Bunit.TestDoubles;
|
||||
@@ -108,8 +109,9 @@ public class InstanceCreateTemplateFieldTests : BunitContext
|
||||
new("Elsewhere") { Id = 8, FolderId = 3 },
|
||||
};
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(templates));
|
||||
_repo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(templates).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(folders));
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class TemplateEditInheritedSetTests : BunitContext
|
||||
IsDerived = true,
|
||||
};
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(
|
||||
new List<Template> { grandparent, baseTemplate, derived }));
|
||||
_repo.GetTemplateWithChildrenAsync(DerivedId, Arg.Any<CancellationToken>())
|
||||
|
||||
+13
-8
@@ -1,3 +1,4 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -61,8 +62,9 @@ public class TransportExportPageTests : BunitContext
|
||||
|
||||
// Default empty repos so OnInitializedAsync doesn't throw — individual
|
||||
// tests override the bits they care about.
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template>()).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>())
|
||||
@@ -139,8 +141,9 @@ public class TransportExportPageTests : BunitContext
|
||||
// export page no longer offers a keys selection list, only API methods.
|
||||
var apiMethod = new ApiMethod("CreateOrder", "// noop") { Id = 70 };
|
||||
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { template }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetAllSharedScriptsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<SharedScript>>(new List<SharedScript> { script }));
|
||||
_externalRepo.GetAllExternalSystemsAsync(Arg.Any<CancellationToken>())
|
||||
@@ -218,8 +221,9 @@ public class TransportExportPageTests : BunitContext
|
||||
});
|
||||
var motor = new Template("Motor") { Id = 2 };
|
||||
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { pump, motor }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { pump, motor }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<Template?>(pump));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(2, Arg.Any<CancellationToken>())
|
||||
@@ -262,8 +266,9 @@ public class TransportExportPageTests : BunitContext
|
||||
public async Task Step4_triggers_ExportAsync_with_selected_artifacts_and_user_identity()
|
||||
{
|
||||
var template = new Template("Pump") { Id = 1 };
|
||||
_templateRepo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_templateRepo.GetTemplateStubsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
(new List<Template> { template }).Select(t => new TemplateStub(t.Id, t.Name, t.ParentTemplateId, t.FolderId, t.IsDerived, t.OwnerCompositionId)).ToList()));
|
||||
_templateRepo.GetTemplateWithChildrenAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<Template?>(template));
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Security.Claims;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Security;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using Dashboard = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Dashboard;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Pages;
|
||||
|
||||
/// <summary>Review 2026-10-21 07/P-1: the landing page must not load the full tracked template graph just to count.</summary>
|
||||
public class TemplateListLoadTests : BunitContext
|
||||
{
|
||||
/// <summary>The Dashboard counts templates from stubs, never the full graph.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Dashboard_CountsTemplatesFromStubs_NotFullGraph()
|
||||
{
|
||||
var repo = Substitute.For<ITemplateEngineRepository>();
|
||||
repo.GetTemplateStubsAsync(Arg.Any<CancellationToken>()).Returns(Task.FromResult<IReadOnlyList<TemplateStub>>(
|
||||
new List<TemplateStub> { new(1, "A", null, null, false, null), new(2, "B", null, null, false, null) }));
|
||||
var sites = Substitute.For<ISiteRepository>();
|
||||
sites.GetAllSitesAsync().Returns(new List<Site>());
|
||||
sites.GetAllDataConnectionsAsync().Returns(new List<DataConnection>());
|
||||
var keys = Substitute.For<IInboundApiKeyAdmin>();
|
||||
Services.AddSingleton(repo);
|
||||
Services.AddSingleton(sites);
|
||||
Services.AddSingleton(keys);
|
||||
Services.AddSingleton(Substitute.For<AuthenticationStateProvider>());
|
||||
AddAuthorization();
|
||||
|
||||
var cut = Render<Dashboard>();
|
||||
await cut.WaitForStateAsync(() => cut.Markup.Contains("Templates"));
|
||||
|
||||
await repo.Received(1).GetTemplateStubsAsync(Arg.Any<CancellationToken>());
|
||||
await repo.DidNotReceive().GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void Renders_EmptyState_WhenNoTemplatesOrFolders()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -85,7 +85,7 @@ public class TemplatesPageTests : BunitContext
|
||||
{
|
||||
var folder = new TemplateFolder("Dev") { Id = 1 };
|
||||
var template = new Template("TestMachine") { Id = 5, FolderId = 1 };
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder> { folder }));
|
||||
@@ -114,7 +114,7 @@ public class TemplatesPageTests : BunitContext
|
||||
new TemplateComposition("DelmiaReceiver") { Id = 10, ComposedTemplateId = 99 });
|
||||
var composed = new Template("Other") { Id = 99 };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { template, composed }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -153,7 +153,7 @@ public class TemplatesPageTests : BunitContext
|
||||
cvdReactor.Compositions.Add(
|
||||
new TemplateComposition("LeftReactorSide") { Id = 200, TemplateId = 1, ComposedTemplateId = 8 });
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(
|
||||
new List<Template> { cvdReactor, reactorSide, leftReactorSide, leakTest }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
@@ -191,7 +191,7 @@ public class TemplatesPageTests : BunitContext
|
||||
var alpha = new Template("AlphaDevice") { Id = 10, FolderId = 1 };
|
||||
var beta = new Template("BetaDevice") { Id = 20, FolderId = 1 };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { alpha, beta }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder> { folder }));
|
||||
@@ -243,7 +243,7 @@ public class TemplatesPageTests : BunitContext
|
||||
var beta = new TemplateFolder("Beta") { Id = 2, ParentFolderId = null, SortOrder = 1 };
|
||||
var all = new List<TemplateFolder> { alpha, beta };
|
||||
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(_ => Task.FromResult<IReadOnlyList<TemplateFolder>>(all));
|
||||
@@ -307,7 +307,7 @@ public class TemplatesPageTests : BunitContext
|
||||
// Tree reloaded after the mutation: LoadTemplatesAsync re-fetched (initial
|
||||
// load + post-reorder reload). GetAllTemplatesAsync is only touched by the
|
||||
// page's load path, never by ReorderFolderAsync, so 2 calls == one reload.
|
||||
_repo.Received(2).GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
_repo.Received(2).GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that choosing move up dispatches a reorder up and reloads the tree.</summary>
|
||||
@@ -333,7 +333,7 @@ public class TemplatesPageTests : BunitContext
|
||||
Assert.Equal(1, alpha.SortOrder);
|
||||
|
||||
// Tree reloaded after the mutation (one reload == GetAllTemplatesAsync twice).
|
||||
_repo.Received(2).GetAllTemplatesAsync(Arg.Any<CancellationToken>());
|
||||
_repo.Received(2).GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that move up is disabled for the first sibling folder.</summary>
|
||||
@@ -372,7 +372,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void RootContextMenu_OffersNewFolderAndNewTemplate()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -392,7 +392,7 @@ public class TemplatesPageTests : BunitContext
|
||||
[Fact]
|
||||
public void RootContextMenu_NewTemplate_NavigatesToRootCreate()
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template>()));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
@@ -417,7 +417,7 @@ public class TemplatesPageTests : BunitContext
|
||||
|
||||
private void SeedOneTemplate(int id, string name)
|
||||
{
|
||||
_repo.GetAllTemplatesAsync(Arg.Any<CancellationToken>())
|
||||
_repo.GetAllTemplatesForAnalysisAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<Template>>(new List<Template> { new(name) { Id = id } }));
|
||||
_repo.GetAllFoldersAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<TemplateFolder>>(new List<TemplateFolder>()));
|
||||
|
||||
Reference in New Issue
Block a user