#!/bin/bash
# Validation rapide de la config E2E (sans lancer Playwright)

echo "🔍 Validation configuration E2E"
echo ""

# 1. Check files exist
echo "✓ Vérification des fichiers..."
[ -f "apps/web/.env.e2e" ] && echo "  ✅ .env.e2e existe" || echo "  ❌ .env.e2e manquant"
[ -f "tests/e2e/dashboard-crud.spec.ts" ] && echo "  ✅ dashboard-crud.spec.ts existe" || echo "  ❌ Test manquant"
[ -f "tests/e2e/support/testHarness.ts" ] && echo "  ✅ testHarness.ts existe" || echo "  ❌ Harness manquant"

# 2. Check .env.e2e content
echo ""
echo "✓ Vérification .env.e2e..."
if grep -q "VITE_E2E_AUTH_BYPASS=true" apps/web/.env.e2e; then
  echo "  ✅ VITE_E2E_AUTH_BYPASS=true configuré"
else
  echo "  ❌ VITE_E2E_AUTH_BYPASS manquant ou incorrect"
fi

# 3. Check router bypass code
echo ""
echo "✓ Vérification router.ts..."
if grep -q "e2e.*true.*urlBypass" apps/web/src/app/router.ts; then
  echo "  ✅ URL bypass (e2e=true) implémenté"
else
  echo "  ⚠️  URL bypass peut-être manquant"
fi

if grep -q "VITE_E2E_AUTH_BYPASS" apps/web/src/app/router.ts; then
  echo "  ✅ Env var bypass implémenté"
else
  echo "  ❌ Env var bypass manquant"
fi

# 4. Check testHarness URL param
echo ""
echo "✓ Vérification testHarness.ts..."
if grep -q "e2e.*true" tests/e2e/support/testHarness.ts; then
  echo "  ✅ testHarness ajoute ?e2e=true"
else
  echo "  ❌ testHarness ne configure pas ?e2e=true"
fi

# 5. Check playwright config
echo ""
echo "✓ Vérification playwright.config.ts..."
if grep -q "mode e2e" playwright.config.ts; then
  echo "  ✅ Playwright démarre serveur avec --mode e2e"
else
  echo "  ❌ Playwright ne passe pas --mode e2e"
fi

# Summary
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Résumé de la configuration"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Les tests E2E sont configurés avec 3 méthodes de bypass :"
echo "  1. Runtime flag: globalThis.__E2E_AUTH_BYPASS__"
echo "  2. Env variable: VITE_E2E_AUTH_BYPASS=true (.env.e2e)"
echo "  3. URL param: ?e2e=true (ajouté par testHarness)"
echo ""
echo "Pour lancer les tests :"
echo "  pnpm exec playwright test dashboard-crud.spec.ts"
echo ""
echo "✅ Configuration validée"
