mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-04-08 08:38:04 -04:00
Update end to end tests (#1404)
This commit is contained in:
@@ -294,6 +294,20 @@ public class ClientPlaywrightTest : PlaywrightTest
|
||||
Assert.That(pageContent, Does.Not.Contain(itemName), "Item not deleted successfully.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a field section to the current item add/edit form via the "+" menu.
|
||||
/// This clicks the add field button and selects the specified option.
|
||||
/// </summary>
|
||||
/// <param name="fieldName">The name of the field/section to add (e.g., "Attachments", "Two-Factor Authentication").</param>
|
||||
/// <returns>Async task.</returns>
|
||||
protected async Task AddFieldSectionAsync(string fieldName)
|
||||
{
|
||||
var addFieldButton = Page.Locator("button.w-full.border-dashed").First;
|
||||
await addFieldButton.ClickAsync();
|
||||
var fieldOption = Page.Locator($"button:has-text('{fieldName}')").First;
|
||||
await fieldOption.ClickAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Login (again) as current user.
|
||||
/// </summary>
|
||||
|
||||
@@ -174,7 +174,7 @@ public abstract class PlaywrightTest
|
||||
.First
|
||||
.WaitForAsync(new LocatorWaitForOptions
|
||||
{
|
||||
Timeout = 20000,
|
||||
Timeout = TestDefaults.DefaultTimeout,
|
||||
State = WaitForSelectorState.Attached,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,12 +56,13 @@ public class AuthTests : ClientPlaywrightTest
|
||||
await Logout();
|
||||
await Login();
|
||||
|
||||
// Wait for the index page to load which should show "Credentials" in the top menu.
|
||||
await WaitForUrlAsync("**", "Credentials");
|
||||
// Wait for the page to load after login. After registration without completing the tutorial,
|
||||
// the welcome screen will be shown. Otherwise the items page is shown.
|
||||
await WaitForUrlAsync("**", WelcomeMessage);
|
||||
|
||||
// Check if the login was successful by verifying content.
|
||||
var pageContent = await Page.TextContentAsync("body");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No index content after logging in.");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No welcome/index content after logging in.");
|
||||
|
||||
// Check if login has created an auth log entry.
|
||||
var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Login);
|
||||
@@ -119,12 +120,13 @@ public class AuthTests : ClientPlaywrightTest
|
||||
await Logout();
|
||||
await Login(rememberMe: true);
|
||||
|
||||
// Wait for the index page to load which should show "Credentials" in the top menu.
|
||||
await WaitForUrlAsync("**", "Credentials");
|
||||
// Wait for the page to load after login. After registration without completing the tutorial,
|
||||
// the welcome screen will be shown. Otherwise the items page is shown.
|
||||
await WaitForUrlAsync("**", WelcomeMessage);
|
||||
|
||||
// Check if the login was successful by verifying content.
|
||||
var pageContent = await Page.TextContentAsync("body");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No index content after logging in.");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No welcome/index content after logging in.");
|
||||
|
||||
// Check if login has created an auth log entry.
|
||||
var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Login);
|
||||
@@ -219,10 +221,10 @@ public class AuthTests : ClientPlaywrightTest
|
||||
|
||||
// Verify we can log in with the new account
|
||||
await Login();
|
||||
await WaitForUrlAsync("**", "Credentials");
|
||||
await WaitForUrlAsync("**", WelcomeMessage);
|
||||
|
||||
var pageContent = await Page.TextContentAsync("body");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No welcome message shown after re-registering deleted account.");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No welcome/index content shown after re-registering deleted account.");
|
||||
|
||||
// Verify that a new auth log entry was created for the registration
|
||||
var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Register);
|
||||
@@ -299,12 +301,13 @@ public class AuthTests : ClientPlaywrightTest
|
||||
/// <returns>Async task.</returns>
|
||||
private async Task VerifySuccessfulLogin()
|
||||
{
|
||||
// Wait for the index page to load which should show "Credentials" in the top menu.
|
||||
await WaitForUrlAsync("**", "Credentials");
|
||||
// Wait for the page to load after login. After registration without completing the tutorial,
|
||||
// the welcome screen will be shown. Otherwise the items page is shown.
|
||||
await WaitForUrlAsync("**", WelcomeMessage);
|
||||
|
||||
// Check if the login was successful by verifying content.
|
||||
var pageContent = await Page.TextContentAsync("body");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No index content after logging in.");
|
||||
Assert.That(pageContent, Does.Contain(WelcomeMessage), "No welcome/index content after logging in.");
|
||||
|
||||
// Check if login has created an auth log entry and it contains the expected client header value.
|
||||
var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.EventType == AuthEventType.Login);
|
||||
|
||||
@@ -32,6 +32,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
},
|
||||
async () =>
|
||||
{
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
// Upload file.
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
@@ -90,6 +96,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
},
|
||||
async () =>
|
||||
{
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
// Upload file.
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
@@ -161,6 +173,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
},
|
||||
async () =>
|
||||
{
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
// Upload file.
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
@@ -222,6 +240,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
},
|
||||
async () =>
|
||||
{
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
|
||||
@@ -285,6 +309,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
await Page.ClickAsync("text=Edit");
|
||||
await WaitForUrlAsync("items/**/edit", "Edit the existing item");
|
||||
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
var attachmentNames = new[] { "Attachment1.txt", "Attachment2.txt", "Attachment3.txt" };
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
@@ -352,6 +382,12 @@ public class AttachmentTests : ClientPlaywrightTest
|
||||
},
|
||||
async () =>
|
||||
{
|
||||
// Add the attachments section via the + menu
|
||||
await AddFieldSectionAsync("Attachments");
|
||||
|
||||
// Wait for the file input to appear
|
||||
await Page.WaitForSelectorAsync("input[type='file']");
|
||||
|
||||
var fileInput = Page.Locator("input[type='file']");
|
||||
var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ public class UserBlockedTests : ClientPlaywrightTest
|
||||
await Logout();
|
||||
await Login();
|
||||
|
||||
// Wait for the index page to load which should show "Credentials" in the top menu.
|
||||
await WaitForUrlAsync("**", "Credentials");
|
||||
// Wait for the page to load after login.
|
||||
await WaitForUrlAsync("**", WelcomeMessage);
|
||||
|
||||
// First navigate to a test page to verify we're logged in
|
||||
await NavigateUsingBlazorRouter("test/1");
|
||||
|
||||
Reference in New Issue
Block a user