Skip to content

Commit

Permalink
Fix test and demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Sep 5, 2024
1 parent 6c18748 commit 767723d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
4 changes: 0 additions & 4 deletions PwshSpectreConsole.Docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ export default defineConfig({
integrations: [
starlight({
title: "PwshSpectreConsole",
editLink: {
baseUrl:
"https://github.com/ShaunLawrie/PwshSpectreConsole/edit/main/PwshSpectreConsole.Docs/",
},
favicon: "/favicon.png",
customCss: ["./src/tailwind.css"],
social: {
Expand Down
74 changes: 37 additions & 37 deletions PwshSpectreConsole.Tests/prompts/Read-SpectreText.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force

Describe "Read-SpectreText" {
InModuleScope "PwshSpectreConsole" {
BeforeEach {
$testAnswerColor = $null
Mock Invoke-SpectrePromptAsync {
$Prompt | Should -BeOfType [Spectre.Console.TextPrompt[string]]
if ($Prompt.PromptStyle.Foreground) {
$Prompt.PromptStyle.Foreground.ToMarkup() | Should -Be $testAnswerColor
}
}
}

It "prompts" {
Read-SpectreText -Question (Get-RandomString)
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "prompts with a default answer" {
Read-SpectreText -Question (Get-RandomString) -DefaultAnswer (Get-RandomString)
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "can allow an empty answer" {
Read-SpectreText -AllowEmpty
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "can use a colored prompt" {
$testAnswerColor = Get-RandomColor
Read-SpectreText -Question (Get-RandomString) -AnswerColor $testAnswerColor
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}
}
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force

Describe "Read-SpectreText" {
InModuleScope "PwshSpectreConsole" {
BeforeEach {
$testAnswerColor = $null
Mock Invoke-SpectrePromptAsync {
$Prompt | Should -BeOfType [Spectre.Console.TextPrompt[string]]
if ($Prompt.PromptStyle.Foreground) {
$Prompt.PromptStyle.Foreground.ToMarkup() | Should -Be $testAnswerColor
}
}
}

It "prompts" {
Read-SpectreText -Question (Get-RandomString)
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "prompts with a default answer" {
Read-SpectreText -Question (Get-RandomString) -DefaultAnswer (Get-RandomString)
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "can allow an empty answer" {
Read-SpectreText -Message "What?" -AllowEmpty
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}

It "can use a colored prompt" {
$testAnswerColor = Get-RandomColor
Read-SpectreText -Question (Get-RandomString) -AnswerColor $testAnswerColor
Assert-MockCalled -CommandName "Invoke-SpectrePromptAsync" -Times 1 -Exactly
}
}
}
22 changes: 20 additions & 2 deletions PwshSpectreConsole/public/demo/Start-SpectreDemo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function Start-SpectreDemo {
Write-Host ""

Write-SpectreRule "PwshSpectreConsole Intro" -Color ([Spectre.Console.Color]::SteelBlue1)
Write-SpectreHost "`nPwshSpectreConsole is an opinionated wrapper for the awesome Spectre.Console library. It's opinionated in that I have not just exposed the internals of Spectre Console to PowerShell but have wrapped them in a way that makes them work better in the PowerShell ecosystem (in my opinion 😜)."
Write-SpectreHost "`nPwshSpectreConsole is a wrapper for the awesome Spectre.Console library. The internals of Spectre Console have not just been exposed to PowerShell but have wrapped them in a way that makes them work better in the PowerShell ecosystem."
Write-SpectreHost "`nSpectre Console is mostly an async library and it leans heavily on types and extension methods in C# which are very verbose to work with in PowerShell so this module hides away some of the complexity."
Write-SpectreHost "`nThe module doesn't expose the full feature set of Spectre.Console because the scope of the library is huge and I've focused on the features that I use to enhance my scripts."
Write-SpectreHost "`nThe module exposes all core functionality of Spectre.Console but not all configuration options may be available. Feel free to open an issue on the Github repo if you would like to see something added."
Write-Host ""
if (![Spectre.Console.AnsiConsole]::Console.Profile.Capabilities.Unicode) {
Write-Warning "To enable all features of Spectre.Console you need to enable Unicode support in your PowerShell profile by adding the following to your profile at $PROFILE. See https://spectreconsole.net/best-practices for more info.`n`n`$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding`n"
Expand Down Expand Up @@ -329,5 +329,23 @@ Write-SpectreHost "I'm Harvey Specter. Are you after a Specter consult or a Spec
Invoke-Expression $example

Read-SpectrePause
Clear-Host

if ($host.UI.RawUI.WindowSize.Width -lt 120) {
Write-SpectreFigletText "Pwsh + Spectre!"
} else {
Write-SpectreFigletText "Welcome to PwshSpectreConsole!"
}
Write-Host ""

Write-SpectreRule "PwshSpectreConsole Outro" -Color ([Spectre.Console.Color]::SteelBlue1)

Get-SpectreDemoFeatures

@(
(Write-SpectreHost "Thanks for checking out the PwshSpectreConsole demo!" -PassThru | Format-SpectrePadded -Top 1 -Left 0 -Right 0 -Bottom 1),
(Write-SpectreHost "There are more examples and documentation at [blue]https://pwshspectreconsole.com/[/]" -PassThru),
(Write-SpectreHost "You can also check out the original dotnet library documentation at [blue]https://spectreconsole.net/[/]" -PassThru),
(Write-SpectreHost "Have fun :waving_hand:" -PassThru | Format-SpectrePadded -Top 1 -Left 0 -Right 0 -Bottom 1)
) | Format-SpectreRows | Format-SpectrePanel -Expand
}

0 comments on commit 767723d

Please sign in to comment.