#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

echo "=========================================="
echo "  Ether PMS - All E2E Tests"
echo "=========================================="
echo ""

cd "$SCRIPT_DIR"

if [ ! -f "playwright.config.ts" ]; then
  echo "ERROR: playwright.config.ts not found in $SCRIPT_DIR"
  exit 1
fi

if [ ! -d "node_modules" ]; then
  echo "Installing dependencies..."
  npm install
  npx playwright install chromium
fi

echo "Running all E2E tests..."
npx playwright test --reporter=html,list

EXIT_CODE=$?

echo ""
echo "=========================================="
echo "  E2E Tests Complete (exit code: $EXIT_CODE)"
echo "=========================================="

exit $EXIT_CODE
