2026-08-12 10:46:09 +02:00
|
|
|
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>
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
Setting("ai.cpaiurl", "http://cpai:32168"),
|
2026-08-12 10:46:09 +02:00
|
|
|
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()
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
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);
|
2026-08-12 10:46:09 +02:00
|
|
|
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 &&
|
2026-08-12 11:12:28 +02:00
|
|
|
r.RequestUri!.AbsolutePath.Contains("ai.cpaiurl", StringComparison.OrdinalIgnoreCase));
|
2026-08-12 10:46:09 +02:00
|
|
|
});
|
|
|
|
|
}
|
2026-08-12 11:50:47 +02:00
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AiSection_TestMoteurs_AppelleEndpointEtAfficheStatut()
|
|
|
|
|
{
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ai.cpaiurl", "http://cpai:32168") });
|
|
|
|
|
Handler.On(HttpMethod.Post, "api/settings/ai/test",
|
|
|
|
|
new { success = true, status = "Healthy", message = "CodeProject.AI reachable" });
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester les moteurs IA"));
|
|
|
|
|
|
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester les moteurs IA")).Click();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
|
|
|
|
Handler.Requests.ShouldContain(r =>
|
|
|
|
|
r.Method == HttpMethod.Post &&
|
|
|
|
|
r.RequestUri!.AbsolutePath.Contains("ai/test", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
cut.Markup.ShouldContain("CodeProject.AI reachable");
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|