import { test, expect } from '@chromatic-com/playwright'; import { loginViaAPI, navigateTo, CONFIG } from '../helpers'; import { TEST_USERS } from '../design-tokens'; test.describe('FONCTIONNEL — Intégrité des données', () => { test('API /auth/me retourne les données du user connecté', async ({ page }) => { await loginViaAPI(page, TEST_USERS.listener.email, TEST_USERS.listener.password); const response = await page.request.get(CONFIG.baseURL + '/api/v1/auth/me'); expect(response.ok(), `GET /auth/me a retourné ${response.status()}`).toBe(true); const body = await response.json(); const user = body?.data || body; expect(user).toHaveProperty('email'); expect(user.email).toBe(TEST_USERS.listener.email); }); test('Pages error 404 et 500 se chargent correctement', async ({ page }) => { await page.goto(CONFIG.baseURL + '/404', { waitUntil: 'domcontentloaded' }); await page.waitForLoadState('networkidle').catch(() => {}); const body404 = await page.textContent('body'); expect(body404).toMatch(/404|not found|page introuvable|n'existe pas/i); await page.goto(CONFIG.baseURL + '/500', { waitUntil: 'domcontentloaded' }); await page.waitForLoadState('networkidle').catch(() => {}); const body500 = await page.textContent('body'); expect(body500).toMatch(/500|server error|erreur serveur|problème/i); }); test('Route inexistante redirige vers 404', async ({ page }) => { await page.goto(CONFIG.baseURL + '/this-page-does-not-exist-at-all', { waitUntil: 'domcontentloaded' }); await page.waitForLoadState('networkidle').catch(() => {}); await page.waitForTimeout(3_000); expect(page.url()).toContain('/404'); }); test('Le sidebar affiche les liens de navigation', async ({ page }) => { await loginViaAPI(page, TEST_USERS.listener.email, TEST_USERS.listener.password); await navigateTo(page, '/dashboard'); const sidebar = page.locator('[data-testid="app-sidebar"]'); // Le sidebar peut être caché sur mobile, vérifier sur desktop viewport if (await sidebar.isVisible({ timeout: 5_000 }).catch(() => false)) { const links = await sidebar.locator('a[href], [role="link"]').count(); expect(links, 'Le sidebar devrait avoir au moins 3 liens de navigation').toBeGreaterThanOrEqual(3); } }); test('La recherche retourne des résultats cohérents', async ({ page }) => { await loginViaAPI(page, TEST_USERS.listener.email, TEST_USERS.listener.password); await navigateTo(page, '/search'); const searchInput = page.locator('[data-testid="search-input"], input[type="search"], input[role="searchbox"]').first(); if (await searchInput.isVisible({ timeout: 5_000 }).catch(() => false)) { await searchInput.fill('test'); await page.waitForTimeout(2_000); // La page ne devrait pas crasher après une recherche const body = await page.textContent('body'); expect(body).not.toMatch(/500|Internal Server Error/i); } }); });