veza/tests/e2e/audit/functional/01-auth.spec.ts
senke 463ad5386b test: update e2e test suite and add audit tests
Refine auth, player, tracks, playlists, search, workflows, edge cases,
forms, responsive, network errors, error boundary, performance, visual
regression, cross-browser, profile, smoke, storybook, chat, and session
tests. Add audit test suite (accessibility, ethical, functional, design
tokens). Update test helpers and visual snapshots.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:06:26 +01:00

76 lines
3.7 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { loginViaUI, loginViaAPI, navigateTo, CONFIG } from '../helpers';
import { TEST_USERS, ROUTES } from '../design-tokens';
test.describe('FONCTIONNEL — Authentification', () => {
test('Login avec compte listener — redirige vers /dashboard', async ({ page }) => {
await loginViaUI(page, TEST_USERS.listener.email, TEST_USERS.listener.password);
await expect(page).toHaveURL(/\/(dashboard|feed|discover)/, { timeout: 15_000 });
});
test('Login avec compte creator — redirige vers /dashboard', async ({ page }) => {
await loginViaUI(page, TEST_USERS.creator.email, TEST_USERS.creator.password);
await expect(page).toHaveURL(/\/(dashboard|feed|discover)/, { timeout: 15_000 });
});
test('Login avec compte admin — redirige vers /dashboard', async ({ page }) => {
await loginViaUI(page, TEST_USERS.admin.email, TEST_USERS.admin.password);
await expect(page).toHaveURL(/\/(dashboard|feed|discover)/, { timeout: 15_000 });
});
test('Login avec identifiants invalides — affiche erreur', async ({ page }) => {
await page.goto('/login', { waitUntil: 'domcontentloaded' });
await page.waitForLoadState('networkidle').catch(() => {});
await page.locator('main, [role="main"]').first().waitFor({ state: 'visible', timeout: 15_000 }).catch(() => {});
const emailInput = page.locator('input[type="email"]');
await emailInput.waitFor({ state: 'visible', timeout: 10_000 });
await emailInput.fill('wrong@wrong.com');
await page.locator('input[type="password"]').fill('WrongPassword123!');
await page.getByTestId('login-submit').click();
// Doit rester sur /login avec un message d'erreur
await page.waitForTimeout(3_000);
expect(page.url()).toContain('/login');
const body = await page.textContent('body');
expect(body).toMatch(/error|erreur|invalid|incorrect|identifiants/i);
});
test('Page register se charge sans erreur', async ({ page }) => {
await navigateTo(page, '/register');
const form = page.getByTestId('register-form').or(page.locator('form'));
await expect(form.first()).toBeVisible({ timeout: 10_000 });
// Vérifier les champs requis
await expect(page.locator('input[type="email"]')).toBeVisible();
await expect(page.locator('input[type="password"]').first()).toBeVisible();
});
test('Logout — redirige vers /login', async ({ page }) => {
await loginViaAPI(page, TEST_USERS.listener.email, TEST_USERS.listener.password);
// Chercher le bouton logout (dans la sidebar ou les settings)
const logoutBtn = page.getByRole('button', { name: /logout|déconnexion|se déconnecter/i }).first()
.or(page.locator('[data-testid="logout-button"]').first())
.or(page.locator('button[aria-label*="logout" i]').first());
if (await logoutBtn.isVisible({ timeout: 5_000 }).catch(() => false)) {
await logoutBtn.click();
await page.waitForURL(/\/login/, { timeout: 15_000 }).catch(() => {});
}
// Si le bouton n'est pas visible directement, ce n'est pas une erreur critique
});
test('Routes protégées redirigent vers /login si non-authentifié', async ({ page }) => {
for (const route of ['/dashboard', '/library', '/settings']) {
await page.goto(route, { waitUntil: 'domcontentloaded' });
await page.waitForLoadState('networkidle').catch(() => {});
await page.waitForTimeout(3_000);
expect(page.url(), `${route} devrait rediriger vers /login`).toContain('/login');
}
});
test('Forgot password page se charge', async ({ page }) => {
await navigateTo(page, '/forgot-password');
await expect(page.locator('input[type="email"]')).toBeVisible({ timeout: 10_000 });
});
});