MCPcopy
hub / github.com/charmbracelet/huh / TestSelectDynamic

Function TestSelectDynamic

huh_test.go:539–618  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

537}
538
539func TestSelectDynamic(t *testing.T) {
540 trigger := "initial"
541
542 field1 := NewSelect[string]().
543 TitleFunc(func() string {
544 return "field1 title " + trigger
545 }, &trigger).
546 DescriptionFunc(func() string {
547 return "field1 desc " + trigger
548 }, &trigger).
549 OptionsFunc(func() []Option[string] {
550 return []Option[string]{NewOption("field1 opt "+trigger, "field1 opt "+trigger)}
551 }, &trigger)
552 field2 := NewSelect[string]().
553 TitleFunc(func() string {
554 return "field2 title " + trigger
555 }, &trigger).
556 DescriptionFunc(func() string {
557 return "field2 desc " + trigger
558 }, &trigger).
559 OptionsFunc(func() []Option[string] {
560 return []Option[string]{NewOption("field2 opt "+trigger, "field2 opt "+trigger)}
561 }, &trigger)
562 field1.WithHeight(5)
563 field2.WithHeight(5)
564 f := NewForm(NewGroup(field1, field2)).WithHeight(10)
565
566 doAllUpdates(f, f.Init())
567
568 view := viewModel(f)
569
570 expectedStrings := []string{
571 "field1 title initial",
572 "field1 desc initial",
573 "field1 opt initial",
574 "field2 title initial",
575 "field2 desc initial",
576 "field2 opt initial",
577 }
578 for _, expected := range expectedStrings {
579 if !strings.Contains(view, expected) {
580 t.Log(pretty.Render(view))
581 t.Error("Expected view to contain " + expected)
582 }
583 }
584
585 if field1.GetValue() != "field1 opt initial" {
586 t.Errorf("Expected field1 value to be field1 opt initial but was %s", field1.GetValue())
587 }
588 if field2.GetValue() != "field2 opt initial" {
589 t.Errorf("Expected field2 value to be field2 opt initial but was %s", field2.GetValue())
590 }
591
592 trigger = "updated"
593 _, cmd := f.Update(nil)
594 doAllUpdates(f, cmd)
595 view = viewModel(f)
596

Callers

nothing calls this directly

Calls 13

NewOptionFunction · 0.85
NewFormFunction · 0.85
NewGroupFunction · 0.85
doAllUpdatesFunction · 0.85
viewModelFunction · 0.85
WithHeightMethod · 0.65
InitMethod · 0.65
ErrorMethod · 0.65
GetValueMethod · 0.65
UpdateMethod · 0.65
OptionsFuncMethod · 0.45
DescriptionFuncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…