From f5e02fb784aecf55fe9b1d701fa91d9fe63bdbd9 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Mon, 8 Jul 2024 11:26:01 +0200 Subject: [PATCH] Add register warning test (#74) --- .../Auth/Pages/Register.razor | 5 ++- .../Common/PlaywrightTest.cs | 3 +- .../AliasVault.E2ETests/Tests/AuthTests.cs | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/AliasVault.WebApp/Auth/Pages/Register.razor b/src/AliasVault.WebApp/Auth/Pages/Register.razor index c6428b88d..be9a371bf 100644 --- a/src/AliasVault.WebApp/Auth/Pages/Register.razor +++ b/src/AliasVault.WebApp/Auth/Pages/Register.razor @@ -77,7 +77,10 @@ if (!result.IsSuccessStatusCode) { - LoginBase.ParseResponse(responseContent); + foreach (var error in LoginBase.ParseResponse(responseContent)) + { + _serverValidationErrors.AddError(error); + } StateHasChanged(); return; } diff --git a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs index 52417af2e..303796ad2 100644 --- a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs +++ b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs @@ -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. diff --git a/src/Tests/AliasVault.E2ETests/Tests/AuthTests.cs b/src/Tests/AliasVault.E2ETests/Tests/AuthTests.cs index 97968bdd6..8f5a3a267 100644 --- a/src/Tests/AliasVault.E2ETests/Tests/AuthTests.cs +++ b/src/Tests/AliasVault.E2ETests/Tests/AuthTests.cs @@ -31,6 +31,45 @@ public class AuthTests : PlaywrightTest await Login(); } + /// + /// Test if registering an account with the same email address as an existing account shows a warning. + /// + /// Async task. + [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."); + } + /// /// Test if logging in works. ///