Skip to content

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

Update web app tests (#2413)

Leendert de Borst3c57f9eed787
diff --git a/apps/web/playwright.config.ts b/apps/web/playwright.config.ts
index ca8fa7233..d30b38313 100644
--- a/apps/web/playwright.config.ts
+++ b/apps/web/playwright.config.ts
@@ -22,11 +22,12 @@ export default defineConfig({
// Checks the API is reachable and applies the test server settings.
globalSetup: './tests/global-setup.ts',
- // Tests within a file run in order; files run in parallel, as every test registers its own account.
- fullyParallel: false,
+ // Every test registers its own account, so all tests run in parallel, also within a file except
+ // when a test file is marked as serial explicitly.
+ fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
- workers: process.env.CI ? 1 : 4,
+ workers: process.env.CI ? 4 : '100%',
reporter: [
['html', { open: 'never' }],
diff --git a/apps/web/src/context/AuthContext.tsx b/apps/web/src/context/AuthContext.tsx
index ceca2bbd2..37bde0588 100644
--- a/apps/web/src/context/AuthContext.tsx
+++ b/apps/web/src/context/AuthContext.tsx
@@ -5,7 +5,8 @@ import { useTranslation } from 'react-i18next';
import { useDb } from '@/context/DbContext';
import { useWebApi } from '@/context/WebApiContext';
-import { StorageKeys } from '@/utils/StorageKeys';
+import { removeLocalPreference } from '@/utils/LocalPreferences';
+import { LocalPreferenceKeys, StorageKeys } from '@/utils/StorageKeys';
import { vaultStore } from '@/vault/VaultStore';
/**
@@ -101,6 +102,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
}
if (options.userInitiated) {
await vaultStore.clearVaultData();
+ removeLocalPreference(LocalPreferenceKeys.RETURN_URL);
setUsername(null);
}
await vaultStore.clearSession();
diff --git a/apps/web/src/layouts/MainLayout.tsx b/apps/web/src/layouts/MainLayout.tsx
index 30b24171d..c402803f0 100644
--- a/apps/web/src/layouts/MainLayout.tsx
+++ b/apps/web/src/layouts/MainLayout.tsx
@@ -42,13 +42,10 @@ const MainLayout: React.FC = () => {
navigate('/user/start', { replace: true });
return;
}
- if (status.isVaultLocked) {
- navigate('/unlock', { replace: true });
- return;
- }
- if (!dbAvailable) {
+ // Unlock continues via the sync page, which returns to this URL.
+ if (status.isVaultLocked || !dbAvailable) {
setLocalPreference(LocalPreferenceKeys.RETURN_URL, location.pathname + location.search);
- navigate('/sync', { replace: true });
+ navigate(status.isVaultLocked ? '/unlock' : '/sync', { replace: true });
return;
}
setIsReady(true);
diff --git a/apps/web/tests/e2e/02-authentication.spec.ts b/apps/web/tests/e2e/02-authentication.spec.ts
index 133a59b66..23e3c4d6c 100644
--- a/apps/web/tests/e2e/02-authentication.spec.ts
+++ b/apps/web/tests/e2e/02-authentication.spec.ts
@@ -29,4 +29,23 @@ test.describe('2. Authentication', () => {
await expect(app.page.getByText('Invalid username or password')).toBeVisible();
await expect(app.page).toHaveURL(/\/user\/login$/);
});
+
+ test('2.3 should return to the open page after unlocking a reloaded vault', async ({ app, testUser }) => {
+ const { page } = app;
+ await app.login(testUser.username, testUser.password);
+ await app.createItem('Return after unlock');
+ const itemUrl = page.url();
+
+ await test.step('reloading locks the vault', async () => {
+ await page.reload();
+ await expect(page).toHaveURL(/\/unlock$/);
+ });
+
+ await test.step('unlocking returns to the item', async () => {
+ await page.locator('#password').fill(testUser.password);
+ await page.locator('#unlock-button').click();
+ await expect(page).toHaveURL(itemUrl);
+ await app.expectItemView('Return after unlock');
+ });
+ });
});
diff --git a/apps/web/tests/e2e/03-items.spec.ts b/apps/web/tests/e2e/03-items.spec.ts
new file mode 100644
index 000000000..65c4e13ba
--- /dev/null
+++ b/apps/web/tests/e2e/03-items.spec.ts
@@ -0,0 +1,53 @@
+/**
+ * Category 3: Items (requires API)
+ */
+import { test, expect } from '../fixtures';
+
+test.describe('3. Items', () => {
+ test.beforeEach(async ({ app, testUser }) => {
+ await app.login(testUser.username, testUser.password);
+ });
+
+ test('3.1 should create an item', async ({ app }) => {
+ await app.createItem('Test Service');
+
+ await test.step('the item shows in the vault list', async () => {
+ await app.openVault();
+ await expect(app.page.getByText('Test Service', { exact: true })).toBeVisible();
+ });
+ });
+
+ test('3.2 should edit an item', async ({ app }) => {
+ const { page } = app;
+ await app.createItem('Item service before');
+
+ await test.step('rename the item', async () => {
+ await page.getByRole('link', { name: 'Edit item' }).click();
+ await expect(page).toHaveURL(/\/edit$/);
+ await page.locator('#service-name').fill('Item service after');
+ await app.saveItemButton().click();
+ });
+
+ await test.step('the view page shows the new name', async () => {
+ await expect(page.getByText('Item updated successfully.')).toBeVisible();
+ await app.expectItemView('Item service after');
+ await expect(page.getByText('Item service before')).toHaveCount(0);
+ });
+ });
+
+ test('3.3 should delete an item', async ({ app }) => {
+ const { page } = app;
+ await app.createItem('Item to delete');
+
+ await test.step('delete it via the confirmation dialog', async () => {
+ await page.getByRole('button', { name: 'Delete item' }).click();
+ await page.getByRole('button', { name: 'Yes, I\'m sure' }).click();
+ });
+
+ await test.step('the item is gone from the vault list', async () => {
+ await expect(page).toHaveURL(/\/items$/);
+ await expect(page.getByText('Item successfully deleted.')).toBeVisible();
+ await expect(page.getByText('Item to delete', { exact: true })).toHaveCount(0);
+ });
+ });
+});
diff --git a/apps/web/tests/fixtures/WebApp.ts b/apps/web/tests/fixtures/WebApp.ts
index 15f61e590..26f447a28 100644
--- a/apps/web/tests/fixtures/WebApp.ts
+++ b/apps/web/tests/fixtures/WebApp.ts
@@ -56,7 +56,7 @@ export class WebApp {
}
/**
- * Stop here and open the Playwright Inspector to look at the page, only in a `npm run test:e2e:pause` run; a no-op otherwise.
+ * Stop here and open the Playwright Inspector to look at the page, only in a `npm run test:e2e:p` run; a no-op otherwise.
*/
public async pause(): Promise<void> {
if (!process.env.E2E_PAUSE) {
diff --git a/apps/web/tests/run-e2e.mjs b/apps/web/tests/run-e2e.mjs
index 604b90d88..ad66298c9 100644
--- a/apps/web/tests/run-e2e.mjs
+++ b/apps/web/tests/run-e2e.mjs
@@ -6,7 +6,7 @@
* npm run test:e2e 4.3 test 4.3
* npm run test:e2e 14.1,14.2 3 tests 14.1 and 14.2, plus every test in file 03
* npm run test:e2e 14.1-14.3 tests 14.1 up to and including 14.3
- * npm run test:e2e:pause 4.3 headed, stopping at each app.pause() in the Playwright Inspector
+ * npm run test:e2e:p 4.3 headed, stopping at each app.pause() in the Playwright Inspector
*
* Numbers become one title filter (--grep), so selections combine as "or". Any other argument goes to Playwright as-is.
*/