package tui import "testing" 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") } }