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:
@@ -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>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user