MCPcopy
hub / github.com/basecamp/once / TestForm_ValidationFocusesFirstError

Function TestForm_ValidationFocusesFirstError

internal/ui/form_test.go:275–288  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

273}
274
275func TestForm_ValidationFocusesFirstError(t *testing.T) {
276 form := NewForm("Submit",
277 FormItem{Label: "First", Field: NewTextField("first")},
278 FormItem{Label: "Second", Field: NewTextField("second"), Required: true},
279 FormItem{Label: "Third", Field: NewTextField("third"), Required: true},
280 )
281 form.OnSubmit(func(f *Form) tea.Cmd { return nil })
282
283 formFocusSubmit(&form)
284 formPressEnter(&form)
285
286 assert.Equal(t, 1, form.Focused(), "focused on first errored field")
287 assert.Equal(t, "Second is required", form.Error())
288}
289
290func TestFormOnRebuild_CalledOnKeyPress(t *testing.T) {
291 form := NewForm("Done",

Callers

nothing calls this directly

Calls 8

OnSubmitMethod · 0.95
FocusedMethod · 0.95
ErrorMethod · 0.95
NewFormFunction · 0.85
NewTextFieldFunction · 0.85
formFocusSubmitFunction · 0.85
formPressEnterFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…