Files
winutil/pester/toggle-status.Tests.ps1
Chris Titus 93dc23dd66 Speed up runspace and tab initialization (#4793)
* Add startup performance tracing

* Lazy initialize non-default tabs

* Render install app entries incrementally

* Defer and cache toggle status checks

* Clean up runspace invocation ownership

* Defer GUI runspace pool startup

* Defer status taskbar asset rendering

* Record final speed verification

* Fix deferred install render timer callback

* Add dispatcher smoke coverage for install rendering

* Replace install render timer with dispatcher callbacks

* Gate performance tracing behind compile switch

* Clean up analyzer warnings in speed changes

* Speed up runspace and tab initialization
2026-07-01 23:34:59 -05:00

85 lines
3.3 KiB
PowerShell

#===========================================================================
# Tests - Toggle status checks
#===========================================================================
BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilToggleStatus.ps1")
}
Describe "Get-WinUtilToggleStatus" {
BeforeEach {
$script:sync = [Hashtable]::Synchronized(@{
configs = @{
tweaks = [pscustomobject]@{
WPFToggleExample = [pscustomobject]@{
registry = @(
[pscustomobject]@{
Path = "HKCU:\Software\WinUtilToggle"
Name = "Enabled"
Value = "1"
OriginalValue = "0"
DefaultState = "true"
}
)
}
WPFToggleDisabledByDefault = [pscustomobject]@{
registry = @(
[pscustomobject]@{
Path = "HKCU:\Software\WinUtilToggle"
Name = "Enabled"
Value = "1"
OriginalValue = "0"
DefaultState = "false"
}
)
}
}
}
})
Mock Get-PSDrive { [pscustomobject]@{ Name = "HKU" } } -ParameterFilter { $Name -eq "HKU" }
Mock New-PSDrive { }
Mock New-Item { }
Mock Test-Path { $false }
Mock Get-ItemProperty { [pscustomobject]@{ Enabled = "1" } }
}
AfterEach {
Remove-Variable -Name sync -Scope Script -ErrorAction SilentlyContinue
}
It "does not create missing registry paths while reading toggle state" {
Get-WinUtilToggleStatus "WPFToggleExample" | Should -BeTrue
Should -Invoke -CommandName Test-Path -Times 1 -Exactly -ParameterFilter {
$Path -eq "HKCU:\Software\WinUtilToggle"
}
Should -Invoke -CommandName New-Item -Times 0 -Exactly
Should -Invoke -CommandName Get-ItemProperty -Times 0 -Exactly
}
It "uses configured false default when the registry path is missing" {
Get-WinUtilToggleStatus "WPFToggleDisabledByDefault" | Should -BeFalse
Should -Invoke -CommandName New-Item -Times 0 -Exactly
}
It "caches toggle results for repeated checks" {
Mock Test-Path { $true } -ParameterFilter { $Path -eq "HKCU:\Software\WinUtilToggle" }
Mock Get-ItemProperty { [pscustomobject]@{ Enabled = "1" } } -ParameterFilter {
$Path -eq "HKCU:\Software\WinUtilToggle"
}
Get-WinUtilToggleStatus "WPFToggleExample" | Should -BeTrue
Get-WinUtilToggleStatus "WPFToggleExample" | Should -BeTrue
Should -Invoke -CommandName Test-Path -Times 1 -Exactly -ParameterFilter {
$Path -eq "HKCU:\Software\WinUtilToggle"
}
Should -Invoke -CommandName Get-ItemProperty -Times 1 -Exactly -ParameterFilter {
$Path -eq "HKCU:\Software\WinUtilToggle"
}
}
}