Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add E2E test for identity generation in client (#156)
Leendert de Borst4a207763cc2a
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razorindex fbaab63de..ce7e642a6 100644--- a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor+++ b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor@@ -66,7 +66,7 @@ else<h3 class="mb-4 text-xl font-semibold dark:text-white">Notes</h3><div class="grid gap-6"><div class="col-span-6 sm:col-span-3">- <EditFormRow Type="textarea" Id="first-name" Label="Notes" @bind-Value="Obj.Notes"></EditFormRow>+ <EditFormRow Type="textarea" Id="notes" Label="Notes" @bind-Value="Obj.Notes"></EditFormRow></div></div></div>diff --git a/src/AliasVault.Client/Services/SettingsService.cs b/src/AliasVault.Client/Services/SettingsService.csindex 242cf70c5..30ba2722a 100644--- a/src/AliasVault.Client/Services/SettingsService.cs+++ b/src/AliasVault.Client/Services/SettingsService.cs@@ -184,11 +184,7 @@ public class SettingsService{string value = GetSetting(key);- try- {- return CastSetting<T>(value);- }- catch (InvalidOperationException ex)+ if (string.IsNullOrEmpty(value)){// If no value is available in database but default value is set, return default value.if (defaultValue is not null)@@ -197,6 +193,15 @@ public class SettingsService}// No value in database and no default value set, throw exception.+ throw new InvalidOperationException($"Setting {key} is not set and no default value is provided");+ }++ try+ {+ return CastSetting<T>(value);+ }+ catch (InvalidOperationException ex)+ {throw new InvalidOperationException($"Failed to cast setting {key} to type {typeof(T)}", ex);}}diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.csindex 6a3f70285..424d507db 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs@@ -86,4 +86,43 @@ public class CredentialTest : ClientPlaywrightTestAssert.That(pageContent, Does.Contain("Credentials updated"), "Credential update confirmation message not shown.");Assert.That(pageContent, Does.Contain(serviceNameAfter), "Credential not updated correctly.");}++ /// <summary>+ /// Test if generating a new identity on the create new credential screen works.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task GenerateIdentityTest()+ {+ // Create a new alias with service name = "Test Service".+ var serviceName = "Test Service";++ await NavigateUsingBlazorRouter("add-credentials");+ await WaitForUrlAsync("add-credentials", "Add credentials");++ await InputHelper.FillInputFields(+ fieldValues: new Dictionary<string, string>+ {+ { "service-name", serviceName },+ });++ // Wait for button with text "Generate Random Identity" to appear.+ var generateButton = Page.Locator("text=Generate Random Identity");+ Assert.That(generateButton, Is.Not.Null, "Generate button not found.");++ // Press the button to generate a random identity.+ await generateButton.First.ClickAsync();++ // Wait for the identity fields to be filled.+ await Task.Delay(1000);++ // Verify that the identity fields are filled.+ var username = await Page.InputValueAsync("#username");+ var firstName = await Page.InputValueAsync("#first-name");+ var lastName = await Page.InputValueAsync("#last-name");++ Assert.That(username, Is.Not.Null.And.Not.Empty, "Username not generated.");+ Assert.That(firstName, Is.Not.Null.And.Not.Empty, "First name not generated.");+ Assert.That(lastName, Is.Not.Null.And.Not.Empty, "Last name not generated.");+ }}