#!/bin/bash

echo "=== Testing Staging Site for Errors ==="
echo ""

# Test if pages are loading without errors
echo "1. Testing Master Dashboard Page..."
response=$(curl -s -I https://upskill-staging.measurequick.com/master-trainer/dashboard/)
status=$(echo "$response" | grep "HTTP" | awk '{print $2}')
if [ "$status" = "200" ]; then
    echo "✅ Master dashboard page loads successfully (HTTP $status)"
else
    echo "❌ Master dashboard page error (HTTP $status)"
fi

echo ""
echo "2. Testing CSS Loading on Master Dashboard..."
response=$(curl -s https://upskill-staging.measurequick.com/master-trainer/dashboard/)
if echo "$response" | grep -q "hvac-common.css"; then
    echo "✅ CSS files are referenced in page"
else
    echo "❌ CSS files NOT found in page source"
fi

# Check for specific error patterns
if echo "$response" | grep -q "There has been a critical error"; then
    echo "❌ CRITICAL ERROR found on page!"
else
    echo "✅ No critical errors detected"
fi

echo ""
echo "3. Checking for Debug Messages..."
if echo "$response" | grep -q "HVAC DEBUG"; then
    echo "❌ Debug messages found in output!"
else
    echo "✅ No debug messages in output"
fi

echo ""
echo "=== Test Complete ==="