Files
tuio/internal/tui/form_test.go
T
jbandClaude Opus 4.8 9943d5f7b7 fix: render full placeholder text in form inputs
bubbles/v2 textinput truncates the placeholder to its first rune when the
input width is 0 (the default): it sizes the placeholder buffer to
Width()+1 and early-returns after the first character. Set a non-zero
width on every text input (defaultInputWidth) and resize inputs
responsively to the terminal on WindowSizeMsg via FormStep.SetWidth, so
placeholders render in full and inputs fill the available width.

Adds a regression test asserting the placeholder renders past its first
rune.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:28:34 -03:00

82 lines
1.9 KiB
Go

package tui
import (
"strings"
"testing"
)
// Guards against the bubbles bug where a text input with width 0 renders only the
// first rune of its placeholder. NewFormStep must set a non-zero width.
func TestPlaceholderRendersBeyondFirstRune(t *testing.T) {
const placeholder = "postgres://user@host/db"
f := NewFormStep("t", []FormField{
{Id: "url", Label: "URL", Placeholder: placeholder, Type: FieldTypeText},
})
view := f.Fields[0].input.View()
if !strings.Contains(view, "ostgres://user@host/db") {
t.Errorf("placeholder appears truncated; rendered view = %q", view)
}
}
func TestFormStepValues(t *testing.T) {
f := NewFormStep("Test", []FormField{
{
Id: "name",
Label: "Name",
Default: "john",
Type: FieldTypeText,
},
{
Id: "secret",
Label: "Secret",
Default: "hunter2",
Type: FieldTypePassword,
},
{
Id: "proto",
Label: "Protocol",
Default: "TCP",
Type: FieldTypeSelect,
Options: []string{"UDP", "TCP"},
},
{
Id: "mode",
Label: "Mode",
Type: FieldTypeSelect,
Options: []string{"a", "b", "c"},
},
})
values := f.Values()
want := map[string]string{
"name": "john", // text default
"secret": "hunter2",
"proto": "TCP", // select default resolves to the matching option
"mode": "a", // select with no default falls back to first option
}
for id, exp := range want {
if got := values[id]; got != exp {
t.Errorf("Values()[%q] = %q, want %q", id, got, exp)
}
}
}
func TestFormStepValues_SelectInvalidDefaultFallsBackToFirst(t *testing.T) {
f := NewFormStep("Test", []FormField{
{
Id: "proto",
Label: "Protocol",
Default: "NOPE", // not among options
Type: FieldTypeSelect,
Options: []string{"UDP", "TCP"},
},
})
if got := f.Values()["proto"]; got != "UDP" {
t.Errorf("Values()[proto] = %q, want first option %q", got, "UDP")
}
}