Files
jdescopingtool/NEW/tests/JdeScoping.Ui.Tests/LoginPageTests.cs
T
2026-02-10 07:47:48 -05:00

49 lines
2.1 KiB
C#

using System.Text.RegularExpressions;
using JdeScoping.Ui.Tests.Helpers;
using JdeScoping.Ui.Tests.Support;
namespace JdeScoping.Ui.Tests;
/// <summary>
/// Playwright UI tests for the Login page.
/// Validates that the login form renders, credentials are accepted, and logout revokes the session.
/// Requires a running Docker host (Category: RequiresDockerHost).
/// </summary>
public sealed class LoginPageTests(PlaywrightFixture fixture) : UiTestBase(fixture)
{
/// <summary>
/// Verifies the login page renders, credentials authenticate the user, and logout revokes the session.
/// </summary>
/// <remarks>
/// Steps:
/// <list type="number">
/// <item>Navigate to the login page.</item>
/// <item>Assert the page title contains "Login - JDE Scoping Tool".</item>
/// <item>Submit test credentials via UiAuthHelper.LoginAsync.</item>
/// <item>Assert the user sees the Logout button or remains on the login view.</item>
/// <item>Invoke UiAuthHelper.LogoutAsync.</item>
/// <item>GET /api/auth/me and assert HTTP 401 (session revoked).</item>
/// </list>
/// </remarks>
[Fact]
[Trait("Category", "RequiresDockerHost")]
public async Task LoginPage_AllowsLoginAndLogout()
{
await RunAsync(async page =>
{
await UiNavigationHelper.NavigateToLoginAsync(page);
await Assertions.Expect(page).ToHaveTitleAsync(new Regex("Login - JDE Scoping Tool"));
await UiAuthHelper.LoginAsync(page);
var loggedOutView = page.GetByText("Authentication Required");
var logoutButton = page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Logout" });
bool authenticated = await logoutButton.IsVisibleAsync();
bool stillOnLogin = await loggedOutView.IsVisibleAsync();
Assert.True(authenticated || stillOnLogin);
await UiAuthHelper.LogoutAsync(page);
var meAfterLogout = await page.Context.APIRequest.GetAsync("/api/auth/me");
Assert.Equal(401, meAfterLogout.Status);
});
}
}