tests/QuickAssistSession.Tests.ps1

$moduleRoot = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $moduleRoot 'Octa.psd1') -Force
. (Join-Path $moduleRoot 'private\StatusPanel.ps1')
. (Join-Path $moduleRoot 'private\RestorePoint.ps1')

Describe 'Invoke-OctaSessionRestorePointGate (010: once per session, not once per category)' {
    $strings = Import-LocalizedData -BaseDirectory $moduleRoot -FileName 'Octa.psd1' -UICulture 'en-US'

    It 'returns true and calls New-OctaRestorePoint exactly once when a point is created' {
        Mock New-OctaRestorePoint { [pscustomobject]@{ Status = 'Created'; SequenceNumber = 1 } }
        $result = Invoke-OctaSessionRestorePointGate -Strings $strings
        $result | Should Be $true
        Assert-MockCalled New-OctaRestorePoint -Times 1 -Exactly
    }

    It 'proceeds when throttled and the interactive user confirms' {
        Mock New-OctaRestorePoint { [pscustomobject]@{ Status = 'SkippedThrottled'; SequenceNumber = $null } }
        Mock Test-OctaInteractiveConsole { return $true }
        Mock Read-Host { return 'y' }
        Invoke-OctaSessionRestorePointGate -Strings $strings | Should Be $true
    }

    It 'declines when throttled and the interactive user says no' {
        Mock New-OctaRestorePoint { [pscustomobject]@{ Status = 'SkippedThrottled'; SequenceNumber = $null } }
        Mock Test-OctaInteractiveConsole { return $true }
        Mock Read-Host { return 'n' }
        Invoke-OctaSessionRestorePointGate -Strings $strings | Should Be $false
    }

    It 'proceeds without blocking on a prompt in a non-interactive console' {
        Mock New-OctaRestorePoint { [pscustomobject]@{ Status = 'SkippedThrottled'; SequenceNumber = $null } }
        Mock Test-OctaInteractiveConsole { return $false }
        Mock Read-Host { throw 'Read-Host should not be called in a non-interactive console' }
        Invoke-OctaSessionRestorePointGate -Strings $strings | Should Be $true
    }

    It 'never throws regardless of the underlying restore-point outcome' {
        foreach ($status in 'Created', 'SkippedThrottled', 'SkippedProtectionDisabled') {
            Mock New-OctaRestorePoint { [pscustomobject]@{ Status = $status; SequenceNumber = $null } }
            Mock Test-OctaInteractiveConsole { return $false }
            { Invoke-OctaSessionRestorePointGate -Strings $strings } | Should Not Throw
        }
    }
}

Describe 'Invoke-OctaDiskCleanup gains -NoRestorePoint (010 FR-008)' {
    It 'exposes a NoRestorePoint switch parameter' {
        # ponytail: Pester 3.4's "Should Contain" greps a file's content, it is NOT a Pester 5
        # "collection contains element" assertion - that's -contains, verified against this
        # exact pinned version (Pester 3.4.0) after this test failed misleadingly with "Should
        # Contain".
        ((Get-Command Invoke-OctaDiskCleanup).Parameters.Keys -contains 'NoRestorePoint') | Should Be $true
    }
}

Describe 'Quick Assist / Quick Custom localized strings (010)' {
    $enStrings = Import-LocalizedData -BaseDirectory $moduleRoot -FileName 'Octa.psd1' -UICulture 'en-US'
    $esStrings = Import-LocalizedData -BaseDirectory $moduleRoot -FileName 'Octa.psd1' -UICulture 'es-ES'

    foreach ($key in 'menuQuickAssist', 'menuQuickAssistDesc', 'menuQuickCustom', 'menuQuickCustomDesc', 'restorePointSessionIntro') {
        It "'$key' exists in both locales" {
            ($enStrings.Keys -contains $key) | Should Be $true
            ($esStrings.Keys -contains $key) | Should Be $true
        }
    }

    It 'the old menuQuickClean key no longer exists (renamed, not duplicated)' {
        ($enStrings.Keys -contains 'menuQuickClean') | Should Be $false
        ($esStrings.Keys -contains 'menuQuickClean') | Should Be $false
    }
}