Le constructeur AppSetting lower-case les clés (ntfy.baseUrl → ntfy.baseurl). Les sections UI utilisaient du camelCase → champs vides au chargement + risque de doublons à l'édition. Normalisation des clés dans les 3 sections + tests.
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using Bunit;
|
|
using Heimdall.Web.Components.Settings;
|
|
using Heimdall.Web.Services;
|
|
using Heimdall.Web.Tests.Components.Pages;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MudBlazor;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.Web.Tests.Components.Settings;
|
|
|
|
public class AiSettingsSectionTests : PageTestBase
|
|
{
|
|
private static AppSettingItem Setting(string key, string value) =>
|
|
new(Guid.NewGuid(), key, value, key, "ai", "string", null, DateTime.UtcNow.AddDays(-1));
|
|
|
|
[Fact]
|
|
public void AiSection_AfficheChampsIA()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
{
|
|
Setting("ai.cpaiurl", "http://cpai:32168"),
|
|
Setting("ai.ollamaUrl", "http://ollama:11434"),
|
|
Setting("ai.detection.enabled", "true"),
|
|
});
|
|
LoginAs();
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("URL CodeProject.AI");
|
|
cut.Markup.ShouldContain("URL Ollama");
|
|
cut.Markup.ShouldContain("http://cpai:32168");
|
|
cut.Markup.ShouldContain("http://ollama:11434");
|
|
cut.Markup.ShouldContain("Détection IA activée");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AiSection_ModifieCpaiUrl_AppellePutAvecBonneCle()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ai.cpaiurl", "http://cpai:32168") });
|
|
Handler.On(HttpMethod.Put, "api/settings/ai.cpaiurl", System.Net.HttpStatusCode.OK);
|
|
LoginAs();
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("http://cpai:32168"));
|
|
|
|
cut.FindAll("input")[0].Change("http://cpai:32169");
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("ai.cpaiurl", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
}
|