Files
loft/frontend/e2e/auth.e2e.ts
2026-06-04 21:55:10 +03:00

48 lines
1.9 KiB
TypeScript

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();
});