mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-08-23 08:02:07 +00:00
fix: match tweak presets and app-removal scope by stable ID instead of translatable text (#737)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,6 +1,40 @@
|
||||
BeforeAll {
|
||||
Add-Type -AssemblyName PresentationFramework
|
||||
function Test-TargetUserName { param($UserName) }
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-AppSelection.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Deployment.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Get-SystemUsesDarkMode.ps1')
|
||||
|
||||
function New-TestWindow {
|
||||
$window = New-Object System.Windows.Window
|
||||
$window.Resources['ValidationErrorColor'] = [System.Windows.Media.Brushes]::Red
|
||||
$window.Resources['ValidationSuccessColor'] = [System.Windows.Media.Brushes]::Green
|
||||
return $window
|
||||
}
|
||||
|
||||
function New-UserSelectionCombo {
|
||||
param([int]$SelectedIndex = 0)
|
||||
|
||||
$combo = New-Object System.Windows.Controls.ComboBox
|
||||
'Current User', 'Other User', 'Windows Default User (Sysprep)' | ForEach-Object {
|
||||
$combo.Items.Add((New-Object System.Windows.Controls.ComboBoxItem -Property @{ Content = $_ })) | Out-Null
|
||||
}
|
||||
$combo.SelectedIndex = $SelectedIndex
|
||||
return $combo
|
||||
}
|
||||
|
||||
function New-AppRemovalScopeCombo {
|
||||
param([string]$SelectedItemName)
|
||||
|
||||
$combo = New-Object System.Windows.Controls.ComboBox
|
||||
if ($SelectedItemName) {
|
||||
$item = New-Object System.Windows.Controls.ComboBoxItem
|
||||
$item.Name = $SelectedItemName
|
||||
$combo.Items.Add($item) | Out-Null
|
||||
$combo.SelectedItem = $item
|
||||
}
|
||||
return $combo
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-UndoFeatureLabel' {
|
||||
@@ -31,3 +65,44 @@ Describe 'Get-UndoFeatureLabel' {
|
||||
Get-SystemUsesDarkMode | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-OtherUsername' {
|
||||
It 'skips validation when neither the deployment target nor the app-removal scope needs a username' {
|
||||
Mock Test-TargetUserName { [PSCustomObject]@{ IsValid = $false; Message = 'unused' } }
|
||||
$window = New-TestWindow
|
||||
$userCombo = New-UserSelectionCombo -SelectedIndex 0
|
||||
$usernameBox = New-Object System.Windows.Controls.TextBox
|
||||
$message = New-Object System.Windows.Controls.TextBlock
|
||||
$scopeCombo = New-AppRemovalScopeCombo -SelectedItemName 'AppRemovalScopeAllUsers'
|
||||
|
||||
Test-OtherUsername -Window $window -UserSelectionCombo $userCombo -OtherUsernameTextBox $usernameBox -UsernameValidationMessage $message -AppRemovalScopeCombo $scopeCombo | Should -BeTrue
|
||||
Should -Invoke Test-TargetUserName -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It 'validates when the deployment target is Other User' {
|
||||
Mock Test-TargetUserName { [PSCustomObject]@{ IsValid = $false; Message = 'Please enter a username' } }
|
||||
$window = New-TestWindow
|
||||
$userCombo = New-UserSelectionCombo -SelectedIndex 1
|
||||
$usernameBox = New-Object System.Windows.Controls.TextBox
|
||||
$usernameBox.Text = ''
|
||||
$message = New-Object System.Windows.Controls.TextBlock
|
||||
|
||||
Test-OtherUsername -Window $window -UserSelectionCombo $userCombo -OtherUsernameTextBox $usernameBox -UsernameValidationMessage $message | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'validates when the app-removal scope is Target user only, even if the deployment target is not Other User' {
|
||||
$window = New-TestWindow
|
||||
$userCombo = New-UserSelectionCombo -SelectedIndex 0
|
||||
$usernameBox = New-Object System.Windows.Controls.TextBox
|
||||
$usernameBox.Text = ' '
|
||||
$message = New-Object System.Windows.Controls.TextBlock
|
||||
$scopeCombo = New-AppRemovalScopeCombo -SelectedItemName 'AppRemovalScopeTargetUser'
|
||||
|
||||
Mock Test-TargetUserName { [PSCustomObject]@{ IsValid = $false; Message = 'Please enter a username' } }
|
||||
Test-OtherUsername -Window $window -UserSelectionCombo $userCombo -OtherUsernameTextBox $usernameBox -UsernameValidationMessage $message -AppRemovalScopeCombo $scopeCombo | Should -BeFalse
|
||||
|
||||
$usernameBox.Text = 'jdoe'
|
||||
Mock Test-TargetUserName { [PSCustomObject]@{ IsValid = $true; Message = 'User found: jdoe' } }
|
||||
Test-OtherUsername -Window $window -UserSelectionCombo $userCombo -OtherUsernameTextBox $usernameBox -UsernameValidationMessage $message -AppRemovalScopeCombo $scopeCombo | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user