MCPcopy
hub / github.com/cli/cli / TestHuhPrompterSelect

Function TestHuhPrompterSelect

internal/prompter/huh_prompter_test.go:164–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestHuhPrompterSelect(t *testing.T) {
165 tests := []struct {
166 name string
167 options []string
168 defaultValue string
169 ix interaction
170 wantIndex int
171 }{
172 {
173 name: "selects first option by default",
174 options: []string{"a", "b", "c"},
175 ix: newInteraction(enter()),
176 wantIndex: 0,
177 },
178 {
179 name: "respects default value",
180 options: []string{"a", "b", "c"},
181 defaultValue: "b",
182 ix: newInteraction(enter()),
183 wantIndex: 1,
184 },
185 {
186 name: "invalid default selects first",
187 options: []string{"a", "b", "c"},
188 defaultValue: "z",
189 ix: newInteraction(enter()),
190 wantIndex: 0,
191 },
192 {
193 name: "navigate down one",
194 options: []string{"a", "b", "c"},
195 ix: newInteraction(down(), enter()),
196 wantIndex: 1,
197 },
198 {
199 name: "navigate down two",
200 options: []string{"a", "b", "c"},
201 ix: newInteraction(down(), down(), enter()),
202 wantIndex: 2,
203 },
204 }
205
206 for _, tt := range tests {
207 t.Run(tt.name, func(t *testing.T) {
208 p := newTestHuhPrompter()
209 f, result := p.buildSelectForm("Pick:", tt.defaultValue, tt.options)
210 runForm(t, f, tt.ix)
211 require.Equal(t, tt.wantIndex, *result)
212 })
213 }
214}
215
216func TestHuhPrompterMultiSelect(t *testing.T) {
217 tests := []struct {

Callers

nothing calls this directly

Calls 8

newInteractionFunction · 0.85
enterFunction · 0.85
downFunction · 0.85
newTestHuhPrompterFunction · 0.85
runFormFunction · 0.85
buildSelectFormMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected