fix(a11y prompter): input prompt default value is readable
This commit is contained in:
parent
315876852a
commit
9bc2c388da
2 changed files with 25 additions and 1 deletions
|
|
@ -140,6 +140,26 @@ func TestAccessiblePrompter(t *testing.T) {
|
|||
assert.Equal(t, dummyDefaultValue, inputValue)
|
||||
})
|
||||
|
||||
t.Run("Input - default value is in prompt and in readable format", func(t *testing.T) {
|
||||
console := newTestVirtualTerminal(t)
|
||||
p := newTestAccessiblePrompter(t, console)
|
||||
dummyDefaultValue := "12345abcdefg"
|
||||
|
||||
go func() {
|
||||
// Wait for prompt to appear
|
||||
_, err := console.ExpectString("Enter some characters (default: 12345abcdefg)")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Enter nothing
|
||||
_, err = console.SendLine("")
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
inputValue, err := p.Input("Enter some characters", dummyDefaultValue)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, dummyDefaultValue, inputValue)
|
||||
})
|
||||
|
||||
t.Run("Password", func(t *testing.T) {
|
||||
console := newTestVirtualTerminal(t)
|
||||
p := newTestAccessiblePrompter(t, console)
|
||||
|
|
|
|||
|
|
@ -131,7 +131,11 @@ func (p *accessiblePrompter) MultiSelect(prompt string, defaults []string, optio
|
|||
|
||||
func (p *accessiblePrompter) Input(prompt, defaultValue string) (string, error) {
|
||||
result := defaultValue
|
||||
prompt = fmt.Sprintf("%s (%s)", prompt, defaultValue)
|
||||
if defaultValue != "" {
|
||||
prompt = fmt.Sprintf("%s (default: %s)", prompt, defaultValue)
|
||||
} else {
|
||||
prompt = fmt.Sprintf("%s:", prompt)
|
||||
}
|
||||
form := p.newForm(
|
||||
huh.NewGroup(
|
||||
huh.NewInput().
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue