fix: match tweak presets and app-removal scope by stable ID instead of translatable text (#737)

This commit is contained in:
Sashank
2026-08-16 17:52:58 +02:00
committed by GitHub
parent 31feaeb6f5
commit 5072958b10
7 changed files with 262 additions and 30 deletions
+95 -2
View File
@@ -117,14 +117,27 @@ Describe 'Get-PendingTweakActions' {
$checkBox = New-Object System.Windows.Controls.CheckBox
$checkBox.Visibility = 'Visible'
$window.RegisterName('DisableTelemetryCheckBox', $checkBox)
$script:UiControlMappings = @{ DisableTelemetryCheckBox = [PSCustomObject]@{ Category = 'Privacy'; Type = 'feature'; FeatureId = 'DisableTelemetry' } }
$script:UiControlMappings = @{ DisableTelemetryCheckBox = [PSCustomObject]@{ Category = 'Privacy & Suggested Content'; CategoryId = 'PrivacySuggestedContent'; Type = 'feature'; FeatureId = 'DisableTelemetry' } }
$map = Get-CategoryTweakPresetMap -Window $window -Category 'Privacy'
$map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'PrivacySuggestedContent'
$map['DisableTelemetryCheckBox'].ControlType | Should -Be 'CheckBox'
$map['DisableTelemetryCheckBox'].DesiredValue | Should -BeTrue
}
It 'matches a mapping whose CategoryId fell back to its Name, for a category missing CategoryId' {
$window = New-TestWindow
$checkBox = New-Object System.Windows.Controls.CheckBox
$checkBox.Visibility = 'Visible'
$window.RegisterName('LegacyCheckBox', $checkBox)
# New-DynamicTweakControls falls back to Name when a category has no CategoryId of its own.
$script:UiControlMappings = @{ LegacyCheckBox = [PSCustomObject]@{ Category = 'Legacy Category'; CategoryId = 'Legacy Category'; Type = 'feature'; FeatureId = 'SomeFeature' } }
$map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'Legacy Category'
$map['LegacyCheckBox'].ControlType | Should -Be 'CheckBox'
}
It 'updates navigation visibility and progress indicators for an interior tab' {
$window = New-TestWindow
$tabControl = New-Object System.Windows.Controls.TabControl
@@ -142,6 +155,86 @@ Describe 'Get-PendingTweakActions' {
}
}
Describe 'Update-AppRemovalScopeDescription' {
It 'matches on the ComboBoxItem Name rather than its (translatable) Content for <Name>' -ForEach @(
@{ Name = 'AppRemovalScopeAllUsers'; ExpectedText = 'Apps will be removed for all users and from the Windows image to prevent reinstallation for new users.' }
@{ Name = 'AppRemovalScopeCurrentUser'; ExpectedText = 'Apps will only be removed for the current user.' }
@{ Name = 'AppRemovalScopeTargetUser'; ExpectedText = 'Apps will only be removed for the specified target user.' }
) {
$combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = $Name
$item.Content = 'Texto traducido'
$combo.Items.Add($item) | Out-Null
$combo.SelectedItem = $item
$description = New-Object System.Windows.Controls.TextBlock
Update-AppRemovalScopeDescription -AppRemovalScopeCombo $combo -AppRemovalScopeDescription $description
$description.Text | Should -Be $ExpectedText
}
}
Describe 'Get-AppRemovalScopeTarget' {
It 'matches on the ComboBoxItem Name rather than its (translatable) Content for <Name>' -ForEach @(
@{ Name = 'AppRemovalScopeAllUsers'; ExpectedTarget = 'AllUsers' }
@{ Name = 'AppRemovalScopeCurrentUser'; ExpectedTarget = 'CurrentUser' }
) {
$combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = $Name
$item.Content = 'Texto traducido'
$combo.Items.Add($item) | Out-Null
$combo.SelectedItem = $item
$usernameBox = New-Object System.Windows.Controls.TextBox
Get-AppRemovalScopeTarget -AppRemovalScopeCombo $combo -OtherUsernameTextBox $usernameBox | Should -Be $ExpectedTarget
}
It 'returns the trimmed username for the target-user scope' {
$combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = 'AppRemovalScopeTargetUser'
$item.Content = 'Texto traducido'
$combo.Items.Add($item) | Out-Null
$combo.SelectedItem = $item
$usernameBox = New-Object System.Windows.Controls.TextBox
$usernameBox.Text = ' jdoe '
Get-AppRemovalScopeTarget -AppRemovalScopeCombo $combo -OtherUsernameTextBox $usernameBox | Should -Be 'jdoe'
}
It 'returns null when nothing is selected' {
$combo = New-Object System.Windows.Controls.ComboBox
$usernameBox = New-Object System.Windows.Controls.TextBox
Get-AppRemovalScopeTarget -AppRemovalScopeCombo $combo -OtherUsernameTextBox $usernameBox | Should -BeNullOrEmpty
}
It 'returns null for an unrecognized ComboBoxItem Name' {
$combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = 'SomeUnrelatedControl'
$combo.Items.Add($item) | Out-Null
$combo.SelectedItem = $item
$usernameBox = New-Object System.Windows.Controls.TextBox
Get-AppRemovalScopeTarget -AppRemovalScopeCombo $combo -OtherUsernameTextBox $usernameBox | Should -BeNullOrEmpty
}
It 'returns an empty string for the target-user scope when the username is blank' {
$combo = New-Object System.Windows.Controls.ComboBox
$item = New-Object System.Windows.Controls.ComboBoxItem
$item.Name = 'AppRemovalScopeTargetUser'
$combo.Items.Add($item) | Out-Null
$combo.SelectedItem = $item
$usernameBox = New-Object System.Windows.Controls.TextBox
$usernameBox.Text = ' '
Get-AppRemovalScopeTarget -AppRemovalScopeCombo $combo -OtherUsernameTextBox $usernameBox | Should -BeExactly ''
}
}
Describe 'Set-WindowThemeResources' {
It 'populates themed resources and selects the Windows 11 icon font' {
$window = New-TestWindow