Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/TemplateListLoadTests.cs
T

42 lines
2.0 KiB
C#

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>());
}
}