using System.Security.Claims; using Bunit; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using NSubstitute; using ScadaLink.Commons.Entities.ExternalSystems; using ScadaLink.Commons.Entities.InboundApi; using ScadaLink.Commons.Entities.Notifications; using ScadaLink.Commons.Entities.Scripts; using ScadaLink.Commons.Entities.Templates; using ScadaLink.Commons.Interfaces.Repositories; using ScadaLink.Commons.Interfaces.Transport; using ScadaLink.Commons.Types.Transport; using ScadaLink.Security; using ScadaLink.Transport; using ScadaLink.Transport.Export; using TransportExportPage = ScadaLink.CentralUI.Components.Pages.Design.TransportExport; namespace ScadaLink.CentralUI.Tests.Pages.Design; /// /// bUnit + logic tests for the TransportExport wizard (Component #24, Task T21). /// /// /// Covers the four contract points the design plan calls out: /// /// /// Step 1 renders the template tree plus every flat artifact group. /// Step 2 surfaces the dependency-resolved closure (seed vs auto-included). /// Step 4 invokes with the user's /// selected ids and authenticated identity. /// The page-level RequireDesign policy denies a user lacking the /// Design role (router enforcement; the component code-behind never sees /// the request). /// /// /// /// JS interop is set to loose mode so the TreeView's sessionStorage round-trip /// and the transport-bundle download interop don't need stubs per test. The /// scadalinkTransport.downloadBundle call returns void — loose mode is /// the lighter wiring than re-stubbing it in every export-path test. /// /// public class TransportExportPageTests : BunitContext { private readonly ITemplateEngineRepository _templateRepo = Substitute.For(); private readonly IExternalSystemRepository _externalRepo = Substitute.For(); private readonly INotificationRepository _notificationRepo = Substitute.For(); private readonly IInboundApiRepository _inboundApiRepo = Substitute.For(); private readonly IBundleExporter _exporter = Substitute.For(); public TransportExportPageTests() { JSInterop.Mode = JSRuntimeMode.Loose; // Default empty repos so OnInitializedAsync doesn't throw — individual // tests override the bits they care about. _templateRepo.GetAllTemplatesAsync(Arg.Any()) .Returns(Task.FromResult>(new List