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

106 lines
2.1 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 TestMultiSelectRender(t *testing.T) {
prompt := MultiSelect{
Message: "Pick your words:",
Options: []string{"foo", "bar", "baz", "buz"},
Default: []string{"bar", "buz"},
}
helpfulPrompt := prompt
helpfulPrompt.Help = "This is helpful"
tests := []struct {
title string
prompt MultiSelect
data MultiSelectTemplateData
expected string
}{
{
"Test MultiSelect question output",
prompt,
MultiSelectTemplateData{
SelectedIndex: 2,
PageEntries: prompt.Options,
Checked: map[string]bool{"bar": true, "buz": true},
},
`? Pick your words:
◯ foo
◉ bar
◯ baz
◉ buz
`,
},
{
"Test MultiSelect answer output",
prompt,
MultiSelectTemplateData{
Answer: "foo, buz",
ShowAnswer: true,
},
"? Pick your words: foo, buz\n",
},
{
"Test MultiSelect question output with help hidden",
helpfulPrompt,
MultiSelectTemplateData{
SelectedIndex: 2,
PageEntries: prompt.Options,
Checked: map[string]bool{"bar": true, "buz": true},
},
`? Pick your words: [? for help]
◯ foo
◉ bar
◯ baz
◉ buz
`,
},
{
"Test MultiSelect question output with help shown",
helpfulPrompt,
MultiSelectTemplateData{
SelectedIndex: 2,
PageEntries: prompt.Options,
Checked: map[string]bool{"bar": true, "buz": true},
ShowHelp: true,
},
`ⓘ This is helpful
? Pick your words:
◯ foo
◉ bar
◯ baz
◉ buz
`,
},
}
outputBuffer := bytes.NewBufferString("")
terminal.Stdout = outputBuffer
for _, test := range tests {
outputBuffer.Reset()
test.data.MultiSelect = test.prompt
err := test.prompt.Render(
MultiSelectQuestionTemplate,
test.data,
)
assert.Nil(t, err, test.title)
assert.Equal(t, test.expected, outputBuffer.String(), test.title)
}
}