Files
jira/vendor/github.com/AlecAivazis/survey/select_test.go
T
2017-08-13 18:23:38 -07:00

90 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)
}
}