Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Fix browser extension tests (#2305)
Leendert de Borstbe67337b65e8
diff --git a/apps/browser-extension/tests/e2e/09-save-login-prompt.spec.ts b/apps/browser-extension/tests/e2e/09-save-login-prompt.spec.tsindex e3878b052..f45a3d115 100644--- a/apps/browser-extension/tests/e2e/09-save-login-prompt.spec.ts+++ b/apps/browser-extension/tests/e2e/09-save-login-prompt.spec.ts@@ -134,6 +134,41 @@ async function fillServiceName(page: Page, serviceName: string): Promise<void> {}, serviceName);}+/**+ * Helper to check if the autofill credential popup is open.+ * Requires E2E test mode (open shadow DOM); reports false when the shadow root is closed.+ */+async function isAutofillPopupOpen(page: Page): Promise<boolean> {+ return page.evaluate(() => {+ const ui = document.querySelector('aliasvault-ui');+ return ui?.shadowRoot?.querySelector('#aliasvault-credential-popup') != null;+ });+}++/**+ * Helper to dismiss the autofill credential popup, which is anchored under the password field and+ * covers the submit button while it is open.+ *+ * Focusing an input opens the popup asynchronously, so a single outside click can land before the+ * popup exists: its outside-click handler then finds nothing to close and the popup shows up right+ * afterwards. Click outside until it is gone and stays gone.+ */+async function dismissAutofillPopup(page: Page, timeout: number = 10000): Promise<void> {+ const deadline = Date.now() + timeout;+ while (Date.now() < deadline) {+ // Click on the form title, which sits safely above the input fields.+ await page.click('h1');++ // Give any in-flight popup open time to land before concluding it is dismissed.+ await page.waitForTimeout(300);+ if (!await isAutofillPopupOpen(page)) {+ return;+ }+ }++ throw new Error(`Autofill popup stayed open after ${timeout}ms and would block the submit button`);+}+/*** Helper to submit the login form on the test page.* Waits for the content script to initialize before filling and submitting.@@ -145,10 +180,8 @@ async function submitLoginForm(page: Page, username: string, password: string):await page.fill('input#username', username);await page.fill('input#password', password);- // Click outside the form fields to dismiss any autofill popup that might be blocking the submit button- // We click on the form title which is safely above the input fields- await page.click('h1');- await page.waitForTimeout(200);+ // Dismiss the autofill popup so it cannot swallow the click meant for the submit button.+ await dismissAutofillPopup(page);// Click the submit button - this triggers the LoginDetector's button click handlerawait page.click('button[type="submit"]');diff --git a/apps/browser-extension/tests/fixtures/TestClient.ts b/apps/browser-extension/tests/fixtures/TestClient.tsindex e758b3b61..5a29df17a 100644--- a/apps/browser-extension/tests/fixtures/TestClient.ts+++ b/apps/browser-extension/tests/fixtures/TestClient.ts@@ -25,6 +25,7 @@ import {waitForUnlockPage,waitForOfflineIndicator,waitForLoginForm,+ waitForPopupReady,Timeouts,} from './waits';@@ -70,10 +71,7 @@ export class TestClient {// Open popupconst popup = await context.newPage();await popup.goto(`chrome-extension://${extensionId}/popup.html`);- await popup.waitForSelector('input[type="text"], input[type="password"], button#settings', {- state: 'visible',- timeout: Timeouts.MEDIUM,- });+ await waitForPopupReady(popup, Timeouts.MEDIUM);return new TestClient(context, extensionId, popup);}@@ -84,10 +82,7 @@ export class TestClient {static async fromContext(context: BrowserContext, extensionId: string): Promise<TestClient> {const popup = await context.newPage();await popup.goto(`chrome-extension://${extensionId}/popup.html`);- await popup.waitForSelector('input[type="text"], input[type="password"], button#settings', {- state: 'visible',- timeout: Timeouts.MEDIUM,- });+ await waitForPopupReady(popup, Timeouts.MEDIUM);return new TestClient(context, extensionId, popup);}@@ -96,8 +91,11 @@ export class TestClient {* Verifies the URL is displayed on the login page after configuration.*/async configureApiUrl(apiUrl: string): Promise<this> {- const settingsButton = await this.popup.waitForSelector('button#settings');- await settingsButton.click();+ // Make sure the popup has settled on the login page before touching the header.+ await waitForPopupReady(this.popup);++ // Use a locator so the button is re-resolved if the app re-renders mid-click.+ await this.popup.locator('button#settings').click();await this.popup.selectOption('select', ['custom']);await this.popup.fill('input#custom-api-url', apiUrl);await this.popup.click('button#back');@@ -118,6 +116,7 @@ export class TestClient {* Open the login settings page (before authentication).*/async openLoginSettings(): Promise<this> {+ await waitForPopupReady(this.popup);const settingsButton = this.popup.locator('button#settings');await settingsButton.click();await expect(this.popup.locator('select')).toBeVisible();diff --git a/apps/browser-extension/tests/fixtures/fixtures.ts b/apps/browser-extension/tests/fixtures/fixtures.tsindex 0bae84782..ee854e8fc 100644--- a/apps/browser-extension/tests/fixtures/fixtures.ts+++ b/apps/browser-extension/tests/fixtures/fixtures.ts@@ -4,6 +4,8 @@ import { fileURLToPath } from 'url';import { createTestUser, type TestUser } from '../helpers/test-api';+import { waitForPopupReady as waitForPopupReadyState, Timeouts } from './waits';+const __filename = fileURLToPath(import.meta.url);const __dirname = path.dirname(__filename);@@ -126,20 +128,13 @@ export async function closeCachedContext(): Promise<void> {* Helper to wait for the popup to finish initial loading.** The popup shows a loading spinner overlay (with z-50) during initial load.- * This function waits for actual content to be visible, indicating loading is complete.+ * This function waits for that overlay to disappear and for actual content to be visible.** @param popup - The popup page* @param timeout - Maximum time to wait in milliseconds (default: 10000)*/-export async function waitForPopupReady(popup: Page, timeout: number = 10000): Promise<void> {- // Wait for the loading overlay to disappear by waiting for actual content to be interactable.- // The login form has input fields that only become visible after loading completes.- // We wait for either the login form inputs OR the settings button (visible on login page).- // Using CSS-only selectors to avoid mixing with Playwright-specific selectors.- await popup.waitForSelector(- 'input[type="text"], input[type="password"], button#settings',- { state: 'visible', timeout }- );+export async function waitForPopupReady(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {+ await waitForPopupReadyState(popup, timeout);}/**@@ -184,9 +179,11 @@ export async function waitForLoggedIn(popup: Page, timeout: number = 30000): Pro* @param apiUrl - The API URL to configure*/export async function configureApiUrl(popup: Page, apiUrl: string): Promise<void> {- // Click settings button- const settingsButton = await popup.waitForSelector('button#settings');- await settingsButton.click();+ // Make sure the popup has settled on the login page before touching the header.+ await waitForPopupReady(popup);++ // Click settings button. Use a locator so it is re-resolved if the app re-renders mid-click.+ await popup.locator('button#settings').click();// Select "Self-hosted" (custom) optionawait popup.selectOption('select', ['custom']);diff --git a/apps/browser-extension/tests/fixtures/waits.ts b/apps/browser-extension/tests/fixtures/waits.tsindex eeea15a69..eb24b7d61 100644--- a/apps/browser-extension/tests/fixtures/waits.ts+++ b/apps/browser-extension/tests/fixtures/waits.ts@@ -4,9 +4,8 @@* This module provides condition-based waiting functions that replace* fixed timeouts with intelligent waits for specific UI states.*/-import type { Page, Locator } from '@playwright/test';+import { expect, type Page, type Locator } from '@playwright/test';-import { expect } from './fixtures';import { FieldSelectors } from './selectors';/**@@ -18,6 +17,12 @@ export const Timeouts = {LONG: 30000,} as const;+/**+ * Full-screen overlays the popup renders while it is busy: the initial load overlay in App.tsx+ * and the shared LoadingSpinnerFullScreen. Both cover the whole popup and swallow clicks.+ */+const LOADING_OVERLAY = 'div.fixed.inset-0.z-50';+/*** Generic wait helper that waits for a locator to be visible.* This is the building block for more specific wait functions.@@ -39,6 +44,35 @@ export async function waitForHidden(locator: Locator, timeout: number = Timeoutsawait locator.waitFor({ state: 'hidden', timeout });}+/**+ * Wait for the full-screen loading overlay to disappear.+ *+ * @param popup - The popup page+ * @param timeout - Timeout in milliseconds+ */+export async function waitForLoadingOverlayGone(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {+ await popup.locator(LOADING_OVERLAY).first().waitFor({ state: 'detached', timeout });+}++/**+ * Wait for the popup to finish its initial load and settle on its destination page.+ *+ * The popup boots on `/`, hops through `/reinitialize` and only then lands on `/login`, `/unlock`+ * or the vault. The loading overlay stays up across that whole hop, so waiting only for content to+ * be visible returns while the app is still routing: the click then lands on the overlay, and the+ * layout swap that follows replaces the header, detaching anything the test grabbed beforehand.+ * Waiting for the overlay first guarantees the destination page is mounted before we touch it.+ *+ * @param popup - The popup page+ * @param timeout - Timeout in milliseconds+ */+export async function waitForPopupReady(popup: Page, timeout: number = Timeouts.MEDIUM): Promise<void> {+ await waitForLoadingOverlayGone(popup, timeout);++ // Auth form inputs (login/unlock) or the settings button (login page header) indicate content is interactable.+ await popup.locator('input[type="text"], input[type="password"], button#settings').first().waitFor({ state: 'visible', timeout });+}+/*** Wait for text to appear on the page.*