From a7c1f79a5fe3012470fbd2b54a0fd90ec1f57d03 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Sat, 31 May 2025 12:48:35 -0700 Subject: [PATCH] =?UTF-8?q?chore:=20=E2=9C=8F=EF=B8=8F=20update=20CHANGELO?= =?UTF-8?q?G=20and=20module=20version=20to=200.3.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added tests for different private commands. * Fixed for loop in `Get-PreviewPanel` to use the correct variable for scrolling. --- CHANGELOG.md | 10 ++++++++++ PesterExplorer/PesterExplorer.psd1 | 2 +- PesterExplorer/Private/Get-PreviewPanel.ps1 | 9 ++++----- tests/Get-PreviewPanel.tests.ps1 | 18 +++++++++--------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 250e448..437bfde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.2] 2025-05-31 + +### Added + +- Added tests for different private commands. + +### Fixed + +- Fixed for loop used to scroll which was using wrong variable. + ## [0.3.1] 2025-05-30 ### Added diff --git a/PesterExplorer/PesterExplorer.psd1 b/PesterExplorer/PesterExplorer.psd1 index 0e03106..246e872 100644 --- a/PesterExplorer/PesterExplorer.psd1 +++ b/PesterExplorer/PesterExplorer.psd1 @@ -12,7 +12,7 @@ RootModule = 'PesterExplorer.psm1' # Version number of this module. - ModuleVersion = '0.3.1' + ModuleVersion = '0.3.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PesterExplorer/Private/Get-PreviewPanel.ps1 b/PesterExplorer/Private/Get-PreviewPanel.ps1 index a05b12b..9042846 100644 --- a/PesterExplorer/Private/Get-PreviewPanel.ps1 +++ b/PesterExplorer/Private/Get-PreviewPanel.ps1 @@ -129,7 +129,7 @@ function Get-PreviewPanel { Get-SpectreEscapedText | Format-SpectrePanel @formatSpectrePanelSplat } else { - Write-Debug "Selected item is a Pester object: $($object.Name)" + Write-Debug "Selected item '$($object.Name)'is a Pester object: $($object.GetType().Name)" $data = Format-PesterTreeHash -Object $object Write-Debug $($data|ConvertTo-Json -Depth 10) $formatSpectrePanelSplat = @{ @@ -151,7 +151,6 @@ function Get-PreviewPanel { $results += $object.StandardOutput | Get-SpectreEscapedText | Format-SpectrePanel @formatSpectrePanelSplat - } # Print errors if they exist. @@ -200,13 +199,13 @@ function Get-PreviewPanel { # If the scroll position is not zero, add a "back" item $reducedList += "[grey]...[/]" } - for ($i = $scrollPosition; $i -le $array.Count; $i++) { + for ($i = $scrollPosition; $i -lt $results.Count; $i++) { $itemHeight = Get-SpectreRenderableSize $results[$i] $totalHeight += $itemHeight.Height if ($totalHeight -gt $PreviewHeight) { if($i -eq $scrollPosition) { # If the first item already exceeds the height, stop here - Write-Debug "First item exceeds preview height. Stopping." + Write-Debug "First item exceeds preview height. Stopping. Total Height: $totalHeight, Preview Height: $PreviewHeight" $reducedList += ":police_car_light:The next item is too large to display! Please resize your terminal.:police_car_light:" | Format-SpectreAligned -HorizontalAlignment Center -VerticalAlignment Middle | Format-SpectrePanel -Header ":police_car_light: [red]Warning[/]" -Color 'red' -Border Double @@ -214,7 +213,7 @@ function Get-PreviewPanel { } # If the total height exceeds the preview height, stop adding items Write-Debug "Total height exceeded preview height. Stopping at item $i." - $reducedList += "[blue]...more.[/] [grey]Switch to Panel and scroll with keys.[/]" + $reducedList += "[blue]...more. Switch to Panel and scroll with keys.[/]" break } $reducedList += $results[$i] diff --git a/tests/Get-PreviewPanel.tests.ps1 b/tests/Get-PreviewPanel.tests.ps1 index 4f88a74..70d8412 100644 --- a/tests/Get-PreviewPanel.tests.ps1 +++ b/tests/Get-PreviewPanel.tests.ps1 @@ -14,7 +14,7 @@ Describe 'Get-PreviewPanel' { InModuleScope $env:BHProjectName { $script:ContainerWidth = 80 - $script:ContainerHeight = 100 + $script:ContainerHeight = 200 $size = [Spectre.Console.Size]::new($containerWidth, $containerHeight) $script:renderOptions = [Spectre.Console.Rendering.RenderOptions]::new( [Spectre.Console.AnsiConsole]::Console.Profile.Capabilities, @@ -77,7 +77,8 @@ Describe 'Get-PreviewPanel' { It 'should print warning when the screen is too small' { InModuleScope $env:BHProjectName { $Items = Get-ListFromObject -Object $script:run.Containers[0].Blocks[0].Order[0] - $size = [Spectre.Console.Size]::new(80, 10) + $height = 5 + $size = [Spectre.Console.Size]::new(80, $height) $renderOptions = [Spectre.Console.Rendering.RenderOptions]::new( [Spectre.Console.AnsiConsole]::Console.Profile.Capabilities, $size @@ -85,7 +86,8 @@ Describe 'Get-PreviewPanel' { $getPreviewPanelSplat = @{ Items = $Items SelectedItem = 'Test1' - PreviewHeight = 5 + ScrollPosition = 1 + PreviewHeight = $height PreviewWidth = $script:ContainerWidth } $panel = Get-PreviewPanel @getPreviewPanelSplat @@ -100,14 +102,12 @@ Describe 'Get-PreviewPanel' { $getPreviewPanelSplat = @{ Items = $Items SelectedItem = 'Test1' - PreviewHeight = 100 - PreviewWidth = 100 + PreviewHeight = $script:ContainerHeight + PreviewWidth = $script:ContainerWidth } - Mock -CommandName 'Get-SpectreEscapedText' -Verifiable $panel = Get-PreviewPanel @getPreviewPanelSplat - #global:Get-RenderedText -panel $panel -renderOptions $renderOptions -containerWidth 100 | - # Should -BeLike 'Passed' - Should -Invoke Get-SpectreEscapedText -Exactly 1 -Scope It + global:Get-RenderedText -panel $panel -renderOptions $script:renderOptions -containerWidth $script:ContainerWidth | + Should -BeLike '*$true | Should -Be $true*' } } }