Files
winutil/pester/variables.Tests.ps1
T
NikhilandChris Titus 436773df73 Fix legacy json import compatibility, UI sidebar refactor, and improved test coverage (#4911)
* Fix backward compatibility for old-style JSON config imports

* Refactor sidebar UI generation and add tests for Get-WinUtilVariables

* Fix appnavigation config test following UI generation refactor

* Restore global sync state in variables tests

* fix(impex): migrate supported legacy selections

Keep modern imports strict while allowing legacy backups to skip retired entries with clear logging and user feedback. Add fixtures covering partial and all-retired imports.

* test: strengthen UI and global state coverage

Exercise app category rendering through Initialize-WPFUI and restore global sync without leaking test state.

* fix(impex): ignore legacy metadata fields

Limit legacy selection migration to supported WPF key families so unrelated string metadata does not produce false retired-setting warnings.

* docs: clarify legacy config imports

Distinguish strict modern flat imports from partial legacy object migration, including single-setting export shape and historical groups.

---------

Co-authored-by: Chris Titus <contact@christitus.com>
2026-08-19 17:13:14 -05:00

61 lines
2.2 KiB
PowerShell

#===========================================================================
# Tests - Get-WinUtilVariables
#===========================================================================
BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$script:originalSyncVariable = Get-Variable -Name sync -Scope Global -ErrorAction SilentlyContinue
if ($script:originalSyncVariable) {
$script:originalSyncValue = $script:originalSyncVariable.Value
}
$global:sync = [Hashtable]::Synchronized(@{})
# Setup some test variables
$global:sync["WPFTestString"] = "I am a string"
$global:sync["WPFTestObj1"] = [PSCustomObject]@{ Name = "Test1" }
$global:sync["WPFTestObj2"] = [PSCustomObject]@{ Name = "Test2" }
$global:sync["WPFTestButton"] = [System.Version]::new("1.0.0.0")
$global:sync["OtherVar"] = "Not a WPF variable"
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilVariables.ps1")
}
AfterAll {
if ($script:originalSyncVariable) {
Set-Variable -Name sync -Value $script:originalSyncValue -Scope Global -Force
} else {
Remove-Variable -Name sync -Scope Global -ErrorAction SilentlyContinue
}
}
Describe "Get-WinUtilVariables" {
It "returns all WPF-prefixed keys when no type is provided" {
$result = Get-WinUtilVariables
$result.Count | Should -Be 4
$result | Should -Contain "WPFTestString"
$result | Should -Contain "WPFTestObj1"
$result | Should -Contain "WPFTestObj2"
$result | Should -Contain "WPFTestButton"
$result | Should -Not -Contain "OtherVar"
}
It "returns only WPF keys matching the specified exact type" {
$result = Get-WinUtilVariables -Type "String"
$result.Count | Should -Be 1
$result | Should -Contain "WPFTestString"
}
It "returns multiple objects matching PSCustomObject" {
$result = Get-WinUtilVariables -Type "PSCustomObject"
$result.Count | Should -Be 2
$result | Should -Contain "WPFTestObj1"
$result | Should -Contain "WPFTestObj2"
}
It "returns an empty list when no matching type is found" {
$result = Get-WinUtilVariables -Type "Int32"
$result | Should -BeNullOrEmpty
}
}