test(frontend): add real-auth Playwright e2e suite

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 21:55:10 +03:00
parent 0ef7728ac0
commit d2f044db07
5 changed files with 182 additions and 4 deletions

47
frontend/e2e/auth.e2e.ts Normal file
View File

@@ -0,0 +1,47 @@
import { test, expect } from '@playwright/test';
import { uniqueUser, registerAndLogin } from './helpers';
test('registering via the form creates an account', async ({ page }) => {
const user = uniqueUser();
await page.goto('/auth');
await page.getByTestId('auth-tab-register').click();
await page.locator('#username').fill(user.username);
await page.locator('#password').fill(user.password);
const register = page.waitForResponse((r) => r.url().includes('/api/auth/register'));
await page.getByTestId('auth-submit').click();
expect((await register).status()).toBe(201);
});
test('logging in via the form reaches the app', async ({ page }) => {
const user = uniqueUser();
// pre-create the account, then exercise the login form (single clean navigation)
const reg = await page.request.post('/api/auth/register', { data: user });
expect(reg.ok()).toBeTruthy();
await page.goto('/auth');
await page.locator('#username').fill(user.username);
await page.locator('#password').fill(user.password);
await page.getByTestId('auth-submit').click();
await expect(page.getByRole('button', { name: 'Import' })).toBeVisible();
});
test('login with wrong credentials shows an error', async ({ page }) => {
await page.goto('/auth');
await page.locator('#username').fill('nope_does_not_exist');
await page.locator('#password').fill('wrongpassword');
await page.getByTestId('auth-submit').click();
await expect(page.getByText('Invalid credentials')).toBeVisible();
});
test('signing out returns to the auth page', async ({ page }) => {
await registerAndLogin(page);
await page.goto('/');
await expect(page.getByRole('button', { name: 'Import' })).toBeVisible();
await page.getByRole('button', { name: 'Sign out' }).click();
await expect(page).toHaveURL(/\/auth$/);
await expect(page.getByTestId('auth-tab-login')).toBeVisible();
});