Tests/Touch/Touch.Presets.Tests.ps1

BeforeAll {
    . "$PSScriptRoot\..\Shared\Setup.ps1"
    Initialize-TestEnvironment
}

AfterAll {
    Clear-TestEnvironment
}

Describe 'Touch - Preset integration' {
    BeforeEach {
        $script:testFolder = Join-Path $TestDrive "Touch_Presets_$(Get-Random)"
        New-Item -Path $script:testFolder -ItemType Directory -Force | Out-Null
    }

    It 'Applies preset to create files' {
        Save-TouchPreset -Name 'creation-preset' -Files 'x.txt', 'y.txt' | Out-Null
        Touch -Preset 'creation-preset' -Path $script:testFolder
        'x.txt', 'y.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
    }

    It 'Applies preset with Count' {
        Save-TouchPreset -Name 'numbered-preset' -Files 'log.txt' -Count 3 | Out-Null
        Touch -Preset 'numbered-preset' -Path $script:testFolder
        '(1)log.txt', '(2)log.txt', '(3)log.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
    }

    It 'Applies preset with default Path' {
        Save-TouchPreset -Name 'path-preset' -Files 'file.txt' -Path $script:testFolder | Out-Null
        Touch -Preset 'path-preset'
        Test-Path (Join-Path $script:testFolder 'file.txt') | Should -BeTrue
    }

    It 'Overrides preset Path with explicit -Path' {
        $otherFolder = Join-Path $TestDrive "Touch_Presets_Override_$(Get-Random)"
        New-Item -Path $otherFolder -ItemType Directory -Force | Out-Null
        Save-TouchPreset -Name 'override-path-preset' -Files 'file.txt' -Path $script:testFolder | Out-Null
        Touch -Preset 'override-path-preset' -Path $otherFolder
        Test-Path (Join-Path $otherFolder 'file.txt') | Should -BeTrue
        Test-Path (Join-Path $script:testFolder 'file.txt') | Should -BeFalse
    }

    It 'Overrides preset Count with explicit -Count' {
        Save-TouchPreset -Name 'override-count-preset' -Files 'log.txt' -Count 2 | Out-Null
        Touch -Preset 'override-count-preset' -Count 4 -Path $script:testFolder
        '(1)log.txt', '(2)log.txt', '(3)log.txt', '(4)log.txt' | ForEach-Object {
            Test-Path (Join-Path $script:testFolder $_) | Should -BeTrue
        }
        Test-Path (Join-Path $script:testFolder '(5)log.txt') | Should -BeFalse
    }

    It 'Throws when preset not found' {
        { Touch -Preset 'nonexistent-preset' } | Should -Throw '*not found*'
    }
}