From b191f16e3e4f7e276dc3633d1b40b4daf8e72e30 Mon Sep 17 00:00:00 2001 From: Thomas Hofkens Date: Sat, 12 Nov 2022 00:26:19 +0100 Subject: [PATCH] Updated Tests --- __tests__/Export-Excel.Tests.ps1 | 26 +++++++++++++------ .../Set-Row_Set-Column-SetFormat.tests.ps1 | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index e1c8be1..a964cce 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -692,15 +692,17 @@ Describe ExportExcel -Tag "ExportExcel" { $processes = Get-Process | Where-Object { $_.StartTime } | Select-Object -First 50 # Export as table with a totals row with a set of possibilities - $TotalSettings = @{ + $TableTotalSettings = @{ Id = "COUNT" WS = "SUM" Handles = "AVERAGE" - CPU = @{ - Custom = '=COUNTIF([CPU];"<1")' + CPU = '=COUNTIF([CPU];"<1")' + NPM = @{ + Function = '=SUMIF([Name];"=Chrome";[NPM])' + Comment = "Sum of Non-Paged Memory (NPM) for all chrome processes" } } - $Processes | Export-Excel $path -TableName "processes" -TotalSettings $TotalSettings + $Processes | Export-Excel $path -TableName "processes" -TableTotalSettings $TableTotalSettings $TotalRows = $Processes.count + 2 # Column header + Data (50 processes) + Totals row $Excel = Open-ExcelPackage -Path $path $ws = $Excel.Workbook.Worksheets[1] @@ -716,22 +718,30 @@ Describe ExportExcel -Tag "ExportExcel" { $WScolumn = $ws.Tables[0].Columns | Where-Object { $_.Name -eq "WS" } $HandlesColumn = $ws.Tables[0].Columns | Where-Object { $_.Name -eq "Handles" } $CPUColumn = $ws.Tables[0].Columns | Where-Object { $_.Name -eq "CPU" } + $NPMColumn = $ws.Tables[0].Columns | Where-Object { $_.Name -eq "NPM" } + # Testing column properties $IDcolumn | Select-Object -ExpandProperty TotalsRowFunction | Should -Be "Count" $WScolumn | Select-Object -ExpandProperty TotalsRowFunction | Should -Be "Sum" $HandlesColumn | Select-Object -ExpandProperty TotalsRowFunction | Should -Be "Average" $CPUColumn | Select-Object -ExpandProperty TotalsRowFunction | Should -Be "Custom" $CPUColumn | Select-Object -ExpandProperty TotalsRowFormula | Should -Be 'COUNTIF([CPU],"<1")' + $NPMColumn | Select-Object -ExpandProperty TotalsRowFunction | Should -Be "Custom" + $NPMColumn | Select-Object -ExpandProperty TotalsRowFormula | Should -Be 'SUMIF([Name],"=Chrome",[NPM])' + # Testing actual cell properties $CountAddress = "{0}{1}" -f (Get-ExcelColumnName -ColumnNumber $IDcolumn.Id).ColumnName, $TotalRows $SumAddress = "{0}{1}" -f (Get-ExcelColumnName -ColumnNumber $WScolumn.Id).ColumnName, $TotalRows $AverageAddress = "{0}{1}" -f (Get-ExcelColumnName -ColumnNumber $HandlesColumn.Id).ColumnName, $TotalRows $CustomAddress = "{0}{1}" -f (Get-ExcelColumnName -ColumnNumber $CPUColumn.Id).ColumnName, $TotalRows + $CustomCommentAddress = "{0}{1}" -f (Get-ExcelColumnName -ColumnNumber $NPMColumn.Id).ColumnName, $TotalRows - $ws.Cells[$CountAddress].Formula | Should -Be "SUBTOTAL(103,processes[Id])" - $ws.Cells[$SumAddress].Formula | Should -Be "SUBTOTAL(109,processes[Ws])" - $ws.Cells[$AverageAddress].Formula | Should -Be "SUBTOTAL(101,processes[Handles])" - $ws.Cells[$CustomAddress].Formula | Should -Be 'COUNTIF([CPU],"<1")' + $ws.Cells[$CountAddress].Formula | Should -Be "SUBTOTAL(103,processes[Id])" + $ws.Cells[$SumAddress].Formula | Should -Be "SUBTOTAL(109,processes[Ws])" + $ws.Cells[$AverageAddress].Formula | Should -Be "SUBTOTAL(101,processes[Handles])" + $ws.Cells[$CustomAddress].Formula | Should -Be 'COUNTIF([CPU],"<1")' + $ws.Cells[$CustomCommentAddress].Formula | Should -Be 'SUMIF([Name],"=Chrome",[NPM])' + $ws.Cells[$CustomCommentAddress].Comment.Text | Should -Not -BeNullOrEmpty } AfterEach { diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index 56bf571..19c1ebb 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -392,7 +392,7 @@ Describe "Table Formatting" { $excel = $data2 | Export-excel -path $path -WorksheetName Hardware -AutoNameRange -AutoSize -BoldTopRow -FreezeTopRow -PassThru $ws = $excel.Workbook.Worksheets[1] #test showfilter & TotalSettings - $Table = Add-ExcelTable -PassThru -Range $ws.Cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName HardwareTable -TotalSettings @{"Total" = "Sum"} -ShowFirstColumn -ShowFilter:$false + $Table = Add-ExcelTable -PassThru -Range $ws.Cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName HardwareTable -TableTotalSettings @{"Total" = "Sum"} -ShowFirstColumn -ShowFilter:$false #test expnading named number formats Set-ExcelColumn -Worksheet $ws -Column 4 -NumberFormat 'Currency' Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency'