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:
@@ -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