veza/apps/web/e2e/tests/purchase.spec.ts
senke 7aedc1ec77 test(e2e): audit 2.10 — flows critiques Auth, Upload, Purchase, Chat
- purchase.spec.ts: add to cart, checkout, success
- chat.spec.ts: load UI, send message (when WebSocket available)
- README: document critical flows and prerequisites
2026-02-15 14:51:29 +01:00

100 lines
3.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
import {
TEST_CONFIG,
loginAsUser,
setupErrorCapture,
waitForToast,
} from '../utils/test-helpers';
/**
* Purchase E2E Test Suite (Audit 2.10)
*
* Couvre le flow critique d'achat :
* - Marketplace → Add to cart → Checkout → Success
* - Cart empty state
*/
test.describe('Purchase Flow', () => {
let consoleErrors: string[] = [];
let networkErrors: Array<{ url: string; status: number; method: string }> = [];
test.beforeEach(async ({ page }) => {
const errorCapture = setupErrorCapture(page);
consoleErrors = errorCapture.consoleErrors;
networkErrors = errorCapture.networkErrors;
});
test('should add product to cart and checkout successfully', async ({ page }) => {
console.log('🧪 [PURCHASE] Running: Add to cart and checkout');
await loginAsUser(page);
await page.waitForTimeout(1000);
await page.goto(`${TEST_CONFIG.FRONTEND_URL}/marketplace`);
await page.waitForLoadState('domcontentloaded');
await page.waitForLoadState('networkidle', { timeout: 15000 }).catch(() => {});
const productCard = page.locator('article[aria-label^="Product:"]').first();
await expect(productCard).toBeVisible({ timeout: 10000 });
await productCard.hover();
await page.waitForTimeout(300);
const addToCartButton = page.locator('button:has-text("Add to Cart")').first();
await expect(addToCartButton).toBeVisible({ timeout: 5000 });
await addToCartButton.click();
await page.waitForTimeout(1500);
const cartButton = page.locator('button:has-text("Cart")').first();
await expect(cartButton).toBeVisible({ timeout: 5000 });
await cartButton.click();
const cartDialog = page.locator('[role="dialog"]').filter({ hasText: 'Shopping Cart' });
await expect(cartDialog).toBeVisible({ timeout: 5000 });
const checkoutButton = cartDialog.locator('button:has-text("Checkout")');
await expect(checkoutButton).toBeVisible({ timeout: 3000 });
await checkoutButton.click();
const successToast = await waitForToast(page, 'success', 15000);
expect(successToast.toLowerCase()).toMatch(/order|success|placed/);
console.log('✅ [PURCHASE] Checkout successful');
});
test('should show cart empty message when no items', async ({ page }) => {
console.log('🧪 [PURCHASE] Running: Cart empty state');
await loginAsUser(page);
await page.waitForTimeout(1000);
await page.goto(`${TEST_CONFIG.FRONTEND_URL}/marketplace`);
await page.waitForLoadState('domcontentloaded');
await page.waitForLoadState('networkidle', { timeout: 15000 }).catch(() => {});
const cartButton = page.locator('button:has-text("Cart")').first();
await expect(cartButton).toBeVisible({ timeout: 5000 });
await cartButton.click();
const cartDialog = page.locator('[role="dialog"]').filter({ hasText: 'Shopping Cart' });
await expect(cartDialog).toBeVisible({ timeout: 5000 });
const emptyMessage = cartDialog.locator('text=/cart is empty|your cart is empty/i');
await expect(emptyMessage).toBeVisible({ timeout: 5000 });
console.log('✅ [PURCHASE] Cart empty message displayed');
});
test.afterEach(async ({}, testInfo) => {
console.log('\n📊 [PURCHASE] === Final Verifications ===');
if (consoleErrors.length > 0) {
console.log(`🔴 [PURCHASE] Console errors (${consoleErrors.length}):`);
consoleErrors.forEach((e) => console.log(` - ${e}`));
}
if (networkErrors.length > 0) {
console.log(`🔴 [PURCHASE] Network errors (${networkErrors.length}):`);
networkErrors.forEach((e) => console.log(` - ${e.method} ${e.url}: ${e.status}`));
}
});
});