Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add E2E test for global search bar (#158)

Leendert de Borst42fc1c018c98
diff --git a/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor b/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor
index 3ee5c5209..b48490cc8 100644
--- a/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor
+++ b/src/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor
@@ -4,7 +4,7 @@
@inject JsInteropService JsInteropService
@implements IAsyncDisposable
-<div class="relative">
+<div class="relative" id="searchWidgetContainer">
<input
id="searchWidget"
type="text"
@@ -44,7 +44,7 @@
{
var result = SearchResults[i];
<div
- class="@(i == SelectedIndex ? "bg-gray-100 dark:bg-gray-700" : "") px-4 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700"
+ class="search-result @(i == SelectedIndex ? "bg-gray-100 dark:bg-gray-700" : "") px-4 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700"
@onclick="() => SelectResult(result)">
@result.Service.Name <span class="text-gray-500">(@result.Alias.Email)</span>
</div>
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/SearchTest.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/SearchTest.cs
new file mode 100644
index 000000000..79f3899d9
--- /dev/null
+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/SearchTest.cs
@@ -0,0 +1,68 @@
+//-----------------------------------------------------------------------
+// <copyright file="SearchTest.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.Tests.Client;
+
+/// <summary>
+/// End-to-end tests for searching.
+/// </summary>
+[TestFixture]
+[Category("ClientTests")]
+[Parallelizable(ParallelScope.Self)]
+public class SearchTest : ClientPlaywrightTest
+{
+ /// <summary>
+ /// Test if the global search bar works.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task GlobalSearchBarTest()
+ {
+ // Create two credentials
+ var serviceName1 = "Test Service 1";
+ var serviceName2 = "Test Service 2";
+ var serviceName3 = "Entirely different name";
+ await CreateCredentialEntry(new Dictionary<string, string>
+ {
+ { "service-name", serviceName1 },
+ });
+ await CreateCredentialEntry(new Dictionary<string, string>
+ {
+ { "service-name", serviceName2 },
+ });
+ await CreateCredentialEntry(new Dictionary<string, string>
+ {
+ { "service-name", serviceName3 },
+ });
+
+ // Focus the "searchWidget" id element if it exists
+ var searchWidget = Page.Locator("#searchWidget");
+ if (await searchWidget.IsVisibleAsync())
+ {
+ await searchWidget.FocusAsync();
+ }
+ else
+ {
+ Assert.Fail("Search widget not found or not visible");
+ }
+
+ // Type in the search bar "Test Service"
+ await searchWidget.FillAsync("Test Service");
+
+ // We expect both test services names to appear on the page inside the div with id "searchWidgetContainer"
+ var searchResults = Page.Locator("#searchWidgetContainer .search-result");
+
+ // Wait for the search results to appear
+ Assert.That(await searchResults.CountAsync(), Is.EqualTo(2));
+
+ // Verify that test service 1 and 2 appear in results, 3 does not.
+ var resultTexts = await searchResults.AllInnerTextsAsync();
+ Assert.That(resultTexts, Has.Some.Contains(serviceName1));
+ Assert.That(resultTexts, Has.Some.Contains(serviceName2));
+ Assert.That(resultTexts, Has.Some.Not.Contains(serviceName3));
+ }
+}