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

Function TestMultiSelectFiltering

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

Source from the content-addressed store, hash-verified

699}
700
701func TestMultiSelectFiltering(t *testing.T) {
702 tests := []struct {
703 name string
704 filtering bool
705 }{
706 {"Filtering off", false},
707 {"Filtering on", true},
708 }
709
710 for _, tc := range tests {
711 t.Run(tc.name, func(t *testing.T) {
712 field := NewMultiSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?").Filterable(tc.filtering)
713 f := NewForm(NewGroup(field))
714 f.Update(f.Init())
715 // Filter for values starting with a 'B' only.
716 f.Update(keypress('/'))
717 f.Update(keypress('B'))
718
719 view := viewModel(f)
720 // When we're filtering, the list should change.
721 if tc.filtering && strings.Contains(view, "Foo") {
722 t.Log(pretty.Render(view))
723 t.Error("Foo should not in filtered list.")
724 }
725 // When we're not filtering, the list shouldn't change.
726 if !tc.filtering && !strings.Contains(view, "Foo") {
727 t.Log(pretty.Render(view))
728 t.Error("Expected list to contain Foo.")
729 }
730 })
731 }
732 t.Run("Remove filter option from help menu.", func(t *testing.T) {
733 field := NewMultiSelect[string]().Options(NewOptions("Foo", "Bar", "Baz")...).Title("Which one?").Filterable(false)
734 f := NewForm(NewGroup(field))
735 f.Update(f.Init())
736 view := viewModel(f)
737 if strings.Contains(view, "filter") {
738 t.Log(pretty.Render(view))
739 t.Error("Expected list to hide filtering in help menu.")
740 }
741 })
742}
743
744func TestSelectPageNavigation(t *testing.T) {
745 opts := NewOptions(

Callers

nothing calls this directly

Calls 12

UpdateMethod · 0.95
InitMethod · 0.95
NewOptionsFunction · 0.85
NewFormFunction · 0.85
NewGroupFunction · 0.85
keypressFunction · 0.85
viewModelFunction · 0.85
FilterableMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.65
TitleMethod · 0.45
OptionsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…