b540d8ac2c
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Bunit;
|
||
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
|
||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||
|
||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Components;
|
||
|
||
/// <summary>
|
||
/// Covers the <c>AlarmStateBadges</c> shared component lifted out of
|
||
/// <c>DebugView</c>. The badge cluster must render identically
|
||
/// wherever it is hosted, so these tests pin the rendered markup: state badge
|
||
/// class, kind label, native sub-state badges, severity, and HiLo level.
|
||
/// </summary>
|
||
public class AlarmStateBadgesTests : BunitContext
|
||
{
|
||
private static AlarmStateChanged ActiveNativeHighUnacked() => new(
|
||
InstanceUniqueName: "Tank01",
|
||
AlarmName: "Tank01.Level.HiHi",
|
||
State: AlarmState.Active,
|
||
Priority: 700,
|
||
Timestamp: DateTimeOffset.UtcNow)
|
||
{
|
||
Kind = AlarmKind.NativeOpcUa,
|
||
Level = AlarmLevel.High,
|
||
Condition = new AlarmConditionState(
|
||
Active: true,
|
||
Acknowledged: false,
|
||
Confirmed: null,
|
||
Shelve: AlarmShelveState.Unshelved,
|
||
Suppressed: false,
|
||
Severity: 700),
|
||
};
|
||
|
||
/// <summary>Verifies that the state, kind, sub-state, severity and level badges are rendered.</summary>
|
||
[Fact]
|
||
public void Renders_StateKindSubStateSeverityAndLevel_Badges()
|
||
{
|
||
var alarm = ActiveNativeHighUnacked();
|
||
|
||
var cut = Render<AlarmStateBadges>(p => p.Add(c => c.Alarm, alarm));
|
||
|
||
// State badge: Active condition tinted danger.
|
||
Assert.Contains("bg-danger", cut.Markup);
|
||
Assert.Contains("Active", cut.Markup);
|
||
|
||
// Kind badge label for a native OPC UA alarm.
|
||
Assert.Contains("OPC UA", cut.Markup);
|
||
|
||
// Native sub-state badge: active + unacknowledged.
|
||
Assert.Contains("Unacked", cut.Markup);
|
||
|
||
// Severity span on the unified 0–1000 scale.
|
||
Assert.Contains("sev 700", cut.Markup);
|
||
|
||
// HiLo level badge label.
|
||
Assert.Contains("Hi", cut.Markup);
|
||
}
|
||
|
||
/// <summary>Gitea #102: a MES-reportable alarm shows the MES badge.</summary>
|
||
[Fact]
|
||
public void MesReportableAlarm_RendersMesBadge()
|
||
{
|
||
var alarm = ActiveNativeHighUnacked() with { IsMesReportable = true };
|
||
|
||
var cut = Render<AlarmStateBadges>(p => p.Add(c => c.Alarm, alarm));
|
||
|
||
Assert.Equal("MES", cut.Find("[data-test='alarm-mes-badge']").TextContent);
|
||
}
|
||
|
||
/// <summary>Gitea #102: a non-reportable alarm shows no MES badge.</summary>
|
||
[Fact]
|
||
public void NonMesReportableAlarm_RendersNoMesBadge()
|
||
{
|
||
var cut = Render<AlarmStateBadges>(p => p.Add(c => c.Alarm, ActiveNativeHighUnacked()));
|
||
|
||
Assert.Empty(cut.FindAll("[data-test='alarm-mes-badge']"));
|
||
}
|
||
}
|