#!/bin/bash
# Script to run Android tests for ProofMode integration

set -e

echo "Running Android ProofMode Integration Tests"
echo "=========================================="

# Check if we're in the right directory
if [ ! -f "gradlew" ]; then
    echo "Error: This script must be run from the android-example directory"
    exit 1
fi

# Clean previous test results
echo "Cleaning previous test results..."
./gradlew clean

# Run unit tests
echo ""
echo "Running Unit Tests..."
echo "--------------------"
./gradlew test

# Run instrumentation tests (requires connected device or emulator)
echo ""
echo "Running Integration Tests..."
echo "---------------------------"
echo "Note: This requires a connected Android device or running emulator"

# Check if device is connected
if adb devices | grep -q "device$"; then
    echo "Device detected, running integration tests..."
    ./gradlew connectedAndroidTest
    
    # Generate test report
    echo ""
    echo "Test Results:"
    echo "-------------"
    echo "Unit test results: app/build/reports/tests/testDebugUnitTest/index.html"
    echo "Integration test results: app/build/reports/androidTests/connected/index.html"
else
    echo "WARNING: No Android device detected. Skipping integration tests."
    echo "To run integration tests, please:"
    echo "  1. Connect an Android device with USB debugging enabled, or"
    echo "  2. Start an Android emulator"
fi

echo ""
echo "Test run complete!"