2026-07-19 22:06:07 +02:00
|
|
|
BeforeAll {
|
|
|
|
|
$rebootFeatureLabelsScriptPath = Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RebootFeatureLabels.ps1'
|
|
|
|
|
. $rebootFeatureLabelsScriptPath
|
2026-10-27 23:08:46 +01:00
|
|
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
2026-09-10 21:18:43 +05:30
|
|
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
|
|
|
|
|
|
|
|
|
# Builds a $script:Lang fixture whose Features section mirrors $script:Features exactly,
|
|
|
|
|
# so Get-Translation resolves the same Label/UndoLabel text the test's fake FeatureIds expect.
|
|
|
|
|
function Sync-TestLangFeatures {
|
|
|
|
|
$langFeatures = @{}
|
|
|
|
|
foreach ($featureId in $script:Features.Keys) {
|
|
|
|
|
$feature = $script:Features[$featureId]
|
|
|
|
|
$entry = @{}
|
|
|
|
|
foreach ($field in 'Label', 'UndoLabel') {
|
|
|
|
|
if ($null -ne $feature.$field) { $entry[$field] = [string]$feature.$field }
|
|
|
|
|
}
|
|
|
|
|
$langFeatures[$featureId] = [PSCustomObject]$entry
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$script:Lang = [PSCustomObject]@{
|
|
|
|
|
LanguageCode = 'en-US'
|
|
|
|
|
Chrome = [PSCustomObject]@{}
|
|
|
|
|
Features = [PSCustomObject]$langFeatures
|
|
|
|
|
UiGroups = [PSCustomObject]@{}
|
|
|
|
|
Categories = [PSCustomObject]@{}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-19 22:06:07 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-27 23:08:46 +01:00
|
|
|
Describe 'Get-DeferredAppRemovalLabels' {
|
|
|
|
|
BeforeEach {
|
|
|
|
|
$script:AppsListFilePath = Join-Path $PSScriptRoot '..\Config\Apps.json'
|
|
|
|
|
$script:Lang = Import-LanguageFile -LanguageCode 'en-US' -LanguagesPath (Join-Path $PSScriptRoot '..\Config\Languages')
|
|
|
|
|
$script:WingetDeferredRemovals = @{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'returns one Edge label for <Ids>' -ForEach @(
|
|
|
|
|
@{ Ids = @('Microsoft.Edge', 'XPFFTQ037JWMHS') }
|
|
|
|
|
@{ Ids = @('XPFFTQ037JWMHS') }
|
|
|
|
|
) {
|
|
|
|
|
foreach ($id in $Ids) { $script:WingetDeferredRemovals[$id] = 'Alice' }
|
|
|
|
|
|
|
|
|
|
$labels = @(Get-DeferredAppRemovalLabels)
|
|
|
|
|
|
|
|
|
|
$labels | Should -HaveCount 1
|
|
|
|
|
$labels[0] | Should -BeExactly 'Microsoft Edge'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'retains other apps and unknown IDs alongside a grouped app' {
|
|
|
|
|
$script:WingetDeferredRemovals = @{ 'Microsoft.Edge' = 'Alice'; 'XPFFTQ037JWMHS' = 'Alice'; 'Microsoft.OneDrive' = 'Alice'; 'Unknown.App' = 'Alice' }
|
|
|
|
|
|
|
|
|
|
$labels = @(Get-DeferredAppRemovalLabels)
|
|
|
|
|
|
|
|
|
|
$labels | Should -HaveCount 3
|
|
|
|
|
$labels | Should -Contain 'Microsoft Edge'
|
|
|
|
|
$labels | Should -Contain 'Unknown.App'
|
|
|
|
|
$labels | Should -Contain (Get-Translation -Key 'Microsoft.OneDrive' -Field 'FriendlyName' -Section 'Apps')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'keeps distinct catalog apps even when their translated names match' {
|
|
|
|
|
Mock Import-JsonFile {
|
|
|
|
|
[PSCustomObject]@{ Apps = @(
|
|
|
|
|
[PSCustomObject]@{ AppId = @('First.App', 'First.Alias') }
|
|
|
|
|
[PSCustomObject]@{ AppId = 'Second.App' }
|
|
|
|
|
) }
|
|
|
|
|
}
|
|
|
|
|
$script:Lang.Apps = [PSCustomObject]@{
|
|
|
|
|
'First.App' = [PSCustomObject]@{ FriendlyName = 'Shared name' }
|
|
|
|
|
'Second.App' = [PSCustomObject]@{ FriendlyName = 'Shared name' }
|
|
|
|
|
}
|
|
|
|
|
$script:WingetDeferredRemovals = @{ 'First.App' = 'Alice'; 'First.Alias' = 'Alice'; 'Second.App' = 'Alice' }
|
|
|
|
|
|
|
|
|
|
$labels = @(Get-DeferredAppRemovalLabels)
|
|
|
|
|
|
|
|
|
|
$labels | Should -HaveCount 2
|
|
|
|
|
@($labels | Where-Object { $_ -eq 'Shared name' }).Count | Should -Be 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'returns no labels without deferred removals' {
|
|
|
|
|
@(Get-DeferredAppRemovalLabels) | Should -HaveCount 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 22:06:07 +02:00
|
|
|
Describe 'Get-RebootFeatureLabels' {
|
|
|
|
|
BeforeEach {
|
|
|
|
|
$script:Params = @{
|
|
|
|
|
ApplyFeature = $true
|
|
|
|
|
NoRebootFeature = $true
|
|
|
|
|
}
|
|
|
|
|
$script:UndoParams = @{
|
|
|
|
|
UndoFeature = $true
|
|
|
|
|
ApplyFeature = $true
|
|
|
|
|
}
|
|
|
|
|
$script:Features = @{
|
|
|
|
|
ApplyFeature = [PSCustomObject]@{ RequiresReboot = $true; Label = 'Apply feature'; UndoLabel = 'Undo apply feature' }
|
|
|
|
|
UndoFeature = [PSCustomObject]@{ RequiresReboot = $true; Label = 'Undoable feature'; UndoLabel = 'Undo feature' }
|
|
|
|
|
NoRebootFeature = [PSCustomObject]@{ RequiresReboot = $false; Label = 'No reboot'; UndoLabel = 'Undo no reboot' }
|
|
|
|
|
}
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-19 22:06:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'includes reboot-required selections once and uses undo labels for undo operations' {
|
2026-11-08 17:55:46 +01:00
|
|
|
foreach ($feature in $script:Features.Values) {
|
|
|
|
|
$feature.PSObject.Properties.Remove('Label')
|
|
|
|
|
$feature.PSObject.Properties.Remove('UndoLabel')
|
|
|
|
|
}
|
2026-07-19 22:06:07 +02:00
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 2
|
|
|
|
|
$result | Should -Contain 'Undo apply feature'
|
|
|
|
|
$result | Should -Contain 'Undo feature'
|
|
|
|
|
$result | Should -Not -Contain 'No reboot'
|
|
|
|
|
}
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
It 'uses the regular label for a forward-only selection' {
|
|
|
|
|
$script:Params = @{ ApplyFeature = $true }
|
|
|
|
|
$script:UndoParams = @{}
|
|
|
|
|
|
|
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 1
|
|
|
|
|
$result | Should -Contain 'Apply feature'
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 17:55:46 +01:00
|
|
|
It 'uses the translation key when an undo selection has no undo label' {
|
2026-07-25 20:05:49 +02:00
|
|
|
$script:Params = @{}
|
|
|
|
|
$script:UndoParams = @{ ApplyFeature = $true }
|
|
|
|
|
$script:Features.ApplyFeature.UndoLabel = $null
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 1
|
2026-11-08 17:55:46 +01:00
|
|
|
$result | Should -Contain 'ApplyFeature'
|
2026-07-25 20:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
2026-11-08 17:55:46 +01:00
|
|
|
It 'uses the translation key when the feature has no UndoLabel property' {
|
2026-07-25 20:05:49 +02:00
|
|
|
$script:Params = @{}
|
|
|
|
|
$script:UndoParams = @{ MissingUndoLabelFeature = $true }
|
|
|
|
|
$script:Features.MissingUndoLabelFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = $true
|
|
|
|
|
Label = 'Feature without undo label'
|
|
|
|
|
}
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 1
|
2026-11-08 17:55:46 +01:00
|
|
|
$result | Should -Contain 'MissingUndoLabelFeature'
|
2026-07-25 20:05:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'returns no labels when there are no selected parameters' {
|
|
|
|
|
$script:Params = @{}
|
|
|
|
|
$script:UndoParams = @{}
|
|
|
|
|
|
|
|
|
|
@(Get-RebootFeatureLabels).Count | Should -Be 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'keeps one label for each distinct reboot feature when their labels match' {
|
|
|
|
|
$script:Params = @{
|
|
|
|
|
FirstMatchingLabelFeature = $true
|
|
|
|
|
SecondMatchingLabelFeature = $true
|
|
|
|
|
}
|
|
|
|
|
$script:UndoParams = @{}
|
|
|
|
|
$script:Features.FirstMatchingLabelFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = $true
|
|
|
|
|
Label = 'Shared label'
|
|
|
|
|
UndoLabel = 'Undo first shared label'
|
|
|
|
|
}
|
|
|
|
|
$script:Features.SecondMatchingLabelFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = $true
|
|
|
|
|
Label = 'Shared label'
|
|
|
|
|
UndoLabel = 'Undo second shared label'
|
|
|
|
|
}
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 2
|
|
|
|
|
@($result | Where-Object { $_ -eq 'Shared label' }).Count | Should -Be 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'accepts truthy reboot flags' {
|
|
|
|
|
$script:Params = @{
|
|
|
|
|
StringRebootFeature = $true
|
|
|
|
|
NumericRebootFeature = $true
|
|
|
|
|
}
|
|
|
|
|
$script:UndoParams = @{}
|
|
|
|
|
$script:Features.StringRebootFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = 'true'
|
|
|
|
|
Label = 'String reboot'
|
|
|
|
|
UndoLabel = 'Undo string reboot'
|
|
|
|
|
}
|
|
|
|
|
$script:Features.NumericRebootFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = 1
|
|
|
|
|
Label = 'Numeric reboot'
|
|
|
|
|
UndoLabel = 'Undo numeric reboot'
|
|
|
|
|
}
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
$result = @(Get-RebootFeatureLabels)
|
|
|
|
|
|
|
|
|
|
$result | Should -HaveCount 2
|
|
|
|
|
$result | Should -Contain 'String reboot'
|
|
|
|
|
$result | Should -Contain 'Numeric reboot'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It 'excludes unknown, non-reboot, and blank-label selections' {
|
|
|
|
|
$script:Params = @{
|
|
|
|
|
UnknownFeature = $true
|
|
|
|
|
NoRebootFeature = $true
|
|
|
|
|
BlankLabelFeature = $true
|
|
|
|
|
}
|
|
|
|
|
$script:UndoParams = @{}
|
|
|
|
|
$script:Features.BlankLabelFeature = [PSCustomObject]@{
|
|
|
|
|
RequiresReboot = $true
|
|
|
|
|
Label = ' '
|
|
|
|
|
UndoLabel = $null
|
|
|
|
|
}
|
2026-09-10 21:18:43 +05:30
|
|
|
Sync-TestLangFeatures
|
2026-07-25 20:05:49 +02:00
|
|
|
|
|
|
|
|
@(Get-RebootFeatureLabels).Count | Should -Be 0
|
|
|
|
|
}
|
2026-07-19 22:06:07 +02:00
|
|
|
}
|