mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-02 05:46:39 -05:00
Code style refactor (#11)
This commit is contained in:
@@ -56,7 +56,7 @@ public class AliasTests : PlaywrightTest
|
||||
public async Task AliasListingCorrect()
|
||||
{
|
||||
await Page.GotoAsync(AppBaseUrl + "aliases");
|
||||
await Page.WaitForURLAsync("**/aliases", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync("**/aliases");
|
||||
|
||||
// Wait for the content to load.
|
||||
await Page.WaitForSelectorAsync("text=AliasVault");
|
||||
@@ -74,7 +74,7 @@ public class AliasTests : PlaywrightTest
|
||||
public async Task CreateAlias()
|
||||
{
|
||||
await Page.GotoAsync(AppBaseUrl + "add-alias");
|
||||
await Page.WaitForURLAsync("**/add-alias", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync("**/add-alias");
|
||||
|
||||
// Wait for the content to load.
|
||||
await Page.WaitForSelectorAsync("text=AliasVault");
|
||||
@@ -89,11 +89,7 @@ public class AliasTests : PlaywrightTest
|
||||
// Press submit button with text "Create Alias"
|
||||
var submitButton = Page.Locator("text=Save Alias").First;
|
||||
await submitButton.ClickAsync();
|
||||
await Page.WaitForURLAsync("**/alias/**", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
|
||||
// Check if the redirection occurred
|
||||
var currentUrl = Page.Url;
|
||||
Assert.That(currentUrl, Does.Contain(AppBaseUrl + "alias/"));
|
||||
await WaitForURLAsync("**/alias/**");
|
||||
|
||||
// Wait for the content to load.
|
||||
await Page.WaitForSelectorAsync("text=Login credentials");
|
||||
|
||||
@@ -46,7 +46,7 @@ public class AuthTests : PlaywrightTest
|
||||
|
||||
// Check that we are on the login page after navigating to the base URL.
|
||||
// We are expecting to not be authenticated and thus to be redirected to the login page.
|
||||
await Page.WaitForURLAsync("**/user/login", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync("**/user/login");
|
||||
|
||||
// Try to login with test credentials.
|
||||
var emailField = Page.Locator("input[id='email']");
|
||||
@@ -57,7 +57,7 @@ public class AuthTests : PlaywrightTest
|
||||
// Check if we get redirected when clicking on the login button.
|
||||
var loginButton = Page.Locator("button[type='submit']");
|
||||
await loginButton.ClickAsync();
|
||||
await Page.WaitForURLAsync(AppBaseUrl, new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync(AppBaseUrl);
|
||||
|
||||
// Check if the login was successful by verifying content.
|
||||
var pageContent = await Page.TextContentAsync("body");
|
||||
|
||||
@@ -117,6 +117,16 @@ public class PlaywrightTest
|
||||
_blazorWasmAppManager.StopBlazorWasm();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for the specified URL to be loaded with a default timeout.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to wait for. This may also contains wildcard such as "**/user/login".</param>
|
||||
/// <returns>Async task.</returns>
|
||||
protected async Task WaitForURLAsync(string url)
|
||||
{
|
||||
await Page.WaitForURLAsync(url, new PageWaitForURLOptions() { Timeout = TestDefaults.DefaultTimeout });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register a new random account.
|
||||
/// </summary>
|
||||
@@ -129,12 +139,12 @@ public class PlaywrightTest
|
||||
|
||||
// Check that we get redirected to /user/login when accessing the root URL and not authenticated.
|
||||
await Page.GotoAsync(AppBaseUrl);
|
||||
await Page.WaitForURLAsync("**/user/login", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync("**/user/login");
|
||||
|
||||
// Try to register a new account.
|
||||
var registerButton = Page.Locator("a[href='/user/register']");
|
||||
await registerButton.ClickAsync();
|
||||
await Page.WaitForURLAsync("**/user/register", new PageWaitForURLOptions() { Timeout = 2000 });
|
||||
await WaitForURLAsync("**/user/register");
|
||||
|
||||
// Try to login with test credentials.
|
||||
var emailField = Page.Locator("input[id='email']");
|
||||
@@ -153,6 +163,6 @@ public class PlaywrightTest
|
||||
await submitButton.ClickAsync();
|
||||
|
||||
// Check if we get redirected to the root URL after registration which means we are logged in.
|
||||
await Page.WaitForURLAsync(AppBaseUrl, new PageWaitForURLOptions() { Timeout = 5000 });
|
||||
await WaitForURLAsync(AppBaseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
19
src/Tests/AliasVault.E2ETests/Common/TestDefaults.cs
Normal file
19
src/Tests/AliasVault.E2ETests/Common/TestDefaults.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="TestDefaults.cs" company="lanedirt">
|
||||
// Copyright (c) lanedirt. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
// </copyright>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
namespace AliasVault.E2ETests.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Default values for tests.
|
||||
/// </summary>
|
||||
public static class TestDefaults
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets default timeout while waiting for pages to load in milliseconds.
|
||||
/// </summary>
|
||||
public static int DefaultTimeout { get; set; } = 5000;
|
||||
}
|
||||
Reference in New Issue
Block a user