Updating game data to mid season patch and made card gallery nicer
This commit is contained in:
@@ -3,8 +3,8 @@ using Microsoft.Playwright.NUnit;
|
||||
namespace Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for Playwright tests that require an authenticated session.
|
||||
/// Signs in via the dev-only bypass endpoint before each test.
|
||||
/// Base class for Playwright tests that require an authenticated session.
|
||||
/// Signs in via the dev-only bypass endpoint before each test.
|
||||
/// </summary>
|
||||
public abstract class AuthenticatedPageTest : PageTest
|
||||
{
|
||||
@@ -13,8 +13,9 @@ public abstract class AuthenticatedPageTest : PageTest
|
||||
[SetUp]
|
||||
public async Task SignIn()
|
||||
{
|
||||
var response = await Page.APIRequestContext.PostAsync($"{BaseUrl}/api/auth/dev-login");
|
||||
var response = await Page.APIRequest.PostAsync($"{BaseUrl}/api/auth/dev-login");
|
||||
if (!response.Ok)
|
||||
throw new Exception($"Dev login failed with status {response.Status}. Ensure the server is running in Development mode.");
|
||||
throw new Exception(
|
||||
$"Dev login failed with status {response.Status}. Ensure the server is running in Development mode.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@ namespace Tests;
|
||||
[TestFixture]
|
||||
public class DeckBuilderTests : AuthenticatedPageTest
|
||||
{
|
||||
private DeckBuilderPage _builderPage = null!;
|
||||
private Guid _savedDeckId = Guid.Empty;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -25,6 +22,9 @@ public class DeckBuilderTests : AuthenticatedPageTest
|
||||
await client.DeleteAsync($"{BaseUrl}/api/decks/{_savedDeckId}");
|
||||
}
|
||||
|
||||
private DeckBuilderPage _builderPage = null!;
|
||||
private Guid _savedDeckId = Guid.Empty;
|
||||
|
||||
[Test]
|
||||
public async Task DeckBuilder_AddFortyCards_TwoDivers_SavesToDB()
|
||||
{
|
||||
@@ -36,16 +36,14 @@ public class DeckBuilderTests : AuthenticatedPageTest
|
||||
// Add 40 cards first — this proves the Blazor SignalR circuit is active.
|
||||
// Click the first 13 browser cards 3 times each (39), then the 14th once (40th).
|
||||
for (var i = 0; i < 13; i++)
|
||||
{
|
||||
for (var copy = 0; copy < 3; copy++)
|
||||
{
|
||||
await _builderPage.BrowserCards.Nth(i).ClickAsync();
|
||||
}
|
||||
}
|
||||
for (var copy = 0; copy < 3; copy++)
|
||||
await _builderPage.BrowserCards.Nth(i).ClickAsync();
|
||||
|
||||
await _builderPage.BrowserCards.Nth(13).ClickAsync();
|
||||
|
||||
// Verify the deck has exactly 40 cards
|
||||
await Expect(_builderPage.CardCountLabel).ToContainTextAsync("40", new() { Timeout = 15_000 });
|
||||
await Expect(_builderPage.CardCountLabel)
|
||||
.ToContainTextAsync("40", new LocatorAssertionsToContainTextOptions { Timeout = 15_000 });
|
||||
|
||||
// Circuit is confirmed active — now fill the deck name so @bind:event=oninput fires correctly
|
||||
await _builderPage.NameInput.ClickAsync();
|
||||
@@ -54,24 +52,27 @@ public class DeckBuilderTests : AuthenticatedPageTest
|
||||
|
||||
// Add first diver
|
||||
await _builderPage.DiverSlots.Nth(0).ClickAsync();
|
||||
await Expect(_builderPage.DiverPickerCards.First).ToBeVisibleAsync(new() { Timeout = 5_000 });
|
||||
await Expect(_builderPage.DiverPickerCards.First)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 5_000 });
|
||||
await _builderPage.DiverPickerCards.Nth(0).ClickAsync();
|
||||
|
||||
// Add second diver
|
||||
await _builderPage.DiverSlots.Nth(1).ClickAsync();
|
||||
await Expect(_builderPage.DiverPickerCards.First).ToBeVisibleAsync(new() { Timeout = 5_000 });
|
||||
await Expect(_builderPage.DiverPickerCards.First)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 5_000 });
|
||||
await _builderPage.DiverPickerCards.Nth(0).ClickAsync();
|
||||
|
||||
// Save the deck
|
||||
await _builderPage.SaveButton.ClickAsync();
|
||||
|
||||
// Confirm save succeeded before waiting for redirect
|
||||
await Expect(_builderPage.SaveToast).ToContainTextAsync("Saved!", new() { Timeout = 10_000 });
|
||||
await Expect(_builderPage.SaveToast)
|
||||
.ToContainTextAsync("Saved!", new LocatorAssertionsToContainTextOptions { Timeout = 10_000 });
|
||||
|
||||
// After first save the page redirects to /deck-builder/{guid}
|
||||
await Page.WaitForURLAsync(
|
||||
new Regex(@"/deck-builder/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"),
|
||||
new() { Timeout = 10_000 }
|
||||
new PageWaitForURLOptions { Timeout = 10_000 }
|
||||
);
|
||||
|
||||
// Extract saved deck ID from URL for cleanup
|
||||
@@ -80,13 +81,14 @@ public class DeckBuilderTests : AuthenticatedPageTest
|
||||
if (match.Success) _savedDeckId = Guid.Parse(match.Value);
|
||||
|
||||
// Verify save toast
|
||||
await Expect(_builderPage.SaveToast).ToContainTextAsync("Saved!", new() { Timeout = 5_000 });
|
||||
await Expect(_builderPage.SaveToast)
|
||||
.ToContainTextAsync("Saved!", new LocatorAssertionsToContainTextOptions { Timeout = 5_000 });
|
||||
|
||||
// Navigate to My Decks and confirm the deck is listed with correct name
|
||||
await Page.GotoAsync($"{BaseUrl}/my-decks");
|
||||
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await Page.WaitForSelectorAsync(".deck-card", new() { Timeout = 10_000 });
|
||||
await Page.WaitForSelectorAsync(".deck-card", new PageWaitForSelectorOptions { Timeout = 10_000 });
|
||||
|
||||
await Expect(Page.Locator(".deck-name").First).ToContainTextAsync(deckName[..10]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,10 @@ public class DeckBuilderPage : BasePage
|
||||
public ILocator DiverSlots => Page.Locator(".diver-slot");
|
||||
public ILocator DiverPickerCards => Page.Locator(".diver-picker-card");
|
||||
|
||||
public async Task GotoAsync() => await NavigateToAsync("/deck-builder");
|
||||
public async Task GotoAsync()
|
||||
{
|
||||
await NavigateToAsync("/deck-builder");
|
||||
}
|
||||
|
||||
public async Task WaitForInteractiveAsync()
|
||||
{
|
||||
@@ -25,4 +28,4 @@ public class DeckBuilderPage : BasePage
|
||||
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await Page.WaitForSelectorAsync(".browser-card", new PageWaitForSelectorOptions { Timeout = 10_000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,22 @@ namespace Tests.PageObjects;
|
||||
|
||||
public class LoginPage : BasePage
|
||||
{
|
||||
public LoginPage(IPage page) : base(page) { }
|
||||
public LoginPage(IPage page) : base(page)
|
||||
{
|
||||
}
|
||||
|
||||
public ILocator EnrollButton =>
|
||||
Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Enroll Passkey" });
|
||||
|
||||
public ILocator SignInButton =>
|
||||
Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Sign in with Passkey" });
|
||||
|
||||
public ILocator EnrollButton => Page.GetByRole(AriaRole.Button, new() { Name = "Enroll Passkey" });
|
||||
public ILocator SignInButton => Page.GetByRole(AriaRole.Button, new() { Name = "Sign in with Passkey" });
|
||||
public ILocator ErrorMessage => Page.Locator(".alert-danger");
|
||||
|
||||
public async Task GotoAsync() => await NavigateToAsync("/login");
|
||||
public async Task GotoAsync()
|
||||
{
|
||||
await NavigateToAsync("/login");
|
||||
}
|
||||
|
||||
public async Task WaitForInteractiveAsync()
|
||||
{
|
||||
@@ -18,4 +27,4 @@ public class LoginPage : BasePage
|
||||
// Wait for Blazor circuit: either button must be visible
|
||||
await Page.WaitForSelectorAsync("button", new PageWaitForSelectorOptions { Timeout = 10_000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@ namespace Tests;
|
||||
[TestFixture]
|
||||
public class PasskeyTests : PageTest
|
||||
{
|
||||
private const string BaseUrl = "http://localhost:5256";
|
||||
private LoginPage _loginPage = null!;
|
||||
|
||||
[SetUp]
|
||||
public async Task SetUp()
|
||||
{
|
||||
@@ -30,26 +27,35 @@ public class PasskeyTests : PageTest
|
||||
await Page.Context.ClearCookiesAsync();
|
||||
}
|
||||
|
||||
private const string BaseUrl = "http://localhost:5256";
|
||||
private LoginPage _loginPage = null!;
|
||||
|
||||
[Test]
|
||||
public async Task LoginPage_WhenNoCredentials_ShowsEnrollButton()
|
||||
{
|
||||
await _loginPage.GotoAsync();
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
|
||||
await Expect(_loginPage.EnrollButton).ToBeVisibleAsync(new() { Timeout = 10_000 });
|
||||
await Expect(_loginPage.EnrollButton)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 10_000 });
|
||||
await Expect(_loginPage.SignInButton).Not.ToBeVisibleAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EnrollPasskey_CompletesSuccessfully_AndRedirectsHome()
|
||||
{
|
||||
var authenticatorId = await Page.Context.AddVirtualAuthenticatorAsync(new VirtualAuthenticatorOptions
|
||||
var cdp = await Page.Context.NewCDPSessionAsync(Page);
|
||||
await cdp.SendAsync("WebAuthn.enable");
|
||||
await cdp.SendAsync("WebAuthn.addVirtualAuthenticator", new Dictionary<string, object>
|
||||
{
|
||||
Protocol = "ctap2",
|
||||
Transport = "internal",
|
||||
HasResidentKey = true,
|
||||
HasUserVerification = true,
|
||||
IsUserVerified = true,
|
||||
["options"] = new Dictionary<string, object>
|
||||
{
|
||||
["protocol"] = "ctap2",
|
||||
["transport"] = "internal",
|
||||
["hasResidentKey"] = true,
|
||||
["hasUserVerification"] = true,
|
||||
["isUserVerified"] = true
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
@@ -57,28 +63,35 @@ public class PasskeyTests : PageTest
|
||||
await _loginPage.GotoAsync();
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
|
||||
await Expect(_loginPage.EnrollButton).ToBeVisibleAsync(new() { Timeout = 10_000 });
|
||||
await Expect(_loginPage.EnrollButton)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 10_000 });
|
||||
await _loginPage.EnrollButton.ClickAsync();
|
||||
|
||||
// After enrollment + auto sign-in, redirects away from /login
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"), new() { Timeout = 20_000 });
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"),
|
||||
new PageWaitForURLOptions { Timeout = 20_000 });
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Page.Context.RemoveVirtualAuthenticatorAsync(authenticatorId);
|
||||
await cdp.SendAsync("WebAuthn.disable");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LoginPage_AfterEnrollment_ShowsSignInButton()
|
||||
{
|
||||
var authenticatorId = await Page.Context.AddVirtualAuthenticatorAsync(new VirtualAuthenticatorOptions
|
||||
var cdp = await Page.Context.NewCDPSessionAsync(Page);
|
||||
await cdp.SendAsync("WebAuthn.enable");
|
||||
await cdp.SendAsync("WebAuthn.addVirtualAuthenticator", new Dictionary<string, object>
|
||||
{
|
||||
Protocol = "ctap2",
|
||||
Transport = "internal",
|
||||
HasResidentKey = true,
|
||||
HasUserVerification = true,
|
||||
IsUserVerified = true,
|
||||
["options"] = new Dictionary<string, object>
|
||||
{
|
||||
["protocol"] = "ctap2",
|
||||
["transport"] = "internal",
|
||||
["hasResidentKey"] = true,
|
||||
["hasUserVerification"] = true,
|
||||
["isUserVerified"] = true
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
@@ -87,7 +100,8 @@ public class PasskeyTests : PageTest
|
||||
await _loginPage.GotoAsync();
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
await _loginPage.EnrollButton.ClickAsync();
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"), new() { Timeout = 20_000 });
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"),
|
||||
new PageWaitForURLOptions { Timeout = 20_000 });
|
||||
|
||||
// Clear the auth cookie and navigate back to /login
|
||||
await Page.Context.ClearCookiesAsync();
|
||||
@@ -95,24 +109,30 @@ public class PasskeyTests : PageTest
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
|
||||
// Should show Sign In button (credential is enrolled)
|
||||
await Expect(_loginPage.SignInButton).ToBeVisibleAsync(new() { Timeout = 10_000 });
|
||||
await Expect(_loginPage.SignInButton)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 10_000 });
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Page.Context.RemoveVirtualAuthenticatorAsync(authenticatorId);
|
||||
await cdp.SendAsync("WebAuthn.disable");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SignInWithPasskey_AfterEnrollment_AuthenticatesSuccessfully()
|
||||
{
|
||||
var authenticatorId = await Page.Context.AddVirtualAuthenticatorAsync(new VirtualAuthenticatorOptions
|
||||
var cdp = await Page.Context.NewCDPSessionAsync(Page);
|
||||
await cdp.SendAsync("WebAuthn.enable");
|
||||
await cdp.SendAsync("WebAuthn.addVirtualAuthenticator", new Dictionary<string, object>
|
||||
{
|
||||
Protocol = "ctap2",
|
||||
Transport = "internal",
|
||||
HasResidentKey = true,
|
||||
HasUserVerification = true,
|
||||
IsUserVerified = true,
|
||||
["options"] = new Dictionary<string, object>
|
||||
{
|
||||
["protocol"] = "ctap2",
|
||||
["transport"] = "internal",
|
||||
["hasResidentKey"] = true,
|
||||
["hasUserVerification"] = true,
|
||||
["isUserVerified"] = true
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
@@ -121,22 +141,25 @@ public class PasskeyTests : PageTest
|
||||
await _loginPage.GotoAsync();
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
await _loginPage.EnrollButton.ClickAsync();
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"), new() { Timeout = 20_000 });
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"),
|
||||
new PageWaitForURLOptions { Timeout = 20_000 });
|
||||
|
||||
// Sign out (clear cookie) and return to login
|
||||
await Page.Context.ClearCookiesAsync();
|
||||
await _loginPage.GotoAsync();
|
||||
await _loginPage.WaitForInteractiveAsync();
|
||||
|
||||
await Expect(_loginPage.SignInButton).ToBeVisibleAsync(new() { Timeout = 10_000 });
|
||||
await Expect(_loginPage.SignInButton)
|
||||
.ToBeVisibleAsync(new LocatorAssertionsToBeVisibleOptions { Timeout = 10_000 });
|
||||
await _loginPage.SignInButton.ClickAsync();
|
||||
|
||||
// After sign-in, redirects away from /login
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"), new() { Timeout = 20_000 });
|
||||
await Page.WaitForURLAsync(new Regex(@"^http://localhost:5256(?!/login)"),
|
||||
new PageWaitForURLOptions { Timeout = 20_000 });
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Page.Context.RemoveVirtualAuthenticatorAsync(authenticatorId);
|
||||
await cdp.SendAsync("WebAuthn.disable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ namespace Tests;
|
||||
[TestFixture]
|
||||
public class PlaywrightTests : AuthenticatedPageTest
|
||||
{
|
||||
|
||||
[Test]
|
||||
public async Task HomePage_ShouldLoad()
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TestSetup
|
||||
WorkingDirectory = currentDir
|
||||
};
|
||||
|
||||
_serverProcess = Process.Start(startInfo);
|
||||
_serverProcess = Process.Start(startInfo) ?? throw new Exception("Failed to start server process.");
|
||||
|
||||
_serverProcess.OutputDataReceived += (s, e) =>
|
||||
{
|
||||
@@ -46,8 +46,6 @@ public class TestSetup
|
||||
_serverProcess.BeginOutputReadLine();
|
||||
_serverProcess.BeginErrorReadLine();
|
||||
|
||||
if (_serverProcess == null) throw new Exception("Failed to start server process.");
|
||||
|
||||
// Wait for the server to be ready
|
||||
using var client = new HttpClient();
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0"/>
|
||||
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.60.0"/>
|
||||
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.61.0"/>
|
||||
<PackageReference Include="NUnit" Version="4.3.2"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.7.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
|
||||
|
||||
Reference in New Issue
Block a user