Files
caddy-proxy-manager/tests/e2e/link-account.spec.ts
fuomag9 2f12475ab0 Fix E2E test locator ambiguity and lint errors
- dashboard.spec.ts: anchor regex /^\d+\s+Proxy Hosts/ to not match
  "L4 Proxy Hosts" sidebar link
- role-access.spec.ts: use exact: true for "Proxy Hosts" link
- users.spec.ts: match any user count (/\d+ users?/) since other test
  suites create additional users
- groups.spec.ts: remove unused emptyText variable
- link-account.spec.ts: remove unused context parameter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 09:59:11 +02:00

41 lines
1.7 KiB
TypeScript

/**
* E2E tests: Link Account page (/link-account).
*
* This page requires a valid LINKING_REQUIRED: error param with a valid JWT linking token.
* Without that, it redirects to /login. We test the redirect behavior and the fallback
* "Sign in with Password Instead" button.
*/
import { test, expect } from '@playwright/test';
test.use({ storageState: { cookies: [], origins: [] } });
test.describe('Link Account page', () => {
test('redirects to /login when no error param is provided', async ({ page }) => {
await page.goto('/link-account');
await expect(page).toHaveURL(/\/login/, { timeout: 10_000 });
});
test('redirects to /login with invalid linking token', async ({ page }) => {
await page.goto('/link-account?error=LINKING_REQUIRED:invalid-token');
await expect(page).toHaveURL(/\/login/, { timeout: 10_000 });
});
test('redirects to /login when error param is not LINKING_REQUIRED', async ({ page }) => {
await page.goto('/link-account?error=SomeOtherError');
await expect(page).toHaveURL(/\/login/, { timeout: 10_000 });
});
test('redirects authenticated users to /', async ({ page }) => {
// First log in
await page.goto('http://localhost:3000/login');
await page.getByRole('textbox', { name: /username/i }).fill('testadmin');
await page.getByRole('textbox', { name: /password/i }).fill('TestPassword2026!');
await page.getByRole('button', { name: /sign in/i }).click();
await expect(page).not.toHaveURL(/\/login/, { timeout: 10_000 });
// Now visit link-account — should redirect to /
await page.goto('/link-account?error=LINKING_REQUIRED:some-token');
await expect(page).toHaveURL(/^\/$|\/(?!link-account)/, { timeout: 10_000 });
});
});