diff --git a/PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1 b/PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1 index e67ec692..bad088b1 100644 --- a/PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1 +++ b/PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1 @@ -99,9 +99,7 @@ foreach ($doc in $docs) { # Work out the tag to apply to the current help file $tag = $null - if ($content -like "*This is experimental*") { - $tag = "Experimental" - } elseif([string]::IsNullOrEmpty($created) -or ((Get-Date) - ([datetime]$created)).TotalDays -lt $recentThresholdDays) { + if([string]::IsNullOrEmpty($created) -or ((Get-Date) - ([datetime]$created)).TotalDays -lt $recentThresholdDays) { $tag = "New" } elseif ((((Get-Date) - ([datetime]$modified)).TotalDays -lt $recentThresholdDays) -and $ignoreUpdatesFor -notcontains $commandName) { $tag = "Updated" diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreAligned.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreAligned.snapshot.txt new file mode 100644 index 00000000..d938688f --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreAligned.snapshot.txt @@ -0,0 +1,7 @@ +╭──────────────────────────────────────────────────────────────────────────────╮ +│ │ +│ │ +│ testing panel │ +│ │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreColumns.Expanded.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreColumns.Expanded.snapshot.txt new file mode 100644 index 00000000..2bbfc5c9 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreColumns.Expanded.snapshot.txt @@ -0,0 +1,3 @@ +╭──────╮ ╭────────╮ ╭───────╮ +│ left │ │ middle │ │ right │ +╰──────╯ ╰────────╯ ╰───────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.CustomStyles.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.CustomStyles.snapshot.txt new file mode 100644 index 00000000..fad62af8 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.CustomStyles.snapshot.txt @@ -0,0 +1,7 @@ +ParameterBindingException: A parameter cannot be found that matches parameter  +name 'BadParam'. + at void CheckActionPreference(FunctionContext funcContext, Exception exception + ) + at int Run(InterpretedFrame frame) + at int Run(InterpretedFrame frame) + at int Run(InterpretedFrame frame) diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.snapshot.txt new file mode 100644 index 00000000..024bee91 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.snapshot.txt @@ -0,0 +1,7 @@ +ParameterBindingException: A parameter cannot be found that matches parameter  +name 'BadParam'. + at void CheckActionPreference(FunctionContext funcContext, Exception exception + ) + at int Run(InterpretedFrame frame) + at int Run(InterpretedFrame frame) + at int Run(InterpretedFrame frame) diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreGrid.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreGrid.snapshot.txt new file mode 100644 index 00000000..e96aad1b --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreGrid.snapshot.txt @@ -0,0 +1,8 @@ +Row 1, Col 1 Row 1, Col 2 Row 1, Col Row 1, Col Row 1, Col Row 1, Col + 3 4 5 6 +Row 2, Col 1 Row 2, Col 2 Row 2, Col Row 2, Col Row 2, Col Row 2, Col + 3 4 5 6 +Row 3, Col 1 Row 3, Col 2 Row 3, Col Row 3, Col Row 3, Col Row 3, Col + 3 4 5 6 +Row 4, Col 1 Row 4, Col 2 Row 4, Col Row 4, Col Row 4, Col Row 4, Col + 3 4 5 6 diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePadded.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePadded.snapshot.txt new file mode 100644 index 00000000..ec44cf46 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePadded.snapshot.txt @@ -0,0 +1,8 @@ +╭────────────────────────╮ +│ │ +│ │ +│ │ +│ │ +│ Item to pad │ +│ │ +╰────────────────────────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreRows.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreRows.snapshot.txt new file mode 100644 index 00000000..7145e3cd --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreRows.snapshot.txt @@ -0,0 +1,61 @@ +lorem +ipsum +dolor +sit +amet +consectetur +adipiscing +elit, +sed +do +eiusmod +tempor +incididunt +ut +labore +et +dolore +magna +aliqua. +Ut +enim +ad +minim +veniam, +quis +nostrud +exercitation +ullamco +laboris +nisi +ut +aliquip +ex +ea +commodo +consequat +duis +aute +irure +dolor +in +reprehenderit +in +voluptate +velit +esse +cillum +dolore +eu +fugiat +nulla +pariatur +excepteur +sint +occaecat +cupidatat +non +proident +sunt +in +culpa diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTextPath.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTextPath.snapshot.txt new file mode 100644 index 00000000..534d9aa5 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTextPath.snapshot.txt @@ -0,0 +1 @@ +C:/Windows/System32/cmd.exe \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/@snapshots/New-SpectreLayout.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/New-SpectreLayout.snapshot.txt new file mode 100644 index 00000000..76f2d96b --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/New-SpectreLayout.snapshot.txt @@ -0,0 +1,24 @@ +╭─panel 1 (align bottom right)─────────────────────────────────────────────────╮ +│ what │ +│ │ +│ │ +│ │ +│ │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯ +╭─panel 2──────────────────────────────╮╭─panel 3 (align middle center)────────╮ +│ hello row 2 ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ test │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +╰──────────────────────────────────────╯╰──────────────────────────────────────╯ \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreAligned.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreAligned.tests.ps1 new file mode 100644 index 00000000..8611aea0 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreAligned.tests.ps1 @@ -0,0 +1,33 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreAligned" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should align an item" { + $renderable = "testing" | Format-SpectreAligned -HorizontalAlignment Right + $renderable | Should -BeOfType [Spectre.Console.Align] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should align an item in a panel horizontally and vertically" { + $renderable = "testing panel" | Format-SpectreAligned -HorizontalAlignment Center -VerticalAlignment Middle | Format-SpectrePanel -Height 7 -Expand + $renderable | Should -BeOfType [Spectre.Console.Panel] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreAligned" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreColumns.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreColumns.tests.ps1 new file mode 100644 index 00000000..9f28acf1 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreColumns.tests.ps1 @@ -0,0 +1,48 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreColumns" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should format an array of strings into columns" { + $renderable = Format-SpectreColumns -Data @("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", + "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", + "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", + "commodo", "consequat", "duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", + "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", + "cupidatat", "non", "proident", "sunt", "in", "culpa") + $renderable | Should -BeOfType [Spectre.Console.Columns] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should expand items to fill the available space" { + $renderable = @("left", "middle", "right") | Foreach-Object { $_ | Format-SpectrePanel } | Format-SpectreColumns -Expand + $renderable | Should -BeOfType [Spectre.Console.Columns] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreColumns.Expanded" -Output $testConsole.Output } | Should -Not -Throw + } + + It "Should allow padding to be set" { + $renderable = @("left", "middle", "right") | Foreach-Object { $_ | Format-SpectrePanel } | Format-SpectreColumns -Padding 4 + $renderable | Should -BeOfType [Spectre.Console.Columns] + $renderable | Out-SpectreHost + $renderable.Padding.Top | Should -Be 4 + $renderable.Padding.Right | Should -Be 4 + $renderable.Padding.Bottom | Should -Be 4 + $renderable.Padding.Left | Should -Be 4 + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreException.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreException.tests.ps1 new file mode 100644 index 00000000..b5515717 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreException.tests.ps1 @@ -0,0 +1,63 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreException" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should format an error record" { + try { + Get-ChildItem -BadParam -ErrorAction Stop + } catch { + $_ | Should -BeOfType [System.Management.Automation.ErrorRecord] + $renderable = $_ | Format-SpectreException -ExceptionFormat ShortenEverything + } + $renderable | Should -BeOfType [Spectre.Console.Rows] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreException" -Output $testConsole.Output } | Should -Not -Throw + } + + It "Should format an exception" { + $testException = [System.Exception]::new("Test exception") + $renderable = Format-SpectreException -Exception $testException -ExceptionFormat ShortenEverything + $renderable | Should -BeOfType [Spectre.Console.Rows] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should format an exception with custom styles" { + try { + Get-ChildItem -BadParam -ErrorAction Stop + } catch { + $_ | Should -BeOfType [System.Management.Automation.ErrorRecord] + $renderable = Format-SpectreException -Exception $_ -ExceptionFormat ShortenEverything -ExceptionStyle @{ + Message = "Red" + Exception = "White" + Method = [Spectre.Console.Color]::Pink3 + ParameterType = "Grey69" + ParameterName = "Silver" + Parenthesis = "#ff0000" + Path = [Spectre.Console.Color]::Pink3 + LineNumber = "Blue" + Dimmed = "Grey" + NonEmphasized = "Red" + } + } + + $renderable | Should -BeOfType [Spectre.Console.Rows] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreException.CustomStyles" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreGrid.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreGrid.tests.ps1 new file mode 100644 index 00000000..b58f7163 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreGrid.tests.ps1 @@ -0,0 +1,37 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreGrid" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should format data in a grid" { + $rows = 4 + $cols = 6 + + $gridRows = @() + for ($row = 1; $row -le $rows; $row++) { + $columns = @() + for ($col = 1; $col -le $cols; $col++) { + $columns += "Row $row, Col $col" + } + $gridRows += New-SpectreGridRow $columns + } + + $renderable = $gridRows | Format-SpectreGrid + $renderable | Should -BeOfType [Spectre.Console.Grid] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreGrid" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectrePadded.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectrePadded.tests.ps1 new file mode 100644 index 00000000..36bc7efe --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectrePadded.tests.ps1 @@ -0,0 +1,47 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectrePadded" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should format data with padding around it" { + $renderable = "Item to pad" | Format-SpectrePadded -Padding 6 + $renderable | Should -BeOfType [Spectre.Console.Padder] + $renderable.Padding.Top | Should -Be 6 + $renderable.Padding.Left | Should -Be 6 + $renderable.Padding.Bottom | Should -Be 6 + $renderable.Padding.Right | Should -Be 6 + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should format data with padding around it with specific padding values" { + $renderable = "Item to pad" | Format-SpectrePadded -Top 4 -Left 10 -Right 1 -Bottom 1 + $renderable | Should -BeOfType [Spectre.Console.Padder] + $renderable.Padding.Top | Should -Be 4 + $renderable.Padding.Left | Should -Be 10 + $renderable.Padding.Bottom | Should -Be 1 + $renderable.Padding.Right | Should -Be 1 + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should format data with padding around it with expanded padding" { + $renderable = "Item to pad" | Format-SpectrePadded -Top 4 -Left 10 -Right 1 -Bottom 1 | Format-SpectrePanel + $renderable | Should -BeOfType [Spectre.Console.Panel] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectrePadded" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreRows.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreRows.tests.ps1 new file mode 100644 index 00000000..42fb6553 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreRows.tests.ps1 @@ -0,0 +1,30 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreRows" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should format an array of strings into rows" { + $renderable = Format-SpectreRows -Data @("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", + "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", + "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", + "commodo", "consequat", "duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", + "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", + "cupidatat", "non", "proident", "sunt", "in", "culpa") + $renderable | Should -BeOfType [Spectre.Console.Rows] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreRows" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreTextPath.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreTextPath.tests.ps1 new file mode 100644 index 00000000..e99eb207 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreTextPath.tests.ps1 @@ -0,0 +1,25 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Format-SpectreTextPath" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.TextPath] + $testConsole.Write($RenderableObject) + } + } + + It "Should format a path" { + $renderable = Format-SpectreTextPath -Path "C:\Windows\System32\cmd.exe" + $renderable | Should -BeOfType [Spectre.Console.TextPath] + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreTextPath" -Output $testConsole.Output } | Should -Not -Throw + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/live/Invoke-SpectreLive.tests.ps1 b/PwshSpectreConsole.Tests/live/Invoke-SpectreLive.tests.ps1 new file mode 100644 index 00000000..a1bf03cc --- /dev/null +++ b/PwshSpectreConsole.Tests/live/Invoke-SpectreLive.tests.ps1 @@ -0,0 +1,50 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "Invoke-SpectreLive" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $writer = [System.IO.StringWriter]::new() + $output = [Spectre.Console.AnsiConsoleOutput]::new($writer) + $settings = [Spectre.Console.AnsiConsoleSettings]::new() + $settings.Out = $output + [Spectre.Console.AnsiConsole]::Console = [Spectre.Console.AnsiConsole]::Create($settings) + } + + AfterEach { + $settings = [Spectre.Console.AnsiConsoleSettings]::new() + $settings.Out = [Spectre.Console.AnsiConsoleOutput]::new([System.Console]::Out) + [Spectre.Console.AnsiConsole]::Console = [Spectre.Console.AnsiConsole]::Create($settings) + } + + It "executes the scriptblock for the basic case" { + $table = @{ Name = "Test"; Value = "Value" } | Format-SpectreTable + Invoke-SpectreLive -Data $table -ScriptBlock { + param ( + $Context + ) + return 1 + } | Should -Be 1 + } + + It "executes the scriptblock with background jobs" { + Mock Start-AnsiConsoleLive { + $Data | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $ScriptBlock | Should -BeOfType [scriptblock] + + & $ScriptBlock + } + + $table = @{ Name = "Test"; Value = "Value" } | Format-SpectreTable + Invoke-SpectreLive -Data $table -ScriptBlock { + param ( + $Context + ) + return 1 + } | Should -Be 1 + } + + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/rendering/New-SpectreLayout.tests.ps1 b/PwshSpectreConsole.Tests/rendering/New-SpectreLayout.tests.ps1 new file mode 100644 index 00000000..dcb45907 --- /dev/null +++ b/PwshSpectreConsole.Tests/rendering/New-SpectreLayout.tests.ps1 @@ -0,0 +1,34 @@ +Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue +Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force +Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force + +Describe "New-SpectreLayout" { + InModuleScope "PwshSpectreConsole" { + + BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + Mock Write-AnsiConsole { + $RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] + $testConsole.Write($RenderableObject) + } + } + + It "Should generate a layout" { + $panel1 = "what" | Format-SpectrePanel -Header "panel 1 (align bottom right)" -Expand -Color Green + $panel2 = "hello row 2" | Format-SpectrePanel -Header "panel 2" -Expand -Color Blue + $panel3 = "test" | Format-SpectreAligned | Format-SpectrePanel -Header "panel 3 (align middle center)" -Expand -Color Yellow + + $row1 = New-SpectreLayout -Name "row1" -Data $panel1 -Ratio 1 + $row2 = New-SpectreLayout -Name "row2" -Columns @($panel2, $panel3) -Ratio 2 + $renderable = New-SpectreLayout -Name "root" -Rows @($row1, $row2) + + $renderable | Should -BeOfType [Spectre.Console.Layout] + + $renderable | Out-SpectreHost + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + { Assert-OutputMatchesSnapshot -SnapshotName "New-SpectreLayout" -Output $testConsole.Output } | Should -Not -Throw + + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 b/PwshSpectreConsole.Tests/writing/Write-SpectreCalendar.tests.ps1 similarity index 100% rename from PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 rename to PwshSpectreConsole.Tests/writing/Write-SpectreCalendar.tests.ps1 diff --git a/PwshSpectreConsole/public/formatting/Format-SpectreColumns.ps1 b/PwshSpectreConsole/public/formatting/Format-SpectreColumns.ps1 index 276098ff..1e779d2a 100644 --- a/PwshSpectreConsole/public/formatting/Format-SpectreColumns.ps1 +++ b/PwshSpectreConsole/public/formatting/Format-SpectreColumns.ps1 @@ -20,7 +20,12 @@ function Format-SpectreColumns { A switch to expand the columns to fill the available space. .EXAMPLE - @("left", "middle", "right") | Format-SpectreColumns + @("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", + "tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", + "veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", + "commodo", "consequat", "duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", + "esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", + "cupidatat", "non", "proident", "sunt", "in", "culpa") | Foreach-Object { $_ } | Format-SpectreColumns .EXAMPLE @("left", "middle", "right") | Foreach-Object { $_ | Format-SpectrePanel -Expand } | Format-SpectreColumns diff --git a/PwshSpectreConsole/public/formatting/Format-SpectreJson.ps1 b/PwshSpectreConsole/public/formatting/Format-SpectreJson.ps1 index 4e26ae9d..970c2768 100644 --- a/PwshSpectreConsole/public/formatting/Format-SpectreJson.ps1 +++ b/PwshSpectreConsole/public/formatting/Format-SpectreJson.ps1 @@ -34,6 +34,26 @@ function Format-SpectreJson { } ``` + .PARAMETER Border + :::caution + This parameter is deprecated and will be removed in the future. + It takes no effect from version 2.0. + To add a border wrap this object in a panel, use the `$data | Format-SpectreJson | Format-SpectrePanel` function. + ::: + + .PARAMETER Title + :::caution + This parameter is deprecated and will be removed in the future. + It takes no effect from version 2.0. + To add a border title to a panel, use the `$data | Format-SpectreJson | Format-SpectrePanel -Header "title"` function. + ::: + + .PARAMETER NoBorder + :::caution + This parameter is deprecated and will be removed in the future. + It takes no effect from version 2.0. + ::: + .EXAMPLE $data = @( [pscustomobject]@{ @@ -69,9 +89,17 @@ function Format-SpectreJson { NumberStyle = [Spectre.Console.Color]::Cyan1 BooleanStyle = [Spectre.Console.Color]::LightSkyBlue1 NullStyle = $script:DefaultValueColor - } + }, + [string] $Border, + [string] $Title, + [switch] $NoBorder ) begin { + + if ($Border -or $Title -or $NoBorder) { + Write-Warning "Format-SpectrePanel: The parameters Border, Title, and NoBorder are deprecated and will be removed in the future." + } + $requiredJsonStyleKeys = @('MemberStyle', 'BracesStyle', 'BracketsStyle', 'ColonStyle', 'CommaStyle', 'StringStyle', 'NumberStyle', 'BooleanStyle', 'NullStyle') if (($requiredJsonStyleKeys | ForEach-Object { $JsonStyle.Keys -contains $_ }) -contains $false) { throw "JsonStyle must contain the following keys: $($requiredJsonStyleKeys -join ', ')"