Add register warning test (#74)

This commit is contained in:
Leendert de Borst
2024-07-08 11:26:01 +02:00
parent 96a7fbaf3b
commit f5e02fb784
3 changed files with 44 additions and 3 deletions

View File

@@ -77,7 +77,10 @@
if (!result.IsSuccessStatusCode)
{
LoginBase.ParseResponse(responseContent);
foreach (var error in LoginBase.ParseResponse(responseContent))
{
_serverValidationErrors.AddError(error);
}
StateHasChanged();
return;
}

View File

@@ -241,7 +241,7 @@ public class PlaywrightTest
await registerButton.ClickAsync();
await WaitForURLAsync("**/user/register");
// Try to login with test credentials.
// Try to register an account with the generated test credentials.
var emailField = Page.Locator("input[id='email']");
var passwordField = Page.Locator("input[id='password']");
var password2Field = Page.Locator("input[id='password2']");
@@ -255,7 +255,6 @@ public class PlaywrightTest
// Check if we get redirected when clicking on the register button.
var submitButton = Page.Locator("button[type='submit']");
Console.WriteLine(submitButton);
await submitButton.ClickAsync();
// Check if we get redirected to the root URL after registration which means we are logged in.

View File

@@ -31,6 +31,45 @@ public class AuthTests : PlaywrightTest
await Login();
}
/// <summary>
/// Test if registering an account with the same email address as an existing account shows a warning.
/// </summary>
/// <returns>Async task.</returns>
[Test]
public async Task RegisterFormWarning()
{
// Logout.
await NavigateUsingBlazorRouter("user/logout");
await WaitForURLAsync("**/user/logout", "AliasVault");
// Wait and check if we get redirected to /user/login.
await WaitForURLAsync("**/user/login");
// Try to register a new account.
var registerButton = Page.Locator("a[href='/user/register']");
await registerButton.ClickAsync();
await WaitForURLAsync("**/user/register");
// Register account with same test credentials as used in the initial registration bootstrap method.
var emailField = Page.Locator("input[id='email']");
var passwordField = Page.Locator("input[id='password']");
var password2Field = Page.Locator("input[id='password2']");
await emailField.FillAsync(TestUserEmail);
await passwordField.FillAsync(TestUserPassword);
await password2Field.FillAsync(TestUserPassword);
// Check the terms of service checkbox
var termsCheckbox = Page.Locator("input[id='terms']");
await termsCheckbox.CheckAsync();
// Check if we get a visible warning when trying to register.
var submitButton = Page.Locator("button[type='submit']");
await submitButton.ClickAsync();
var warning = await Page.TextContentAsync("div[role='alert']");
Assert.That(warning, Does.Contain("is already taken."), "No visible warning when registering with existing email address.");
}
/// <summary>
/// Test if logging in works.
/// </summary>