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;
/// Review 2026-10-21 07/P-1: the landing page must not load the full tracked template graph just to count.
public class TemplateListLoadTests : BunitContext
{
/// The Dashboard counts templates from stubs, never the full graph.
/// A task that represents the asynchronous operation.
[Fact]
public async Task Dashboard_CountsTemplatesFromStubs_NotFullGraph()
{
var repo = Substitute.For();
repo.GetTemplateStubsAsync(Arg.Any()).Returns(Task.FromResult>(
new List { new(1, "A", null, null, false, null), new(2, "B", null, null, false, null) }));
var sites = Substitute.For();
sites.GetAllSitesAsync().Returns(new List());
sites.GetAllDataConnectionsAsync().Returns(new List());
var keys = Substitute.For();
Services.AddSingleton(repo);
Services.AddSingleton(sites);
Services.AddSingleton(keys);
Services.AddSingleton(Substitute.For());
AddAuthorization();
var cut = Render();
await cut.WaitForStateAsync(() => cut.Markup.Contains("Templates"));
await repo.Received(1).GetTemplateStubsAsync(Arg.Any());
await repo.DidNotReceive().GetAllTemplatesAsync(Arg.Any());
}
}