Merge pull request #157 from lanedirt/156-add-e2e-test-for-generating-identity-via-client-gui

Add E2E test for identity generation in client (#156)
This commit is contained in:
Leendert de Borst
2024-08-05 13:53:21 -07:00
committed by GitHub
3 changed files with 54 additions and 6 deletions

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -86,4 +86,47 @@ public class CredentialTest : ClientPlaywrightTest
Assert.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.Multiple(
() =>
{
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.");
});
}
}