test_cassiel_compatibility.ps1

# Quick Test for Show-ConsoleMenu Cassiel Compatibility

Write-Host "=== Testing HermesConsoleUI v2.1.0 - Cassiel Compatibility ===" -ForegroundColor Cyan
Write-Host ""

# Import the module from local development path
$modulePath = Join-Path $PSScriptRoot "HermesConsoleUI.psm1"
if (Test-Path $modulePath) {
    Import-Module $modulePath -Force
    Write-Host "[OK] Module loaded from: $modulePath" -ForegroundColor Green
}
else {
    Write-Host "[ERROR] Module not found at: $modulePath" -ForegroundColor Red
    exit 1
}

Write-Host ""
Write-Host "--- Test 1: Legacy Behavior (No -ReturnIndex) ---" -ForegroundColor Yellow
$options = @("Option 1", "Option 2", "Option 3")
$count = Show-ConsoleMenu -Title "Legacy Test" -Options $options -NoClear
Write-Host "Returned count: $count (Expected: 3)" -ForegroundColor $(if ($count -eq 3) { "Green" } else { "Red" })

Write-Host ""
Write-Host "--- Test 2: Header Parameter ---" -ForegroundColor Yellow
Write-Host "The menu below should display 'Please select an option:' before the options" -ForegroundColor Gray
$count2 = Show-ConsoleMenu -Title "Header Test" -Options $options -Header "Please select an option:" -NoClear
Write-Host "Returned count: $count2 (Expected: 3)" -ForegroundColor $(if ($count2 -eq 3) { "Green" } else { "Red" })

Write-Host ""
Write-Host "--- Test 3: Headers and Separators (Non-selectable) ---" -ForegroundColor Yellow
$optionsWithHeaders = @(
    "[CATEGORY 1]",
    "Option 1.1",
    "Option 1.2",
    "---",
    "[CATEGORY 2]",
    "Option 2.1"
)
$count3 = Show-ConsoleMenu -Title "Headers Test" -Options $optionsWithHeaders -NoClear
Write-Host "Returned count: $count3 (Expected: 3 selectable options)" -ForegroundColor $(if ($count3 -eq 3) { "Green" } else { "Red" })

Write-Host ""
Write-Host "--- Test 4: ReturnIndex Parameter (Interactive) ---" -ForegroundColor Yellow
Write-Host "This test will prompt you for input. Select option 2, then 0 to exit." -ForegroundColor Gray
Write-Host ""

$testOptions = @("First Option", "Second Option", "Third Option")
$choice = Show-ConsoleMenu -Title "ReturnIndex Test" -Options $testOptions -Header "Select option 2:" -ReturnIndex -NoClear

Write-Host ""
Write-Host "You selected: $choice" -ForegroundColor Cyan
if ($choice -eq 2) {
    Write-Host "[OK] ReturnIndex works correctly!" -ForegroundColor Green
}
elseif ($choice -eq 0) {
    Write-Host "[INFO] You selected exit (0)" -ForegroundColor Yellow
}
else {
    Write-Host "[WARN] Expected 2, got $choice" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "=== All Tests Completed ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "Summary:" -ForegroundColor White
Write-Host " - Legacy behavior (returns count): $(if ($count -eq 3) { 'PASS' } else { 'FAIL' })" -ForegroundColor $(if ($count -eq 3) { "Green" } else { "Red" })
Write-Host " - Header parameter: $(if ($count2 -eq 3) { 'PASS' } else { 'FAIL' })" -ForegroundColor $(if ($count2 -eq 3) { "Green" } else { "Red" })
Write-Host " - Non-selectable headers/separators: $(if ($count3 -eq 3) { 'PASS' } else { 'FAIL' })" -ForegroundColor $(if ($count3 -eq 3) { "Green" } else { "Red" })
Write-Host " - ReturnIndex parameter: $(if ($choice -eq 2 -or $choice -eq 0) { 'PASS' } else { 'FAIL' })" -ForegroundColor $(if ($choice -eq 2 -or $choice -eq 0) { "Green" } else { "Red" })
Write-Host ""