Skip to content

Commit

Permalink
test: add tests for custom answers
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdavim committed Jul 24, 2022
1 parent ba28126 commit f1c8f2b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions interactive_confirm_printer_test.go
Expand Up @@ -76,6 +76,45 @@ func TestInteractiveConfirmPrinter_WithRejectText(t *testing.T) {
testza.AssertEqual(t, p.RejectText, "reject")
}

func TestInteractiveConfirmPrinter_CustomAnswers(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithRejectText("reject").WithConfirmText("accept")
tests := []struct {
name string
key rune
expected bool
}{
{
name: "Accept_upper_case",
key: 'A',
expected: true,
},
{
name: "Accept_lower",
key: 'a',
expected: true,
},
{
name: "Reject_upper_case",
key: 'R',
expected: false,
},
{
name: "Reject_lower_case",
key: 'r',
expected: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(tc.key)
}()
result, _ := p.Show()
testza.AssertEqual(t, result, tc.expected)
})
}
}

func TestInteractiveConfirmPrinter_WithSuffixStyle(t *testing.T) {
style := pterm.NewStyle(pterm.FgRed)
p := pterm.DefaultInteractiveConfirm.WithSuffixStyle(style)
Expand Down

0 comments on commit f1c8f2b

Please sign in to comment.