mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-10-08 06:26:45 +00:00
Add localization framework for the GUI (en-US baseline) (#764)
Credit to @jmolinap2 for their work in #643, which was used as inspiration.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
BeforeAll {
|
||||
function Show-MessageBox { param($Message, $Title, $Button, $Icon, $Owner) 'Yes' }
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Confirm-UnsafeAppRemoval.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Confirm-UnsafeAppRemoval' {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
BeforeAll {
|
||||
$friendlyTargetScriptPath = Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-FriendlyRegistryBackupTarget.ps1'
|
||||
. $friendlyTargetScriptPath
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Get-FriendlyRegistryBackupTarget' {
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
BeforeAll {
|
||||
$rebootFeatureLabelsScriptPath = Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RebootFeatureLabels.ps1'
|
||||
. $rebootFeatureLabelsScriptPath
|
||||
. (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]@{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-RebootFeatureLabels' {
|
||||
@@ -18,6 +41,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
UndoFeature = [PSCustomObject]@{ RequiresReboot = $true; Label = 'Undoable feature'; UndoLabel = 'Undo feature' }
|
||||
NoRebootFeature = [PSCustomObject]@{ RequiresReboot = $false; Label = 'No reboot'; UndoLabel = 'Undo no reboot' }
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
}
|
||||
|
||||
It 'includes reboot-required selections once and uses undo labels for undo operations' {
|
||||
@@ -43,6 +67,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
$script:Params = @{}
|
||||
$script:UndoParams = @{ ApplyFeature = $true }
|
||||
$script:Features.ApplyFeature.UndoLabel = $null
|
||||
Sync-TestLangFeatures
|
||||
|
||||
$result = @(Get-RebootFeatureLabels)
|
||||
|
||||
@@ -57,6 +82,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
RequiresReboot = $true
|
||||
Label = 'Feature without undo label'
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
|
||||
$result = @(Get-RebootFeatureLabels)
|
||||
|
||||
@@ -87,6 +113,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
Label = 'Shared label'
|
||||
UndoLabel = 'Undo second shared label'
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
|
||||
$result = @(Get-RebootFeatureLabels)
|
||||
|
||||
@@ -110,6 +137,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
Label = 'Numeric reboot'
|
||||
UndoLabel = 'Undo numeric reboot'
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
|
||||
$result = @(Get-RebootFeatureLabels)
|
||||
|
||||
@@ -130,6 +158,7 @@ Describe 'Get-RebootFeatureLabels' {
|
||||
Label = ' '
|
||||
UndoLabel = $null
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
|
||||
@(Get-RebootFeatureLabels).Count | Should -Be 0
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
BeforeAll {
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Import-ConfigToParams.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Test-ConfigConsistency.ps1')
|
||||
$script:ConfigFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.WithSettings.json'
|
||||
$script:SkipRegistryBackupFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.SkipRegistryBackup.json'
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Import-ConfigToParams' {
|
||||
|
||||
@@ -42,4 +42,17 @@ Describe 'Import-JsonFile' {
|
||||
$result | Should -BeNullOrEmpty
|
||||
Should -Invoke Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It 'reads non-ASCII characters correctly from a UTF-8 file with no BOM, regardless of the system default encoding' {
|
||||
# Unicode escapes here, not literal accented characters: this test file has no BOM, so
|
||||
# PowerShell 5.1 would decode literal non-ASCII source characters using the system default
|
||||
# codepage too, defeating the point of the assertion on a non-UTF-8-default machine.
|
||||
$expectedName = "Espa$([char]0x00F1)ol"
|
||||
$expectedNote = "caf$([char]0x00E9), na$([char]0x00EF)ve, $([char]0x00FC)ber"
|
||||
|
||||
$result = Import-JsonFile -filePath (Join-Path $script:FixturePath 'Config.Utf8NoBom.json')
|
||||
|
||||
$result.Name | Should -Be $expectedName
|
||||
$result.Note | Should -Be $expectedNote
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
BeforeAll {
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot 'TestData\LanguageLoading'
|
||||
}
|
||||
|
||||
Describe 'Resolve-LanguageFolder' {
|
||||
It 'resolves <Case>' -ForEach @(
|
||||
@{ Case = 'an exact match'; LanguageCode = 'en-US'; Expected = 'en-US' }
|
||||
@{ Case = 'a second exact match'; LanguageCode = 'es-ES'; Expected = 'es-ES' }
|
||||
@{ Case = 'a language-prefix match when no exact folder exists'; LanguageCode = 'es-AR'; Expected = 'es-ES' }
|
||||
@{ Case = 'an unrelated locale to the en-US fallback'; LanguageCode = 'fr-FR'; Expected = 'en-US' }
|
||||
) {
|
||||
Resolve-LanguageFolder -LanguageCode $LanguageCode | Should -Be $Expected
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Import-LanguageFile' {
|
||||
It 'loads all three JSON files for the resolved language' {
|
||||
$lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
|
||||
$lang.LanguageCode | Should -Be 'en-US'
|
||||
$lang.Chrome.TitleBarClose | Should -Be 'Close'
|
||||
$lang.Features.DisableTelemetry.Label | Should -Be 'Disable telemetry'
|
||||
$lang.Categories.PrivacySuggestedContent.Label | Should -Be 'Privacy & Suggested Content'
|
||||
}
|
||||
|
||||
It 'attaches an en-US Fallback when a non-en-US language is loaded' {
|
||||
$lang = Import-LanguageFile -LanguageCode 'es-ES'
|
||||
|
||||
$lang.LanguageCode | Should -Be 'es-ES'
|
||||
$lang.Fallback.LanguageCode | Should -Be 'en-US'
|
||||
}
|
||||
|
||||
It 'does not attach a Fallback when en-US itself is loaded' {
|
||||
$lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
|
||||
$lang.PSObject.Properties['Fallback'] | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'falls back to en-US without warning when the requested language has no folder at all' {
|
||||
# Resolve-LanguageFolder already resolves a nonexistent language straight to 'en-US',
|
||||
# so there's no real fallback to warn about here, unlike the broken-folder case below.
|
||||
Mock Write-Warning {}
|
||||
|
||||
$lang = Import-LanguageFile -LanguageCode 'fr-FR'
|
||||
|
||||
$lang.LanguageCode | Should -Be 'en-US'
|
||||
Should -Invoke Write-Warning -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It 'warns and falls back to en-US when the requested language folder exists but fails to load' {
|
||||
Mock Write-Warning {}
|
||||
Mock Write-Error {}
|
||||
|
||||
$languagesPath = Join-Path $TestDrive 'WithWorkingFallback'
|
||||
$brokenFolder = Join-Path $languagesPath 'xx-XX'
|
||||
New-Item -ItemType Directory -Path $brokenFolder | Out-Null
|
||||
'not valid json' | Out-File (Join-Path $brokenFolder 'Chrome.json')
|
||||
|
||||
$enUsFolder = Join-Path $languagesPath 'en-US'
|
||||
Copy-Item -Path (Join-Path $PSScriptRoot 'TestData\LanguageLoading\en-US') -Destination $enUsFolder -Recurse
|
||||
|
||||
$lang = Import-LanguageFile -LanguageCode 'xx-XX' -LanguagesPath $languagesPath
|
||||
|
||||
$lang.LanguageCode | Should -Be 'en-US'
|
||||
Should -Invoke Write-Warning -ParameterFilter { $Message -match "Failed to load language 'xx-XX'" } -Times 1 -Exactly
|
||||
# The broken xx-XX folder is still expected to report load errors; the fallback en-US load itself must not.
|
||||
Should -Invoke Write-Error -ParameterFilter { $Message -match 'Unable to load the en-US language files' } -Times 0
|
||||
}
|
||||
|
||||
It 'returns null and reports an error when the requested language fails and en-US is unavailable too' {
|
||||
Mock Write-Warning {}
|
||||
Mock Write-Error {}
|
||||
|
||||
$languagesPath = Join-Path $TestDrive 'WithoutFallback'
|
||||
$brokenFolder = Join-Path $languagesPath 'xx-XX'
|
||||
New-Item -ItemType Directory -Path $brokenFolder | Out-Null
|
||||
'not valid json' | Out-File (Join-Path $brokenFolder 'Chrome.json')
|
||||
|
||||
$lang = Import-LanguageFile -LanguageCode 'xx-XX' -LanguagesPath $languagesPath
|
||||
|
||||
$lang | Should -BeNullOrEmpty
|
||||
Should -Invoke Write-Warning -ParameterFilter { $Message -match "Failed to load language 'xx-XX'" } -Times 1 -Exactly
|
||||
}
|
||||
|
||||
It 'reports an error and returns null when en-US itself cannot be loaded' {
|
||||
Mock Write-Error {}
|
||||
|
||||
$lang = Import-LanguageFile -LanguageCode 'en-US' -LanguagesPath $TestDrive
|
||||
|
||||
$lang | Should -BeNullOrEmpty
|
||||
Should -Invoke Write-Error -ParameterFilter { $Message -match 'Unable to load the en-US language files' } -Times 1 -Exactly
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-PluralCategory' {
|
||||
It 'returns <Expected> for a count of <Count>' -ForEach @(
|
||||
@{ Count = 0; Expected = 'other' }
|
||||
@{ Count = 1; Expected = 'one' }
|
||||
@{ Count = 2; Expected = 'other' }
|
||||
@{ Count = 5; Expected = 'other' }
|
||||
) {
|
||||
Get-PluralCategory -LanguageCode 'en-US' -Count $Count | Should -Be $Expected
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-Translation' {
|
||||
BeforeAll {
|
||||
$script:EnLang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
$script:EsLang = Import-LanguageFile -LanguageCode 'es-ES'
|
||||
}
|
||||
|
||||
It 'looks up a flat Chrome key' {
|
||||
Get-Translation -Key 'TitleBarClose' -Lang $script:EnLang | Should -Be 'Close'
|
||||
}
|
||||
|
||||
It 'looks up a Field on a Features entry' {
|
||||
Get-Translation -Key 'DisableTelemetry' -Field 'Label' -Lang $script:EnLang | Should -Be 'Disable telemetry'
|
||||
Get-Translation -Key 'DisableTelemetry' -Field 'ToolTip' -Lang $script:EnLang | Should -Be 'Disables telemetry collection.'
|
||||
}
|
||||
|
||||
It 'looks up a Field on a Categories entry' {
|
||||
Get-Translation -Key 'PrivacySuggestedContent' -Field 'Label' -Lang $script:EnLang | Should -Be 'Privacy & Suggested Content'
|
||||
}
|
||||
|
||||
It 'looks up a Field on a UiGroups entry' {
|
||||
Get-Translation -Key 'SearchIcon' -Field 'Label' -Lang $script:EnLang | Should -Be 'Taskbar search style'
|
||||
}
|
||||
|
||||
It 'resolves the correct section for a key that exists as both a FeatureId and a GroupId' {
|
||||
# ClearStart is a real collision in Config/Features.json: a FeatureId ("remove for this
|
||||
# user only") and a GroupId (the combo heading above it) that share the same string.
|
||||
# Mirrored in the TestData fixture above so this test doesn't depend on production content.
|
||||
Get-Translation -Key 'ClearStart' -Field 'Label' -Section 'Features' -Lang $script:EnLang | Should -Be 'Remove for the selected user'
|
||||
Get-Translation -Key 'ClearStart' -Field 'Label' -Section 'UiGroups' -Lang $script:EnLang | Should -Be 'Remove pinned apps from the start menu'
|
||||
Get-Translation -Key 'ClearStart' -Field 'ToolTip' -Section 'UiGroups' -Lang $script:EnLang | Should -Be 'This setting allows you to quickly remove all pinned apps from the start menu.'
|
||||
}
|
||||
|
||||
It 'returns the key itself when no language has it' {
|
||||
Get-Translation -Key 'NoSuchKeyAnywhere' -Lang $script:EnLang | Should -Be 'NoSuchKeyAnywhere'
|
||||
}
|
||||
|
||||
It 'returns the key itself when the field is missing on an entry that exists' {
|
||||
Get-Translation -Key 'DisableTelemetry' -Field 'UndoLabel' -Lang $script:EnLang | Should -Be 'DisableTelemetry'
|
||||
}
|
||||
|
||||
It 'falls back to en-US for a key missing from the active language' {
|
||||
Get-Translation -Key 'TitleBarOptions' -Lang $script:EsLang | Should -Be 'Options'
|
||||
}
|
||||
|
||||
It 'prefers the active language over the fallback when both have the key' {
|
||||
Get-Translation -Key 'TitleBarClose' -Lang $script:EsLang | Should -Be 'Cerrar'
|
||||
}
|
||||
|
||||
It 'resolves a plural-suffixed key by count, falling back to the bare key' {
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 1 -Lang $script:EnLang | Should -Be '{0} app selected'
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 5 -Lang $script:EnLang | Should -Be '{0} apps selected'
|
||||
}
|
||||
|
||||
It 'substitutes FormatArgs into the resolved string' {
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 1 -FormatArgs @(1) -Lang $script:EnLang | Should -Be '1 app selected'
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 5 -FormatArgs @(5) -Lang $script:EnLang | Should -Be '5 apps selected'
|
||||
}
|
||||
|
||||
It 'substitutes a zero FormatArgs value instead of treating the array as falsy' {
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 0 -FormatArgs @(0) -Lang $script:EnLang | Should -Be '0 apps selected'
|
||||
}
|
||||
|
||||
It 'returns the unformatted string instead of throwing when FormatArgs is empty' {
|
||||
Get-Translation -Key 'AppsSelectedCount' -Count 1 -FormatArgs @() -Lang $script:EnLang | Should -Be '{0} app selected'
|
||||
}
|
||||
|
||||
It 'warns and returns the unformatted string instead of throwing on a placeholder/argument count mismatch' {
|
||||
Mock Write-Warning {}
|
||||
|
||||
$result = Get-Translation -Key 'TooManyPlaceholders' -FormatArgs @('only one arg') -Lang $script:EnLang
|
||||
|
||||
$result | Should -Be 'Value is {0} and {1}'
|
||||
Should -Invoke Write-Warning -ParameterFilter { $Message -match 'TooManyPlaceholders' } -Times 1 -Exactly
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Test-LanguageKeyCoverage' {
|
||||
It 'reports no missing or extra keys when a language is compared against itself' {
|
||||
$coverage = Test-LanguageKeyCoverage -LanguageCode 'en-US'
|
||||
|
||||
$coverage.MissingKeys | Should -BeNullOrEmpty
|
||||
$coverage.ExtraKeys | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'flags every key missing from a partially translated language' {
|
||||
$coverage = Test-LanguageKeyCoverage -LanguageCode 'es-ES'
|
||||
|
||||
$coverage.MissingKeys | Should -Contain 'TitleBarOptions'
|
||||
$coverage.MissingKeys | Should -Contain 'AppsSelectedCount_one'
|
||||
$coverage.MissingKeys | Should -Contain 'AppsSelectedCount_other'
|
||||
$coverage.MissingKeys | Should -Contain 'Features.DisableTelemetry.Label'
|
||||
$coverage.MissingKeys | Should -Contain 'Features.DisableTelemetry.ToolTip'
|
||||
$coverage.MissingKeys | Should -Contain 'UiGroups.SearchIcon.Label'
|
||||
$coverage.MissingKeys | Should -Contain 'Categories.PrivacySuggestedContent.Label'
|
||||
$coverage.ExtraKeys | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'does not flag a key the target language already has' {
|
||||
$coverage = Test-LanguageKeyCoverage -LanguageCode 'es-ES'
|
||||
|
||||
$coverage.MissingKeys | Should -Not -Contain 'TitleBarClose'
|
||||
}
|
||||
|
||||
It 'resolves a regional variant to its language-prefix match instead of erroring' {
|
||||
$coverage = Test-LanguageKeyCoverage -LanguageCode 'es-AR'
|
||||
|
||||
$coverage.ResolvedLanguageCode | Should -Be 'es-ES'
|
||||
$coverage.MissingKeys | Should -Contain 'TitleBarOptions'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'ConvertTo-LocalizedXaml' {
|
||||
BeforeAll {
|
||||
$script:EnLang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
$script:EsLang = Import-LanguageFile -LanguageCode 'es-ES'
|
||||
}
|
||||
|
||||
It 'substitutes every marker and XML-escapes the resolved value' {
|
||||
$xaml = '<Button Content="%LANG:TitleBarClose%"/>'
|
||||
|
||||
ConvertTo-LocalizedXaml -Xaml $xaml -Lang $script:EnLang | Should -Be '<Button Content="Close"/>'
|
||||
}
|
||||
|
||||
It 'does not let one substituted value be re-matched by a later marker' {
|
||||
$xaml = '<a Text="%LANG:TitleBarOptions%"/><b Text="%LANG:TitleBarClose%"/>'
|
||||
|
||||
ConvertTo-LocalizedXaml -Xaml $xaml -Lang $script:EnLang | Should -Be '<a Text="Options"/><b Text="Close"/>'
|
||||
}
|
||||
|
||||
It 'throws when a marker key does not exist in any language' {
|
||||
$xaml = '<Button Content="%LANG:NoSuchKeyAnywhere%"/>'
|
||||
|
||||
{ ConvertTo-LocalizedXaml -Xaml $xaml -Lang $script:EnLang } | Should -Throw '*NoSuchKeyAnywhere*'
|
||||
}
|
||||
|
||||
It 'falls back to en-US instead of throwing for a key missing from a partially translated language' {
|
||||
$xaml = '<Button Content="%LANG:TitleBarOptions%"/>'
|
||||
|
||||
ConvertTo-LocalizedXaml -Xaml $xaml -Lang $script:EsLang | Should -Be '<Button Content="Options"/>'
|
||||
}
|
||||
|
||||
It 'throws rather than stringifying a Features/UiGroups/Categories entry used by mistake' {
|
||||
$xaml = '<TextBlock Text="%LANG:DisableTelemetry%"/>'
|
||||
|
||||
{ ConvertTo-LocalizedXaml -Xaml $xaml -Lang $script:EnLang } | Should -Throw '*DisableTelemetry*'
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,31 @@ BeforeAll {
|
||||
function Set-StoreSearchSuggestionsDisabledForAllUsers { $true }
|
||||
function Set-StoreSearchSuggestionsDisabled { param($StoreAppsDatabase) $true }
|
||||
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
|
||||
|
||||
# Builds a $script:Lang fixture whose Features section mirrors $script:Features exactly,
|
||||
# so Get-Translation resolves the same ApplyText/UndoLabel/ApplyUndoText text the fake
|
||||
# FeatureIds in this file's fixtures expect, without duplicating per-test lookup data.
|
||||
function Sync-TestLangFeatures {
|
||||
$langFeatures = @{}
|
||||
foreach ($featureId in $script:Features.Keys) {
|
||||
$feature = $script:Features[$featureId]
|
||||
$entry = @{}
|
||||
foreach ($field in 'ApplyText', 'UndoLabel', 'ApplyUndoText') {
|
||||
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]@{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Resolve-UndoRegFilePath' {
|
||||
@@ -62,6 +86,7 @@ Describe 'Invoke-FeatureApply' {
|
||||
ReplaceStartAllUsers = [PSCustomObject]@{ ApplyText = 'Replace Start all users'; RegistryKey = '' }
|
||||
DisableStoreSearchSuggestions = [PSCustomObject]@{ ApplyText = 'Disable Store suggestions'; RegistryKey = '' }
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
Mock Import-RegistryFile { $true }
|
||||
Mock Remove-SelectedApps { $true }
|
||||
Mock Invoke-ForceRemoveEdge { $true }
|
||||
@@ -238,6 +263,7 @@ Describe 'Invoke-ApplyFeatures' {
|
||||
One = [PSCustomObject]@{ ApplyText = 'Apply one' }
|
||||
Two = [PSCustomObject]@{ ApplyText = 'Apply two' }
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
$script:progressCalls = New-Object System.Collections.Generic.List[object]
|
||||
$script:ApplyProgressCallback = { param($Step, $Total, $Text) $script:progressCalls.Add(@($Step, $Total, $Text)) }
|
||||
Mock Invoke-FeatureApply { $true }
|
||||
@@ -283,6 +309,7 @@ Describe 'Invoke-UndoFeatures' {
|
||||
RegistryUndo = [PSCustomObject]@{ UndoLabel = 'Undo registry'; ApplyUndoText = 'Restoring registry'; RegistryUndoKey = 'undo.reg' }
|
||||
CustomUndo = [PSCustomObject]@{ UndoLabel = 'Undo custom'; ApplyUndoText = ''; RegistryUndoKey = '' }
|
||||
}
|
||||
Sync-TestLangFeatures
|
||||
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
|
||||
Mock Import-RegistryFile { $true }
|
||||
Mock Invoke-FeatureUndo { $true }
|
||||
|
||||
@@ -4,7 +4,11 @@ BeforeAll {
|
||||
function Enable-ComputerRestore { param($Drive) }
|
||||
function Get-ComputerRestorePoint {}
|
||||
function Checkpoint-Computer { param($Description, $RestorePointType) }
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-SystemRestorePoint.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Invoke-SystemRestorePoint' {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
BeforeAll {
|
||||
Add-Type -AssemblyName PresentationFramework
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-AppSelection.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Deployment.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Navigation.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-TweaksBuilder.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Set-WindowThemeResources.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
|
||||
function New-TestWindow {
|
||||
$window = New-Object System.Windows.Window
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
BeforeAll {
|
||||
function Get-RegistryBackupCapturePlans {}
|
||||
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Registry-BackupValidation.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Test-RegistryBackupMatchesSelectedFeatures' {
|
||||
|
||||
@@ -2,8 +2,12 @@ BeforeAll {
|
||||
$registryPathHelperScriptPath = Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1'
|
||||
$validationScriptPath = Join-Path $PSScriptRoot '..\Scripts\Features\Registry-BackupValidation.ps1'
|
||||
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. $registryPathHelperScriptPath
|
||||
. $validationScriptPath
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Get-NormalizedSelectedFeatureIdsFromBackup' {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
BeforeAll {
|
||||
function Get-UserDirectory { param($userName, $fileName, $exitIfPathNotFound) }
|
||||
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Replace-StartMenu.ps1')
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Get-StartMenuUserNameFromPath' {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
BeforeAll {
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Restore-BackupDialogFeatureLists.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
}
|
||||
|
||||
Describe 'New-RestoreDialogState' {
|
||||
@@ -9,6 +10,18 @@ Describe 'New-RestoreDialogState' {
|
||||
CustomFeature = [PSCustomObject]@{ Label = 'Custom feature'; Category = 'Privacy'; RegistryKey = '' }
|
||||
HiddenFeature = [PSCustomObject]@{ Label = 'Hidden feature'; Category = ''; RegistryKey = 'HiddenFeature.reg' }
|
||||
}
|
||||
|
||||
$script:Lang = [PSCustomObject]@{
|
||||
LanguageCode = 'en-US'
|
||||
Chrome = [PSCustomObject]@{ RestoreUnknownFeature = 'Unknown feature' }
|
||||
Features = [PSCustomObject]@{
|
||||
RegistryFeature = [PSCustomObject]@{ Label = 'Registry feature' }
|
||||
CustomFeature = [PSCustomObject]@{ Label = 'Custom feature' }
|
||||
HiddenFeature = [PSCustomObject]@{ Label = 'Hidden feature' }
|
||||
}
|
||||
UiGroups = [PSCustomObject]@{}
|
||||
Categories = [PSCustomObject]@{}
|
||||
}
|
||||
}
|
||||
|
||||
It 'creates a dialog state with the supplied values' {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
BeforeAll {
|
||||
function Test-RunningAsSystem { $false }
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-FriendlyRegistryBackupTarget.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Resolve-UserProfilePath.ps1')
|
||||
@@ -8,6 +10,8 @@ BeforeAll {
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Restore-RegistryApplyState.ps1')
|
||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Restore-RegistryBackup.ps1')
|
||||
$script:JsonFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading'
|
||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||
$script:Lang = Import-LanguageFile -LanguageCode 'en-US'
|
||||
}
|
||||
|
||||
Describe 'Import-RegistryBackup' {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"Name": "Español",
|
||||
"Note": "café, naïve, über"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"PrivacySuggestedContent": {
|
||||
"Label": "Privacy & Suggested Content"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"TitleBarClose": "Close",
|
||||
"TitleBarOptions": "Options",
|
||||
"AppsSelectedCount_one": "{0} app selected",
|
||||
"AppsSelectedCount_other": "{0} apps selected",
|
||||
"TooManyPlaceholders": "Value is {0} and {1}"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Features": {
|
||||
"DisableTelemetry": {
|
||||
"Label": "Disable telemetry",
|
||||
"ToolTip": "Disables telemetry collection."
|
||||
},
|
||||
"ClearStart": {
|
||||
"Label": "Remove for the selected user"
|
||||
}
|
||||
},
|
||||
"UiGroups": {
|
||||
"SearchIcon": {
|
||||
"Label": "Taskbar search style"
|
||||
},
|
||||
"ClearStart": {
|
||||
"Label": "Remove pinned apps from the start menu",
|
||||
"ToolTip": "This setting allows you to quickly remove all pinned apps from the start menu."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"TitleBarClose": "Cerrar"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"Features": {},
|
||||
"UiGroups": {}
|
||||
}
|
||||
@@ -54,9 +54,9 @@ Describe 'XAML UI contracts' {
|
||||
$applyWindow = Get-Content -LiteralPath (Join-Path $script:SchemaPath 'ApplyChangesWindow.xaml') -Raw
|
||||
$appWindow = Get-Content -LiteralPath (Join-Path $script:SchemaPath 'AppSelectionWindow.xaml') -Raw
|
||||
|
||||
$applyWindow | Should -Match 'AutomationProperties.Name="Cancel"'
|
||||
$applyWindow | Should -Match 'AutomationProperties.Name="Close"'
|
||||
$appWindow | Should -Match 'AutomationProperties.Name="Confirm"'
|
||||
$appWindow | Should -Match 'AutomationProperties.Name="Cancel"'
|
||||
$applyWindow | Should -Match 'AutomationProperties.Name="%LANG:ApplyCancelTooltip%"'
|
||||
$applyWindow | Should -Match 'AutomationProperties.Name="%LANG:TitleBarClose%"'
|
||||
$appWindow | Should -Match 'AutomationProperties.Name="%LANG:AppSelectionWindowConfirm%"'
|
||||
$appWindow | Should -Match 'AutomationProperties.Name="%LANG:AppSelectionWindowCancel%"'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user