513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
230 lines
9.5 KiB
C#
230 lines
9.5 KiB
C#
using System.Security.Claims;
|
|
using ZB.MOM.WW.ScadaBridge.Security;
|
|
using Bunit;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
|
using NotificationListsPage = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Notifications.NotificationLists;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Pages;
|
|
|
|
/// <summary>
|
|
/// bUnit rendering tests for the standalone Notification Lists page.
|
|
/// </summary>
|
|
public class NotificationListsPageTests : BunitContext
|
|
{
|
|
private void WireAuthAndDialog()
|
|
{
|
|
Services.AddSingleton<IDialogService>(new AlwaysConfirmDialogService());
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim(JwtTokenService.UsernameClaimType, "tester"),
|
|
new Claim(JwtTokenService.RoleClaimType, "Designer"),
|
|
};
|
|
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
|
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(user));
|
|
Services.AddAuthorizationCore();
|
|
Services.AddTestConfigurationMutations();
|
|
}
|
|
|
|
/// <summary>Verifies that the page renders a row for each notification list.</summary>
|
|
[Fact]
|
|
public void RendersNotificationListRows()
|
|
{
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList> { new("Ops On-Call") { Id = 1 } }));
|
|
repo.GetRecipientsByListIdAsync(1)
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationRecipient>>(
|
|
new List<NotificationRecipient> { new("Jane", "jane@example.com") }));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Assert.Contains("Ops On-Call", cut.Markup);
|
|
Assert.Contains("jane@example.com", cut.Markup);
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that the page shows an empty state when there are no lists.</summary>
|
|
[Fact]
|
|
public void ShowsEmptyState_WhenNoLists()
|
|
{
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList>()));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
Assert.Contains("No notification lists", cut.Markup));
|
|
}
|
|
|
|
/// <summary>Verifies that deleting a list confirms, deletes it and reloads the list.</summary>
|
|
[Fact]
|
|
public void DeleteList_ConfirmsThenDeletesAndReloads()
|
|
{
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList> { new("Ops On-Call") { Id = 1 } }));
|
|
repo.GetRecipientsByListIdAsync(1)
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationRecipient>>(
|
|
new List<NotificationRecipient>()));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForState(() => cut.Markup.Contains("Ops On-Call"));
|
|
|
|
var deleteButton = cut.FindAll("tbody tr button")
|
|
.First(b => b.TextContent.Contains("Delete"));
|
|
deleteButton.Click();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
repo.Received().DeleteNotificationListAsync(1);
|
|
repo.Received().SaveChangesAsync();
|
|
// Reload re-invokes the list query (once on init, once after delete).
|
|
repo.Received(2).GetAllNotificationListsAsync();
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that the type column renders SMS for an SMS list.</summary>
|
|
[Fact]
|
|
public void RendersTypeColumn_Sms()
|
|
{
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList>
|
|
{
|
|
new("SMS Alerts") { Id = 2, Type = NotificationType.Sms }
|
|
}));
|
|
repo.GetRecipientsByListIdAsync(2)
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationRecipient>>(
|
|
new List<NotificationRecipient>()));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Assert.Contains("SMS Alerts", cut.Markup);
|
|
Assert.Contains("Sms", cut.Markup);
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that an SMS list recipient badge shows the phone number instead of empty angle brackets.</summary>
|
|
[Fact]
|
|
public void SmsListRecipientBadge_ShowsPhoneNumber_NotEmptyAngleBrackets()
|
|
{
|
|
// CentralUI-NNN regression: an SMS recipient carries a PhoneNumber and a null
|
|
// EmailAddress. The badge must render the phone, not the email-shaped "Name <>".
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList>
|
|
{
|
|
new("SMS Alerts") { Id = 7, Type = NotificationType.Sms }
|
|
}));
|
|
repo.GetRecipientsByListIdAsync(7)
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationRecipient>>(
|
|
new List<NotificationRecipient> { NotificationRecipient.ForSms("Jane", "+15551234567") }));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Assert.Contains("+15551234567", cut.Markup);
|
|
// The bug rendered an empty contact field ("Jane <>") for SMS recipients.
|
|
Assert.DoesNotContain("Jane <>", cut.Markup);
|
|
Assert.DoesNotContain("Jane <>", cut.Markup);
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that the type column renders Email for an email list.</summary>
|
|
[Fact]
|
|
public void RendersTypeColumn_Email()
|
|
{
|
|
// The list name deliberately contains no channel word so that the only "Email"
|
|
// in the rendered markup originates from the Type column cell, not the name cell.
|
|
// This guards against false-passes where the name itself satisfies the assertion.
|
|
var repo = Substitute.For<INotificationRepository>();
|
|
repo.GetAllNotificationListsAsync()
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationList>>(
|
|
new List<NotificationList>
|
|
{
|
|
new("Ops Alerts") { Id = 3, Type = NotificationType.Email }
|
|
}));
|
|
repo.GetRecipientsByListIdAsync(3)
|
|
.Returns(Task.FromResult<IReadOnlyList<NotificationRecipient>>(
|
|
new List<NotificationRecipient>()));
|
|
Services.AddSingleton(repo);
|
|
WireAuthAndDialog();
|
|
|
|
var cut = Render<NotificationListsPage>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
// Verify the row name rendered.
|
|
Assert.Contains("Ops Alerts", cut.Markup);
|
|
|
|
// Locate the Type <td> in the rendered table row and assert its text content
|
|
// is exactly "Email". If the Type column were removed the <td> would not
|
|
// exist and the assertion would throw, catching the regression.
|
|
var typeCell = cut.FindAll("tbody tr td")
|
|
.FirstOrDefault(td => td.TextContent.Trim() == "Email");
|
|
Assert.NotNull(typeCell);
|
|
});
|
|
}
|
|
|
|
/// <summary>A dialog service that auto-confirms, so action paths run end-to-end.</summary>
|
|
private sealed class AlwaysConfirmDialogService : IDialogService
|
|
{
|
|
/// <inheritdoc />
|
|
public Task<bool> ConfirmAsync(string title, string message, bool danger = false, string? confirmLabel = null)
|
|
=> Task.FromResult(true);
|
|
|
|
// Register row 75 added a DialogSeverity overload. This stub auto-confirms
|
|
// regardless of severity — it exists to let action paths run end to end, not to
|
|
// assert anything about styling.
|
|
/// <inheritdoc />
|
|
public Task<bool> ConfirmAsync(string title, string message, DialogSeverity severity, string? confirmLabel = null)
|
|
=> Task.FromResult(true);
|
|
|
|
/// <inheritdoc />
|
|
public Task<string?> PromptAsync(
|
|
string title, string label, string initialValue = "", string? placeholder = null)
|
|
=> Task.FromResult<string?>(null);
|
|
|
|
/// <summary>Returns a completed task with the default result without showing a dialog.</summary>
|
|
/// <typeparam name="TResult">The dialog result type.</typeparam>
|
|
/// <param name="title">The dialog title.</param>
|
|
/// <param name="body">The dialog body fragment.</param>
|
|
/// <param name="size">The optional dialog size.</param>
|
|
/// <returns>A task that resolves to the default result.</returns>
|
|
public Task<TResult?> ShowAsync<TResult>(
|
|
string title,
|
|
Microsoft.AspNetCore.Components.RenderFragment<DialogContext<TResult>> body,
|
|
string? size = null)
|
|
=> Task.FromResult<TResult?>(default);
|
|
}
|
|
}
|