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.
81 lines
2.9 KiB
C#
81 lines
2.9 KiB
C#
using System.Security.Claims;
|
|
using Bunit;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests;
|
|
|
|
/// <summary>
|
|
/// bUnit rendering tests for CentralUI Blazor components.
|
|
/// Verifies that pages render their expected markup structure.
|
|
/// </summary>
|
|
public class ComponentRenderingTests : BunitContext
|
|
{
|
|
/// <summary>Verifies that the login page renders a form with username and password fields.</summary>
|
|
[Fact]
|
|
public void LoginPage_RendersForm_WithUsernameAndPasswordFields()
|
|
{
|
|
var cut = Render<Login>();
|
|
|
|
// Verify the form action
|
|
var form = cut.Find("form");
|
|
Assert.Equal("/auth/login", form.GetAttribute("action"));
|
|
|
|
// Verify username field
|
|
var usernameInput = cut.Find("input#username");
|
|
Assert.Equal("text", usernameInput.GetAttribute("type"));
|
|
Assert.Equal("username", usernameInput.GetAttribute("name"));
|
|
|
|
// Verify password field
|
|
var passwordInput = cut.Find("input#password");
|
|
Assert.Equal("password", passwordInput.GetAttribute("type"));
|
|
Assert.Equal("password", passwordInput.GetAttribute("name"));
|
|
|
|
// Verify submit button
|
|
var submitButton = cut.Find("button[type='submit']");
|
|
Assert.Contains("Sign in", submitButton.TextContent);
|
|
}
|
|
|
|
/// <summary>Verifies that the login page does not render an alert when there is no error.</summary>
|
|
[Fact]
|
|
public void LoginPage_WithoutError_DoesNotRenderAlert()
|
|
{
|
|
var cut = Render<Login>();
|
|
|
|
Assert.Throws<Bunit.ElementNotFoundException>(() => cut.Find("div.panel.notice.login-error"));
|
|
}
|
|
|
|
/// <summary>Verifies that the dashboard page requires an authorize attribute.</summary>
|
|
[Fact]
|
|
public void Dashboard_RequiresAuthorizeAttribute()
|
|
{
|
|
var authorizeAttrs = typeof(Dashboard)
|
|
.GetCustomAttributes(typeof(AuthorizeAttribute), true);
|
|
Assert.NotEmpty(authorizeAttrs);
|
|
}
|
|
|
|
/// <summary>Verifies that the templates page requires the Design authorization policy.</summary>
|
|
[Fact]
|
|
public void TemplateEditor_RequiresDesignPolicy()
|
|
{
|
|
var authorizeAttrs = typeof(ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Design.Templates)
|
|
.GetCustomAttributes(typeof(AuthorizeAttribute), true);
|
|
Assert.NotEmpty(authorizeAttrs);
|
|
|
|
var attr = (AuthorizeAttribute)authorizeAttrs[0];
|
|
Assert.Equal("RequireDesign", attr.Policy);
|
|
}
|
|
|
|
/// <summary>Verifies that the login page renders the ScadaBridge title.</summary>
|
|
[Fact]
|
|
public void LoginPage_RendersScadaBridgeTitle()
|
|
{
|
|
var cut = Render<Login>();
|
|
|
|
var title = cut.Find("h1.login-title");
|
|
Assert.Contains("ScadaBridge", title.TextContent);
|
|
}
|
|
}
|