#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUST_ROOT="/Users/ashwin/workspace/nxtgauge-backend-rust"

echo "[1/7] Node unit tests (existing)"
cd "$ROOT_DIR"
npm run test

echo "[2/7] Vitest suite"
npm run test:vitest

echo "[3/7] Storybook build smoke"
npm run build-storybook

echo "[4/7] Playwright management parity e2e"
npm run test:management:parity

echo "[5/7] Playwright visual pixelmatch e2e"
npm run test:visual

echo "[6/7] Storybook Playwright smoke e2e"
npm run test:storybook:e2e

echo "[7/7] Rust backend cargo test"
if command -v cargo >/dev/null 2>&1 && [ -f "$RUST_ROOT/Cargo.toml" ]; then
  (cd "$RUST_ROOT" && cargo test --workspace)
else
  echo "Skipping cargo test (cargo or backend workspace not found)."
fi

echo "Nxtgauge E2E suite completed."
