Skip to content

Commit 78e54d6

Browse files
committed
feat: ✨ enhance Get-PreviewPanel functionality
* Updated `Get-PreviewPanel` to utilize `-Color` parameter in `Format-SpectrePanel`. * Refactored variable names for clarity and consistency. * Added debug logging for better traceability of function calls and parameters. * Implemented scrolling logic to manage the display of results effectively.
1 parent 2a43165 commit 78e54d6

File tree

5 files changed

+228
-25
lines changed

5 files changed

+228
-25
lines changed

PesterExplorer/Private/Get-ListPanel.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ function Get-ListPanel {
8989
}
9090
$results |
9191
Format-SpectreRows |
92-
Format-SpectrePanel -Header "[white]List[/]" -Expand $paneColor
92+
Format-SpectrePanel -Header "[white]List[/]" -Expand -Color $paneColor
9393
}

PesterExplorer/Private/Get-PreviewPanel.ps1

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ function Get-PreviewPanel {
5454
[Parameter(Mandatory)]
5555
[string]
5656
$SelectedItem,
57-
[Parameter()]
58-
[int]
5957
$ScrollPosition = 0,
6058
[Parameter()]
6159
[ValidateNotNull()]
@@ -65,6 +63,7 @@ function Get-PreviewPanel {
6563
$PreviewWidth,
6664
[string]$SelectedPane = "list"
6765
)
66+
Write-Debug "Get-PreviewPanel called with SelectedItem: $SelectedItem, ScrollPosition: $ScrollPosition"
6867
$paneColor = if($SelectedPane -ne "preview") {
6968
# If the selected pane is not preview, return an empty panel
7069
"blue"
@@ -81,95 +80,139 @@ function Get-PreviewPanel {
8180
Format-SpectrePanel -Header "[white]Preview[/]" -Expand -Color $paneColor
8281
}
8382
$object = $Items.Item($SelectedItem)
84-
$rows = @()
83+
$results = @()
8584
# SelectedItem can be a few different types:
8685
# - A Pester object (Run, Container, Block, Test)
8786

8887
#region Breakdown
8988
# Skip if the object is null or they are all zero.
9089
if (
90+
$null -ne $object.PassedCount -and
91+
$null -ne $object.InconclusiveCount -and
92+
$null -ne $object.SkippedCount -and
93+
$null -ne $object.FailedCount -and
9194
(
92-
$object.PassedCount +
93-
$object.InconclusiveCount +
94-
$object.SkippedCount +
95-
$object.FailedCount
95+
[int]$object.PassedCount +
96+
[int]$object.InconclusiveCount +
97+
[int]$object.SkippedCount +
98+
[int]$object.FailedCount
9699
) -gt 0
97100
) {
101+
Write-Debug "Adding breakdown chart for $($object.Name)"
98102
$data = @()
99103
$data += New-SpectreChartItem -Label "Passed" -Value ($object.PassedCount) -Color "Green"
100104
$data += New-SpectreChartItem -Label "Failed" -Value ($object.FailedCount) -Color "Red"
101105
$data += New-SpectreChartItem -Label "Inconclusive" -Value ($object.InconclusiveCount) -Color "Grey"
102106
$data += New-SpectreChartItem -Label "Skipped" -Value ($object.SkippedCount) -Color "Yellow"
103-
$result += Format-SpectreBreakdownChart -Data $data
107+
$results += Format-SpectreBreakdownChart -Data $data
104108
}
105109
#endregion Breakdown
106110

107111
# For Tests Let's print some more details
108112
if ($object.GetType().Name -eq "Test") {
113+
Write-Debug "Selected item is a Test: $($object.Name)"
109114
$formatSpectrePanelSplat = @{
110115
Header = "Test Result"
111116
Border = "Rounded"
112117
Color = "White"
113118
}
114-
$result += $object.Result |
119+
$results += $object.Result |
115120
Format-SpectrePanel @formatSpectrePanelSplat
116121
# Show the code tested
117122
$formatSpectrePanelSplat = @{
118123
Header = "Test Code"
119124
Border = "Rounded"
120125
Color = "White"
121126
}
122-
$result += $object.ScriptBlock |
127+
$results += $object.ScriptBlock |
123128
Get-SpectreEscapedText |
124129
Format-SpectrePanel @formatSpectrePanelSplat
125130
} else {
131+
Write-Debug "Selected item is a Pester object: $($object.Name)"
126132
$data = Format-PesterTreeHash -Object $object
127133
Write-Debug $($data|ConvertTo-Json -Depth 10)
128134
$formatSpectrePanelSplat = @{
129135
Header = "Results"
130136
Border = "Rounded"
131137
Color = "White"
132138
}
133-
$result += Format-SpectreTree -Data $data |
139+
$results += Format-SpectreTree -Data $data |
134140
Format-SpectrePanel @formatSpectrePanelSplat
135141
}
136142

137143
if($null -ne $object.StandardOutput){
144+
Write-Debug "Adding standard output for $($object.Name)"
138145
$formatSpectrePanelSplat = @{
139146
Header = "Standard Output"
140147
Border = "Ascii"
141148
Color = "White"
142149
}
143-
$result += $object.StandardOutput |
150+
$results += $object.StandardOutput |
144151
Get-SpectreEscapedText |
145152
Format-SpectrePanel @formatSpectrePanelSplat
146153

147154
}
148155

149156
# Print errors if they exist.
150157
if($object.ErrorRecord.Count -gt 0) {
158+
Write-Debug "Adding error records for $($object.Name)"
151159
$errorRecords = @()
152160
$object.ErrorRecord | ForEach-Object {
153161
$errorRecords += $_ |
154162
Format-SpectreException -ExceptionFormat ShortenEverything
155163
}
156-
$rows += $errorRecords | Format-SpectreRows | Format-SpectrePanel -Header "Errors" -Border "Rounded" -Color "Red"
164+
$results += $errorRecords | Format-SpectreRows | Format-SpectrePanel -Header "Errors" -Border "Rounded" -Color "Red"
157165
}
158166

159167
$formatSpectrePanelSplat = @{
160168
Header = "[white]Preview[/]"
161-
Width = $PreviewWidth
162-
Height = $PreviewHeight
163169
Color = $paneColor
164-
}
165-
166-
$formatScrollableSpectrePanelSplat = @{
167170
Height = $PreviewHeight
168171
Width = $PreviewWidth
169-
ScrollPosition = $ScrollPosition
170-
PanelSplat = $formatSpectrePanelSplat
171-
Data = $($rows | Format-SpectreRows)
172+
Expand = $true
173+
}
174+
175+
if($scrollPosition -ge $results.Count) {
176+
# If the scroll position is greater than the number of items,
177+
# reset it to the last item
178+
Write-Debug "Resetting ScrollPosition to last item."
179+
$scrollPosition = $results.Count - 1
180+
}
181+
# If the scroll position is out of bounds, reset it
182+
if ($scrollPosition -lt 0) {
183+
Write-Debug "Resetting ScrollPosition to 0."
184+
$scrollPosition = 0
185+
}
186+
187+
if($results.Count -eq 0) {
188+
# If there are no results, return an empty panel
189+
return "[grey]No results to display.[/]" |
190+
Format-SpectreAligned -HorizontalAlignment Center -VerticalAlignment Middle |
191+
Format-SpectrePanel @formatSpectrePanelSplat
192+
} else {
193+
Write-Debug "Reducing Preview List: $($results.Count), ScrollPosition: $scrollPosition"
194+
195+
# Determine the height of each item in the results
196+
$totalHeight = 0
197+
$reducedList = @()
198+
if($ScrollPosition -ne 0) {
199+
# If the scroll position is not zero, add a "back" item
200+
$reducedList += "[grey]...[/]"
201+
}
202+
for ($i = $scrollPosition; $i -le $array.Count; $i++) {
203+
$itemHeight = Get-SpectreRenderableSize $results[$i]
204+
$totalHeight += $itemHeight.Height
205+
if ($totalHeight -gt $PreviewHeight) {
206+
# If the total height exceeds the preview height, stop adding items
207+
Write-Debug "Total height exceeded preview height. Stopping at item $i."
208+
$reducedList += "[blue]...more. Switch to Panel and scroll with keys.[/]"
209+
break
210+
}
211+
$reducedList += $results[$i]
212+
}
172213
}
173214

174-
return $(Format-ScrollableSpectrePanel @formatScrollableSpectrePanelSplat)
215+
return $reducedList | Format-SpectreRows |
216+
Format-SpectrePanel @formatSpectrePanelSplat
217+
#Format-ScrollableSpectrePanel @formatScrollableSpectrePanelSplat
175218
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
function Get-PesterTestView {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
5+
[ValidateNotNullOrEmpty()]
6+
[Pester.Test[]]
7+
$Test
8+
)
9+
begin {
10+
$rows = @()
11+
}
12+
process {
13+
$Test | ForEach-Object {
14+
$object = $_
15+
if($null -eq $object) {
16+
return
17+
}
18+
19+
# Print the test name
20+
$formatSpectrePanelSplat = @{
21+
Header = "Test Name"
22+
Border = "Ascii"
23+
Color = "Cyan"
24+
}
25+
$rows += Format-PesterObjectName -Object $object |
26+
Format-SpectrePanel @formatSpectrePanelSplat
27+
28+
$formatSpectrePanelSplat = @{
29+
Header = "Test Result"
30+
Border = "Rounded"
31+
Color = "White"
32+
}
33+
$rows += $object.Result |
34+
Format-SpectrePanel @formatSpectrePanelSplat
35+
36+
# Show the code tested
37+
$formatSpectrePanelSplat = @{
38+
Header = "Test Code"
39+
Border = "Rounded"
40+
Color = "White"
41+
}
42+
$rows += $object.ScriptBlock |
43+
Get-SpectreEscapedText |
44+
Format-SpectrePanel @formatSpectrePanelSplat
45+
46+
if($null -ne $object.StandardOutput){
47+
$formatSpectrePanelSplat = @{
48+
Header = "Standard Output"
49+
Border = "Ascii"
50+
Color = "White"
51+
}
52+
53+
$rows += $object.StandardOutput |
54+
Get-SpectreEscapedText |
55+
Format-SpectrePanel @formatSpectrePanelSplat
56+
}
57+
58+
# Print errors if they exist.
59+
if($object.ErrorRecord.Count -gt 0) {
60+
$errorRecords = @()
61+
$formatSpectrePanelSplat = @{
62+
Header = "Errors"
63+
Border = "Rounded"
64+
Color = "Red"
65+
}
66+
$object.ErrorRecord | ForEach-Object {
67+
$errorRecords += $_ |
68+
Format-SpectreException -ExceptionFormat ShortenEverything
69+
}
70+
$rows += $errorRecords |
71+
Format-SpectreRows |
72+
Format-SpectrePanel @formatSpectrePanelSplat
73+
}
74+
}
75+
}
76+
end {
77+
return $rows
78+
}
79+
}

PesterExplorer/Public/Show-PesterResult.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,26 @@ function Show-PesterResult {
9595
if($selectedPane -eq 'list') {
9696
if ($lastKeyPressed.Key -eq "DownArrow") {
9797
$selectedItem = $list[($list.IndexOf($selectedItem) + 1) % $list.Count]
98+
$scrollPosition = 0
9899
} elseif ($lastKeyPressed.Key -eq "UpArrow") {
99100
$selectedItem = $list[($list.IndexOf($selectedItem) - 1 + $list.Count) % $list.Count]
101+
$scrollPosition = 0
100102
} elseif ($lastKeyPressed.Key -eq "PageDown") {
101103
$currentIndex = $list.IndexOf($selectedItem)
102104
$newIndex = [Math]::Min($currentIndex + 10, $list.Count - 1)
103105
$selectedItem = $list[$newIndex]
106+
$scrollPosition = 0
104107
} elseif ($lastKeyPressed.Key -eq "PageUp") {
105108
$currentIndex = $list.IndexOf($selectedItem)
106109
$newIndex = [Math]::Max($currentIndex - 10, $list.Count - 1)
107110
$selectedItem = $list[$newIndex]
111+
$scrollPosition = 0
108112
} elseif ($lastKeyPressed.Key -eq "Home") {
109113
$selectedItem = $list[0]
114+
$scrollPosition = 0
110115
} elseif ($lastKeyPressed.Key -eq "End") {
111116
$selectedItem = $list[-1]
117+
$scrollPosition = 0
112118
} elseif ($lastKeyPressed.Key -in @("Tab", "RightArrow")) {
113119
$selectedPane = 'preview'
114120
} elseif ($lastKeyPressed.Key -eq "Enter") {
@@ -155,10 +161,10 @@ function Show-PesterResult {
155161
$scrollPosition = $ScrollPosition - 1
156162
} elseif ($lastKeyPressed.Key -eq "PageDown") {
157163
# Scroll down by a page in the preview panel
158-
$scrollPosition = $ScrollPosition + 10
164+
$scrollPosition = $ScrollPosition + 1
159165
} elseif ($lastKeyPressed.Key -eq "PageUp") {
160166
# Scroll up by a page in the preview panel
161-
$scrollPosition = $ScrollPosition - 10
167+
$scrollPosition = $ScrollPosition - 1
162168
}
163169
#endregion Preview Navigation
164170
}

docs/en-US/Get-PesterTestView.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
external help file: PesterExplorer-help.xml
3+
Module Name: PesterExplorer
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-PesterTestView
9+
10+
## SYNOPSIS
11+
{{ Fill in the Synopsis }}
12+
13+
## SYNTAX
14+
15+
```
16+
Get-PesterTestView [-Test] <Test[]> [-ProgressAction <ActionPreference>] [<CommonParameters>]
17+
```
18+
19+
## DESCRIPTION
20+
{{ Fill in the Description }}
21+
22+
## EXAMPLES
23+
24+
### Example 1
25+
```powershell
26+
PS C:\> {{ Add example code here }}
27+
```
28+
29+
{{ Add example description here }}
30+
31+
## PARAMETERS
32+
33+
### -Test
34+
{{ Fill Test Description }}
35+
36+
```yaml
37+
Type: Test[]
38+
Parameter Sets: (All)
39+
Aliases:
40+
41+
Required: True
42+
Position: 0
43+
Default value: None
44+
Accept pipeline input: True (ByValue)
45+
Accept wildcard characters: False
46+
```
47+
48+
### -ProgressAction
49+
{{ Fill ProgressAction Description }}
50+
51+
```yaml
52+
Type: ActionPreference
53+
Parameter Sets: (All)
54+
Aliases: proga
55+
56+
Required: False
57+
Position: Named
58+
Default value: None
59+
Accept pipeline input: False
60+
Accept wildcard characters: False
61+
```
62+
63+
### CommonParameters
64+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
65+
66+
## INPUTS
67+
68+
### Pester.Test[]
69+
70+
## OUTPUTS
71+
72+
### System.Object
73+
## NOTES
74+
75+
## RELATED LINKS

0 commit comments

Comments
 (0)