using System.Net; using System.Text.RegularExpressions; using HrynCo.NotificationService.DAL.Abstract.Providers; using HrynCo.NotificationService.DAL.Abstract.Repositories; using HrynCo.NotificationService.DAL.EF; using Microsoft.Extensions.DependencyInjection; namespace HrynCo.NotificationService.Web.IntegrationTests; public sealed class AdminNavigationTests(TemplateDatabaseFixture fixture) : IClassFixture { [Fact] public async Task LayoutLinksToApiDocumentationInNewTab_AndScalarIsAvailable() { await using var context = await DefinitionApiTestContext.CreateAsync(fixture); var pages = new[] { "/admin/services", "/admin/channels", "/admin/services/create", "/admin/channels/create" }; foreach (var page in pages) { var html = await context.Client.GetStringAsync(page); Assert.Single(Regex.Matches(html, "class=\"admin-api-documentation\"")); Assert.Contains("href=\"/scalar/v1\" target=\"_blank\" rel=\"noopener noreferrer\"", html); Assert.Contains("aria-label=\"API documentation (opens in a new tab)\">API documentation", html); } Assert.Equal(HttpStatusCode.OK, (await context.Client.GetAsync("/scalar/v1")).StatusCode); } [Fact] public async Task BothListTablesHaveScopedGridBorders_AndRetainTemplateHeaderOnFilterMiss() { await using var context = await DefinitionApiTestContext.CreateAsync(fixture); var services = await context.Client.GetStringAsync("/admin/services"); Assert.Contains("table table-hover admin-data-table", services); var templates = await context.Client.GetStringAsync($"/admin/services/{context.ServiceId}?key=Missing"); Assert.Contains("table table-hover admin-data-table service-template-grid", templates); Assert.Contains("class=\"template-actions\"", templates); Assert.Contains("No templates match this key.", templates); Assert.Contains("class=\"template-key-filter\"", templates); } [Fact] public async Task AllFourDataTablesShareTheGridClassAndScopedColumnHeaders() { await using var context = await DefinitionApiTestContext.CreateAsync(fixture); using var scope = context.App.Services.CreateScope(); await scope.ServiceProvider.GetRequiredService().AddAsync(new EmailChannel { ServiceName = "TestService", EmailChannelType = EmailChannelType.Smtp, Settings = new SmtpChannelSettings { Host = "localhost", FromEmail = "test@example.invalid" } }); await scope.ServiceProvider.GetRequiredService().SaveChangesAsync(); var pages = new[] { "/admin/services", $"/admin/services/{context.ServiceId}", "/admin/channels", $"/admin/services/{context.ServiceId}/edit" }; foreach (var page in pages) { var html = await context.Client.GetStringAsync(page); Assert.Single(Regex.Matches(html, "]+admin-data-table")); Assert.Equal(Regex.Matches(html, "]").Count, Regex.Matches(html, "", html); } } }