67 lines
2.9 KiB
C#
67 lines
2.9 KiB
C#
using Akka.Actor;
|
|
using Akka.Hosting;
|
|
using Bunit;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages;
|
|
using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
|
|
|
/// <summary>#1089: <c>/alarms-historian</c> shows a historian outage with its own badge, distinct from "stalled".</summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class AlarmsHistorianPageTests : BunitContext
|
|
{
|
|
private sealed class StatusActor : ReceiveActor
|
|
{
|
|
public StatusActor(HistorianSinkStatus status) => Receive<HistorianAdapterActor.GetStatus>(_ => Sender.Tell(status));
|
|
}
|
|
|
|
private sealed class Required(IActorRef actor) : IRequiredActor<HistorianAdapterActorKey>
|
|
{
|
|
public IActorRef ActorRef { get; } = actor;
|
|
public Task<IActorRef> GetAsync(CancellationToken cancellationToken = default) => Task.FromResult(ActorRef);
|
|
}
|
|
|
|
private static HistorianSinkStatus Status(bool stalled, bool unreachable) =>
|
|
new(5, 0, null, null, "Historian unavailable", HistorianDrainState.BackingOff, Stalled: stalled, HistorianUnreachable: unreachable);
|
|
|
|
private IRenderedComponent<AlarmsHistorian> RenderPage(ActorSystem sys, HistorianSinkStatus status)
|
|
{
|
|
JSInterop.Mode = JSRuntimeMode.Loose;
|
|
var actor = sys.ActorOf(Props.Create(() => new StatusActor(status)));
|
|
Services.AddSingleton<IRequiredActor<HistorianAdapterActorKey>>(new Required(actor));
|
|
return Render<AlarmsHistorian>();
|
|
}
|
|
|
|
[Fact]
|
|
public void An_unreachable_historian_shows_its_own_badge_and_not_the_stalled_one()
|
|
{
|
|
using var sys = ActorSystem.Create("hist-ui-1");
|
|
var cut = RenderPage(sys, Status(stalled: false, unreachable: true));
|
|
cut.WaitForAssertion(() => cut.Find("[data-testid=historian-unreachable]").TextContent.ShouldContain("unreachable"));
|
|
cut.FindAll("[data-testid=queue-stalled]").ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_stalled_queue_shows_the_stalled_badge_and_not_the_unreachable_one()
|
|
{
|
|
using var sys = ActorSystem.Create("hist-ui-2");
|
|
var cut = RenderPage(sys, Status(stalled: true, unreachable: false));
|
|
cut.WaitForAssertion(() => cut.Find("[data-testid=queue-stalled]").TextContent.ShouldContain("stalled"));
|
|
cut.FindAll("[data-testid=historian-unreachable]").ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_healthy_sink_shows_neither_badge()
|
|
{
|
|
using var sys = ActorSystem.Create("hist-ui-3");
|
|
var cut = RenderPage(sys, Status(stalled: false, unreachable: false));
|
|
cut.WaitForAssertion(() => cut.Find(".metric-card").TextContent.ShouldContain("Depth"));
|
|
cut.FindAll("[data-testid=queue-stalled],[data-testid=historian-unreachable]").ShouldBeEmpty();
|
|
}
|
|
}
|