winutil/pester/winutil.Tests.ps1
Chris Titus e2086e5ef7
Bugfixes before December (#465)
* Update Branch in script

* Pester Updates (#394)

* Update Branch in script

* Update Branch in script

* remove redundant test pipeline

* update unit tests

* remove tests for features not yet implemented

* test

* update tests

* test pipeline

* test pipeline

* test pipeline

* test pipeline

* test pipeline

* test pipeline

* update tests

* update pipeline

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>

* Update Branch in script

* Move preset buttons to function (#396)

* Update Branch in script

* update set-presets

* Update Branch in script

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>

* Update Branch in script

* Require Admin and attempt relaunch (#395)

* Update Branch in script

* migrate admin check from runspace.ps1

* changed relaunch to use $BranchToUse

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>

* Update Branch in script

* Choco prep (#429)

* Update Branch in script

* update application file

* Update Branch in script

* update helper script and fix RevoUnInstaller

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>

* Update Branch in script

* Feature/simplelogging (#431)

* Update Branch in script

* added transcript for simple logging

* Update Branch in script

* Update winutil.ps1

* Update Branch in script

* Update runspace.ps1

* Update Branch in script

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>
Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>

* Update Branch in script

* Replaced Dark Theme Enable and Disable buttons with a toggle switch (#445)

* Replaced Dark Theme Enable and Disable button with a toggle switch

* Changed toggle switch background colour

Co-authored-by: Chris Titus <contact@christitus.com>

* Replace WMI calls (#450)

Co-authored-by: Chris Titus <contact@christitus.com>

* Fix Chocolatey installation detection (#452)

* Fix error

* Actually fix it this time

* Add comments

* Do it faster

Co-authored-by: Chris Titus <contact@christitus.com>

* 420/removeadmin (#462)

* Update Branch in script

* Remove Administrator Check

Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>

* Update Branch in script

* Update Branch in script

Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
Co-authored-by: DeveloperDurp <developerdurp@durp.info>
Co-authored-by: DeveloperDurp <DeveloperDurp@users.noreply.github.com>
Co-authored-by: Josh Ackland <joshackland@pm.me>
Co-authored-by: Carter <60557606+Carterpersall@users.noreply.github.com>
2022-11-29 17:54:18 -06:00

174 lines
6.7 KiB
PowerShell

#region Configurable Variables
<#
.NOTES
Use this section to configure testing variables. IE if the number of tabs change in the GUI update that variable here.
All variables need to be global to be passed between contexts
#>
$global:FormName = "Chris Titus Tech's Windows Utility"
#endregion Configurable Variables
#region Load Variables needed for testing
#Config Files
$global:configs = @{}
(
"applications"
) | ForEach-Object {
$global:configs["$PSItem"] = Get-Content .\config\$PSItem.json | ConvertFrom-Json
}
#GUI
$global:inputXML = get-content MainWindow.xaml
$global:inputXML = $global:inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
[xml]$global:XAML = $global:inputXML
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
$global:reader = (New-Object System.Xml.XmlNodeReader $global:xaml)
$global:Form = [Windows.Markup.XamlReader]::Load( $global:reader )
$global:xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name "Global:WPF$($_.Name)" -Value $global:Form.FindName($_.Name) -Scope global }
#dotsource original script to pull in all variables and ensure no errors
$script = Get-Content .\winutil.ps1
$output = $script[0..($script.count - 4)] | Out-File .\pester.ps1
#endregion Load Variables needed for testing
#===========================================================================
# Tests - Application Installs
#===========================================================================
Describe "Application Installs" {
Context "Application installs" {
It "Imports with no errors" {
$global:configs.Applications | should -Not -BeNullOrEmpty
}
}
Context "Winget Install" {
$global:configs.applications.install | Get-Member -MemberType NoteProperty | ForEach-Object {
$TestCase = @{ name = $psitem.name }
It "$($psitem.name) should include Winget Install" -TestCases $TestCase{
param($name)
$null -eq $global:configs.applications.install.$name.winget | should -Befalse -because "$name Did not include a Winget Install"
}
}
}
Context "GUI Applications Checkbox" {
(get-variable | Where-Object {$psitem.name -like "*install*" -and $psitem.value.GetType().name -eq "CheckBox"}).name -replace 'Global:','' | ForEach-Object {
$TestCase = @{ name = $psitem }
It "$($psitem) should include application.json " -TestCases $TestCase{
param($name)
$null -eq $global:configs.applications.install.$name | should -Befalse -because "$name Does not have entry in applications.json"
}
}
}
}
#===========================================================================
# Tests - Tweak Presets
#===========================================================================
Describe "Tweak Presets" {
Context "Json Import" {
It "Imports with no errors" {
$global:configs.preset | should -Not -BeNullOrEmpty
}
}
}
#===========================================================================
# Tests - GUI
#===========================================================================
Describe "GUI" {
Context "XML" {
It "Imports with no errors" {
$global:XAML | should -Not -BeNullOrEmpty
}
It "Title should be $global:FormName" {
$global:XAML.window.Title | should -Be $global:FormName
}
}
Context "Form" {
It "Imports with no errors" {
$global:Form | should -Not -BeNullOrEmpty
}
It "Title should match XML" {
$global:Form.title | should -Be $global:XAML.window.Title
}
}
}
#===========================================================================
# Tests - GUI Functions
#===========================================================================
Describe "GUI Functions" {
BeforeEach -Scriptblock {. ./pester.ps1}
It "GUI should load with no errors" {
$WPFTab1BT | should -Not -BeNullOrEmpty
$WPFundoall | should -Not -BeNullOrEmpty
$WPFPanelDISM | should -Not -BeNullOrEmpty
$WPFPanelAutologin | should -Not -BeNullOrEmpty
$WPFUpdatesdefault | should -Not -BeNullOrEmpty
$WPFFixesUpdate | should -Not -BeNullOrEmpty
$WPFUpdatesdisable | should -Not -BeNullOrEmpty
$WPFUpdatessecurity | should -Not -BeNullOrEmpty
$WPFFeatureInstall | should -Not -BeNullOrEmpty
$WPFundoall | should -Not -BeNullOrEmpty
$WPFDisableDarkMode | should -Not -BeNullOrEmpty
$WPFEnableDarkMode | should -Not -BeNullOrEmpty
$WPFtweaksbutton | should -Not -BeNullOrEmpty
$WPFminimal | should -Not -BeNullOrEmpty
$WPFlaptop | should -Not -BeNullOrEmpty
$WPFdesktop | should -Not -BeNullOrEmpty
$WPFInstallUpgrade | should -Not -BeNullOrEmpty
$WPFinstall | should -Not -BeNullOrEmpty
}
Context "Get-CheckBoxes" {
It "Get-CheckBoxes Install should return data" {
. .\pester.ps1
$TestCheckBoxes = @(
"WPFInstallvc2015_32"
"WPFInstallvscode"
"WPFInstallgit"
)
$OutputResult = New-Object System.Collections.Generic.List[System.Object]
$TestCheckBoxes | ForEach-Object {
$global:configs.applications.Install.$psitem.winget -split ";" | ForEach-Object {
$OutputResult.Add($psitem)
}
}
$OutputResult = Sort-Object -InputObject $OutputResult
$TestCheckBoxes | ForEach-Object {(Get-Variable $PSItem).value.ischecked = $true}
$Output = Get-CheckBoxes -Group WPFInstall | Sort-Object
$Output | should -Not -BeNullOrEmpty -Because "Output did not containe applications to install"
$Output | Should -Not -Be $OutputResult -Because "Output contains duplicate values"
$Output | Should -Be $($OutputResult | Select-Object -Unique | Sort-Object) -Because "Output doesn't match"
$TestCheckBoxes | ForEach-Object {(Get-Variable $PSItem).value.ischecked | should -be $false}
}
Context "Set-Presets" {
$global:configs.preset | Get-Member -MemberType NoteProperty | ForEach-Object {
$TestCase = @{ name = $psitem.name }
It "preset $($psitem.name) should modify the correct values" -TestCases $TestCase {
param($name)
Set-Presets $name
get-variable $global:configs.preset.$name | Select-Object -ExpandProperty value | Select-Object -ExpandProperty ischecked | Where-Object {$psitem -eq $false} | should -BeNullOrEmpty
}
}
}
}