2026-08-10 13:10:37 +02:00
|
|
|
using Bunit;
|
|
|
|
|
using Heimdall.Web.Components.Pages;
|
|
|
|
|
using Heimdall.Web.Services;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using MudBlazor;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Web.Tests.Components.Pages;
|
|
|
|
|
|
|
|
|
|
public class SettingsPageTests : PageTestBase
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
2026-08-12 10:46:09 +02:00
|
|
|
public void SettingsPage_AfficheLesSectionsVisuelles()
|
2026-08-10 13:10:37 +02:00
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>());
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<SettingsPage>();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
2026-08-12 10:46:09 +02:00
|
|
|
// Plus de CRUD clé/valeur : chaque domaine a sa section dédiée
|
|
|
|
|
cut.Markup.ShouldContain("Stockage");
|
|
|
|
|
cut.Markup.ShouldContain("Notifications");
|
|
|
|
|
cut.Markup.ShouldContain("Intelligence artificielle");
|
|
|
|
|
cut.Markup.ShouldContain("Défauts agents");
|
2026-08-10 13:10:37 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-08-12 10:46:09 +02:00
|
|
|
public void SettingsPage_PasDeChampCleLibre()
|
2026-08-10 13:10:37 +02:00
|
|
|
{
|
2026-08-12 10:46:09 +02:00
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>());
|
2026-08-10 13:10:37 +02:00
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<SettingsPage>();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
2026-08-12 10:46:09 +02:00
|
|
|
// L'exigence produit : plus aucun champ « Clé » libre dans l'UI
|
|
|
|
|
cut.Markup.ShouldNotContain("Clé *");
|
|
|
|
|
cut.Markup.ShouldNotContain("Nouveau paramètre");
|
2026-08-10 13:10:37 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingsPage_RechargerConfig_AfficheSucces()
|
|
|
|
|
{
|
2026-08-12 10:46:09 +02:00
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>());
|
2026-08-10 13:10:37 +02:00
|
|
|
Handler.On(HttpMethod.Post, "api/settings/reload", System.Net.HttpStatusCode.OK);
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<SettingsPage>();
|
2026-08-12 10:46:09 +02:00
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Configuration"));
|
2026-08-10 13:10:37 +02:00
|
|
|
|
2026-08-12 10:46:09 +02:00
|
|
|
// Le refresh est le seul MudIconButton de la page (header)
|
2026-08-10 13:10:37 +02:00
|
|
|
cut.FindAll("button.mud-icon-button")[0].Click();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
var snackbar = Services.GetRequiredService<ISnackbar>();
|
|
|
|
|
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
|
|
|
|
.ShouldContain(m => m.Contains("Configuration rechargée", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-08-12 10:46:09 +02:00
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingsPage_ApiIndisponible_LaPageRendSansCrash()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/settings", System.Net.HttpStatusCode.InternalServerError);
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = RenderPage<SettingsPage>();
|
|
|
|
|
|
|
|
|
|
// Les sections gèrent leur propre échec de chargement (défauts) — pas de crash global
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Stockage"));
|
|
|
|
|
}
|
2026-08-10 13:10:37 +02:00
|
|
|
}
|