mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-31 10:18:29 +02:00
90 lines
1.7 KiB
Go
90 lines
1.7 KiB
Go
package survey
|
||
|
||
import (
|
||
"bytes"
|
||
"testing"
|
||
|
||
"github.com/AlecAivazis/survey/core"
|
||
"github.com/AlecAivazis/survey/terminal"
|
||
"github.com/stretchr/testify/assert"
|
||
)
|
||
|
||
func init() {
|
||
// disable color output for all prompts to simplify testing
|
||
core.DisableColor = true
|
||
}
|
||
|
||
func TestSelectRender(t *testing.T) {
|
||
|
||
prompt := Select{
|
||
Message: "Pick your word:",
|
||
Options: []string{"foo", "bar", "baz", "buz"},
|
||
Default: "baz",
|
||
}
|
||
|
||
helpfulPrompt := prompt
|
||
helpfulPrompt.Help = "This is helpful"
|
||
|
||
tests := []struct {
|
||
title string
|
||
prompt Select
|
||
data SelectTemplateData
|
||
expected string
|
||
}{
|
||
{
|
||
"Test Select question output",
|
||
prompt,
|
||
SelectTemplateData{SelectedIndex: 2, PageEntries: prompt.Options},
|
||
`? Pick your word:
|
||
foo
|
||
bar
|
||
❯ baz
|
||
buz
|
||
`,
|
||
},
|
||
{
|
||
"Test Select answer output",
|
||
prompt,
|
||
SelectTemplateData{Answer: "buz", ShowAnswer: true, PageEntries: prompt.Options},
|
||
"? Pick your word: buz\n",
|
||
},
|
||
{
|
||
"Test Select question output with help hidden",
|
||
helpfulPrompt,
|
||
SelectTemplateData{SelectedIndex: 2, PageEntries: prompt.Options},
|
||
`? Pick your word: [? for help]
|
||
foo
|
||
bar
|
||
❯ baz
|
||
buz
|
||
`,
|
||
},
|
||
{
|
||
"Test Select question output with help shown",
|
||
helpfulPrompt,
|
||
SelectTemplateData{SelectedIndex: 2, ShowHelp: true, PageEntries: prompt.Options},
|
||
`ⓘ This is helpful
|
||
? Pick your word:
|
||
foo
|
||
bar
|
||
❯ baz
|
||
buz
|
||
`,
|
||
},
|
||
}
|
||
|
||
outputBuffer := bytes.NewBufferString("")
|
||
terminal.Stdout = outputBuffer
|
||
|
||
for _, test := range tests {
|
||
outputBuffer.Reset()
|
||
test.data.Select = test.prompt
|
||
err := test.prompt.Render(
|
||
SelectQuestionTemplate,
|
||
test.data,
|
||
)
|
||
assert.Nil(t, err, test.title)
|
||
assert.Equal(t, test.expected, outputBuffer.String(), test.title)
|
||
}
|
||
}
|