veza/tests/e2e/13-workflows.spec.ts
senke 3640aec716 test(e2e): convert all remaining 298 console.log to real expect()
Convert 20 files from fake assertions (console.log with ✓/✗) to real
expect() assertions. This completes the conversion started in the
previous session — zero console.log calls remain in the E2E suite.

Files converted (by batch):
Batch 1: 16-forms-validation (38→0), 13-workflows (18→0), 14-edge-cases (8→0)
Batch 2: 15-routes-coverage (8→0), 20-network-errors (5→0), 04-tracks (4→0),
         32-deep-pages (4→0), 19-responsive (3→0), 11-accessibility-ethics (3→0)
Batch 3: 25-profile (2→0), 12-api (2→0), 29-chat-functional (2→0),
         30-marketplace-checkout (1→0), 22-performance (1→0),
         31-auth-sessions (1→0), 26-smoke (1→0), 02-navigation (1→0)
Batch 4: 24-cross-browser (0 fakes, 12 info→0), 34-workflows-empty (0→0),
         33-visual-bugs (0→0)

Total: 139 fake assertions → real expect(), 159 informational logs removed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 15:50:17 +02:00

398 lines
16 KiB
TypeScript

import { test, expect } from '@chromatic-com/playwright';
import { loginViaAPI,
CONFIG,
navigateTo,
assertNoDebugText,
assertNotBroken,
assertPlayerVisible,
playFirstTrack,
SELECTORS,
} from './helpers';
// =============================================================================
// WORKFLOW — Parcours auditeur complet
// =============================================================================
test.describe('WORKFLOW — Parcours auditeur complet', () => {
test('01. Login → discover → play track → favorites → playlist → search → follow → logout @critical', async ({ page }) => {
test.setTimeout(90_000);
// --- Step 1: Login as listener ---
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
await expect(page).not.toHaveURL(/login/, { timeout: CONFIG.timeouts.navigation });
const sidebar = page.getByTestId('app-sidebar');
await expect(sidebar).toBeVisible({ timeout: CONFIG.timeouts.action });
// --- Step 2: Navigate to /discover ---
await navigateTo(page, '/discover');
const discoverContent = page.getByRole('heading', { name: /découvrir|discover|explore/i })
.or(page.locator('main'));
await expect(discoverContent.first()).toBeVisible({ timeout: CONFIG.timeouts.action });
await assertNotBroken(page);
// --- Step 3: Play a track ---
await playFirstTrack(page);
const player = page.getByTestId('global-player');
// Player may not appear if no tracks are seeded — soft check
const playerVisible = await player.isVisible().catch(() => false);
if (playerVisible) {
await expect(player).toBeVisible();
}
// --- Step 4: Try to add to favorites ---
const likeBtn = page.getByRole('button', { name: /ajouter aux favoris|add to favorites/i }).first();
const likeBtnVisible = await likeBtn.isVisible().catch(() => false);
if (likeBtnVisible) {
await likeBtn.click();
const unlikeBtn = page.getByRole('button', { name: /retirer des favoris|remove from favorites/i }).first();
await expect(unlikeBtn).toBeVisible({ timeout: CONFIG.timeouts.action });
}
// --- Step 5: Navigate to playlists and check page loads ---
await navigateTo(page, '/playlists');
await assertNotBroken(page);
// --- Step 6: Search for something ---
await navigateTo(page, '/search');
const searchInput = page.locator('input[role="combobox"][aria-label="Search"]')
.or(page.getByPlaceholder(/search for tracks/i));
const searchVisible = await searchInput.first().isVisible().catch(() => false);
if (searchVisible) {
await searchInput.first().fill('music');
await page.waitForTimeout(1_500);
const body = await page.textContent('body') || '';
expect(body).not.toMatch(/crash|TypeError|500/i);
}
// --- Step 7: Navigate to social / follow ---
await navigateTo(page, '/social');
const socialBody = await page.textContent('body') || '';
expect(socialBody).not.toMatch(/crash|TypeError/i);
// --- Step 8: Logout ---
const userMenu = page.getByTestId('user-menu')
.or(page.getByRole('button', { name: /profil|account|menu/i }).first())
.or(page.locator('[class*="avatar"]').first());
if (await userMenu.isVisible().catch(() => false)) {
await userMenu.click();
}
const logoutBtn = page.getByRole('menuitem', { name: /déconnexion|logout|sign out/i })
.or(page.getByRole('button', { name: /déconnexion|logout|sign out/i }))
.or(page.getByRole('link', { name: /déconnexion|logout|sign out/i }));
const logoutVisible = await logoutBtn.isVisible().catch(() => false);
if (logoutVisible) {
await logoutBtn.click();
await expect(page).toHaveURL(/login|\/$/, { timeout: CONFIG.timeouts.navigation });
}
});
test('02. Dashboard → library → track detail → back to library', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
// Navigate to dashboard
await navigateTo(page, '/dashboard');
await assertNotBroken(page);
await assertNoDebugText(page);
// Navigate to library
await navigateTo(page, '/library');
await assertNotBroken(page);
// Try clicking a track card to go to detail
const trackCard = page.locator('[role="article"]').first();
const trackCardVisible = await trackCard.isVisible().catch(() => false);
test.skip(!trackCardVisible, 'No track cards found in library — skipping detail navigation');
const trackLink = trackCard.locator('a[href*="/tracks/"]').first();
const trackLinkVisible = await trackLink.isVisible().catch(() => false);
test.skip(!trackLinkVisible, 'No track link found in card — skipping detail navigation');
await trackLink.click();
await page.waitForLoadState('networkidle').catch(() => {});
expect(page.url()).toContain('/tracks/');
await assertNotBroken(page);
// Go back
await page.goBack();
await page.waitForLoadState('networkidle').catch(() => {});
await assertNotBroken(page);
});
});
// =============================================================================
// WORKFLOW — Parcours créateur
// =============================================================================
test.describe('WORKFLOW — Parcours créateur', () => {
test('03. Login as creator → library → verify tracks → analytics → sell page @critical', async ({ page }) => {
test.setTimeout(90_000);
// --- Step 1: Login as creator ---
await loginViaAPI(page, CONFIG.users.creator.email, CONFIG.users.creator.password);
await page.waitForTimeout(2_000);
await expect(page).not.toHaveURL(/login/, { timeout: CONFIG.timeouts.navigation });
// --- Step 2: Navigate to library ---
await navigateTo(page, '/library');
await assertNotBroken(page);
// --- Step 3: Verify track cards are present ---
const trackCards = page.locator('[role="article"]');
const trackCount = await trackCards.count();
expect(trackCount).toBeGreaterThanOrEqual(0);
// --- Step 4: Navigate to analytics ---
await navigateTo(page, '/analytics');
const analyticsBody = await page.textContent('body') || '';
expect(analyticsBody).not.toMatch(/crash|TypeError/i);
expect(analyticsBody.length).toBeGreaterThan(50);
// --- Step 5: Navigate to sell page (marketplace) ---
await navigateTo(page, '/sell');
const sellBody = await page.textContent('body') || '';
expect(sellBody).not.toMatch(/crash|TypeError/i);
// --- Step 6: Navigate to profile ---
await navigateTo(page, '/profile');
await assertNotBroken(page);
});
test('04. Creator can access settings and sessions', async ({ page }) => {
test.setTimeout(60_000);
await loginViaAPI(page, CONFIG.users.creator.email, CONFIG.users.creator.password);
// Settings page
await navigateTo(page, '/settings');
await assertNotBroken(page);
await assertNoDebugText(page);
// Sessions page
await navigateTo(page, '/settings/sessions');
const sessionsBody = await page.textContent('body') || '';
expect(sessionsBody).not.toMatch(/crash|TypeError/i);
});
});
// =============================================================================
// WORKFLOW — Parcours admin
// =============================================================================
test.describe('WORKFLOW — Parcours admin', () => {
test('05. Login as admin → admin dashboard → moderation → platform @critical', async ({ page }) => {
test.setTimeout(90_000);
// --- Step 1: Login as admin ---
await loginViaAPI(page, CONFIG.users.admin.email, CONFIG.users.admin.password);
await page.waitForTimeout(2_000);
await expect(page).not.toHaveURL(/login/, { timeout: CONFIG.timeouts.navigation });
// --- Step 2: Navigate to admin dashboard ---
await navigateTo(page, '/admin');
const adminBody = await page.textContent('body') || '';
expect(adminBody).not.toMatch(/crash|TypeError|403|forbidden/i);
expect(adminBody.length).toBeGreaterThan(50);
// --- Step 3: Navigate to moderation ---
await navigateTo(page, '/admin/moderation');
const modBody = await page.textContent('body') || '';
expect(modBody).not.toMatch(/crash|TypeError/i);
// --- Step 4: Navigate to platform settings ---
await navigateTo(page, '/admin/platform');
const platformBody = await page.textContent('body') || '';
expect(platformBody).not.toMatch(/crash|TypeError/i);
// --- Step 5: Verify admin can still access regular pages ---
await navigateTo(page, '/dashboard');
await assertNotBroken(page);
});
test('06. Non-admin cannot access admin pages', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
await navigateTo(page, '/admin');
await page.waitForLoadState('networkidle').catch(() => {});
// Should either redirect away or show forbidden/not found
const url = page.url();
const body = await page.textContent('body') || '';
const isBlocked = url.includes('/login') ||
url.includes('/dashboard') ||
/403|forbidden|not authorized|access denied|not found/i.test(body);
expect(isBlocked).toBe(true);
});
});
// =============================================================================
// WORKFLOW — Navigation et état
// =============================================================================
test.describe('WORKFLOW — Navigation et état', () => {
test('07. Page refresh preserves auth state @critical', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
await page.waitForTimeout(2_000);
// Navigate to dashboard
await navigateTo(page, '/dashboard');
const sidebar = page.getByTestId('app-sidebar');
await expect(sidebar).toBeVisible({ timeout: CONFIG.timeouts.action });
// Refresh the page
await page.reload({ waitUntil: 'networkidle' });
// Auth state should persist - should not redirect to login
await page.waitForTimeout(2_000);
expect(page.url()).not.toContain('/login');
// Sidebar should still be visible (authenticated layout)
const sidebarAfterRefresh = page.getByTestId('app-sidebar');
await expect(sidebarAfterRefresh).toBeVisible({ timeout: CONFIG.timeouts.action });
});
test('08. Browser back button works correctly across pages', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
// Navigate through several pages
await navigateTo(page, '/dashboard');
await navigateTo(page, '/library');
expect(page.url()).toContain('/library');
await navigateTo(page, '/discover');
expect(page.url()).toContain('/discover');
// Go back
await page.goBack();
await page.waitForLoadState('networkidle').catch(() => {});
// Verify page is still functional regardless of URL change
const bodyAfterBack = await page.textContent('body') || '';
expect(bodyAfterBack).not.toMatch(/crash|TypeError|Cannot read/i);
expect(bodyAfterBack.length).toBeGreaterThan(50);
// Go back again
await page.goBack();
await page.waitForLoadState('networkidle').catch(() => {});
const bodyAfterSecondBack = await page.textContent('body') || '';
expect(bodyAfterSecondBack).not.toMatch(/crash|TypeError|Cannot read/i);
expect(bodyAfterSecondBack.length).toBeGreaterThan(50);
});
test('09. Forward button works after going back', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
await navigateTo(page, '/dashboard');
await navigateTo(page, '/library');
// Go back
await page.goBack();
await page.waitForLoadState('networkidle').catch(() => {});
const bodyAfterBack = await page.textContent('body') || '';
expect(bodyAfterBack).not.toMatch(/crash|TypeError|Cannot read/i);
expect(bodyAfterBack.length).toBeGreaterThan(50);
// Go forward
await page.goForward();
await page.waitForLoadState('networkidle').catch(() => {});
const bodyAfterForward = await page.textContent('body') || '';
expect(bodyAfterForward).not.toMatch(/crash|TypeError|Cannot read/i);
expect(bodyAfterForward.length).toBeGreaterThan(50);
});
test('10. Deep link to protected page redirects to login then back after auth', async ({ page }) => {
// Try to access a protected page while logged out
await navigateTo(page, '/settings');
// Should redirect to login
await page.waitForURL(/login/, { timeout: CONFIG.timeouts.navigation }).catch(() => {});
const redirectedToLogin = page.url().includes('/login');
test.skip(!redirectedToLogin, 'Page did not redirect to login — app may handle auth differently');
// Now login
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
// After login, should be redirected away from /login
await page.waitForTimeout(2_000);
await expect(page).not.toHaveURL(/login/, { timeout: CONFIG.timeouts.navigation });
});
test('11. Rapid navigation between pages does not crash', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
const routes = ['/dashboard', '/library', '/discover', '/search', '/playlists', '/profile'];
for (const route of routes) {
await page.goto(route, { waitUntil: 'domcontentloaded', timeout: CONFIG.timeouts.navigation });
}
// Wait for final page to stabilize
await page.waitForLoadState('networkidle').catch(() => {});
// Should be on the last page without crash
const body = await page.textContent('body') || '';
expect(body).not.toMatch(/crash|TypeError|Cannot read/i);
expect(body.length).toBeGreaterThan(50);
});
test('12. Sidebar navigation works for all main routes', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
await navigateTo(page, '/dashboard');
const sidebar = page.getByTestId('app-sidebar');
await expect(sidebar).toBeVisible({ timeout: CONFIG.timeouts.action });
// Click sidebar links and verify navigation
const sidebarLinks = sidebar.locator('a[href]');
const linkCount = await sidebarLinks.count();
expect(linkCount).toBeGreaterThan(0);
// Test first few sidebar links
const maxToTest = Math.min(linkCount, 5);
for (let i = 0; i < maxToTest; i++) {
const href = await sidebarLinks.nth(i).getAttribute('href');
if (href && !href.startsWith('http')) {
await sidebarLinks.nth(i).click();
await page.waitForLoadState('networkidle').catch(() => {});
await assertNotBroken(page);
}
}
});
});
// =============================================================================
// WORKFLOW — Player across navigation
// =============================================================================
test.describe('WORKFLOW — Player persiste pendant la navigation', () => {
test('13. Player stays visible when navigating between pages', async ({ page }) => {
await loginViaAPI(page, CONFIG.users.listener.email, CONFIG.users.listener.password);
// Go to discover and try to play a track
await navigateTo(page, '/discover');
await playFirstTrack(page);
const player = page.getByTestId('global-player');
const playerVisible = await player.isVisible().catch(() => false);
test.skip(!playerVisible, 'No track available to play — skipping player persistence check');
// Navigate to other pages - player should stay
await navigateTo(page, '/library');
await expect(player).toBeVisible({ timeout: CONFIG.timeouts.action });
await navigateTo(page, '/search');
await expect(player).toBeVisible({ timeout: CONFIG.timeouts.action });
await navigateTo(page, '/settings');
await expect(player).toBeVisible({ timeout: CONFIG.timeouts.action });
});
});