mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-10-09 21:21:18 +11:00
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>
This commit is contained in:
@@ -93,6 +93,9 @@ namespace System.Windows.Controls
|
||||
function Write-WinUtilLog {
|
||||
param($Message, $Level, $Component)
|
||||
}
|
||||
function Show-WinUtilMessage {
|
||||
param($Message, $Title, $Button, $Icon)
|
||||
}
|
||||
|
||||
function script:New-WinUtilFakeCheckBox {
|
||||
param([bool]$IsChecked = $false)
|
||||
@@ -244,6 +247,8 @@ Describe "Invoke-WPFImpex import selection state" {
|
||||
|
||||
Mock Reset-WPFCheckBoxes { }
|
||||
Mock Write-Error { }
|
||||
Mock Write-WinUtilLog { }
|
||||
Mock Show-WinUtilMessage { }
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
@@ -271,6 +276,72 @@ Describe "Invoke-WPFImpex import selection state" {
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "imports supported legacy selections and reports retired entries" {
|
||||
$configPath = Join-Path $script:repoRoot "pester\fixtures\legacy-config.json"
|
||||
|
||||
Invoke-WPFImpex -type "import" -Config $configPath
|
||||
|
||||
@($script:sync.selectedApps) | Should -Be @("WPFInstallGit")
|
||||
@($script:sync.selectedTweaks) | Should -Be @("WPFTweaksTelemetry")
|
||||
@($script:sync.selectedFeatures) | Should -Be @("WPFFeatureSandbox")
|
||||
Should -Invoke -CommandName Reset-WPFCheckBoxes -Times 1 -Exactly -ParameterFilter {
|
||||
$doToggles -eq $true
|
||||
}
|
||||
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
|
||||
$Component -eq "Impex" -and
|
||||
$Level -eq "WARN" -and
|
||||
$Message -eq "Skipped unsupported legacy selections: WPFInstallRetired"
|
||||
}
|
||||
Should -Invoke -CommandName Show-WinUtilMessage -Times 1 -Exactly -ParameterFilter {
|
||||
$Title -eq "Legacy Configuration Partially Imported" -and
|
||||
$Message -like "*WPFInstallRetired*"
|
||||
}
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "ignores unrelated string metadata in a legacy configuration" {
|
||||
$configPath = Join-Path $TestDrive "legacy-config-with-metadata.json"
|
||||
[pscustomobject]@{
|
||||
Install = @([pscustomobject]@{ winget = "Git.Git"; choco = "git" })
|
||||
WPFInstall = @("WPFInstallGit")
|
||||
ExportVersion = "1.0"
|
||||
} | ConvertTo-Json -Depth 3 | Set-Content -LiteralPath $configPath
|
||||
|
||||
Invoke-WPFImpex -type "import" -Config $configPath
|
||||
|
||||
@($script:sync.selectedApps) | Should -Be @("WPFInstallGit")
|
||||
Should -Invoke -CommandName Reset-WPFCheckBoxes -Times 1 -Exactly
|
||||
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
|
||||
$Component -eq "Impex" -and
|
||||
$Message -eq "Detected legacy WinUtil config structure; flattening import object."
|
||||
}
|
||||
Should -Invoke -CommandName Show-WinUtilMessage -Times 0 -Exactly
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "preserves selections when every legacy entry is retired" {
|
||||
$script:sync.selectedApps.Add("WPFInstallExisting")
|
||||
$configPath = Join-Path $TestDrive "retired-legacy-config.json"
|
||||
[pscustomobject]@{
|
||||
Install = @([pscustomobject]@{ winget = "Retired.App"; choco = "retired-app" })
|
||||
WPFTweaks = @()
|
||||
WPFFeature = @()
|
||||
WPFInstall = @("WPFInstallRetired")
|
||||
} | ConvertTo-Json -Depth 3 | Set-Content -LiteralPath $configPath
|
||||
|
||||
Invoke-WPFImpex -type "import" -Config $configPath
|
||||
|
||||
@($script:sync.selectedApps) | Should -Be @("WPFInstallExisting")
|
||||
Should -Invoke -CommandName Reset-WPFCheckBoxes -Times 0 -Exactly
|
||||
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
|
||||
$Message -eq "Skipped unsupported legacy selections: WPFInstallRetired"
|
||||
}
|
||||
Should -Invoke -CommandName Show-WinUtilMessage -Times 1 -Exactly -ParameterFilter {
|
||||
$Title -eq "Unsupported Legacy Configuration"
|
||||
}
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "imports legacy selection groups without treating Install metadata as a selection" {
|
||||
$legacyConfigPath = Join-Path $TestDrive "legacy-config.json"
|
||||
[ordered]@{
|
||||
|
||||
Reference in New Issue
Block a user