MCPcopy Index your code
hub / github.com/cli/cli / TestHuhPrompterSelect

Function TestHuhPrompterSelect

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

Source from the content-addressed store, hash-verified

204}
205
206func TestHuhPrompterSelect(t *testing.T) {
207 tests := []struct {
208 name string
209 options []string
210 defaultValue string
211 ix interaction
212 wantIndex int
213 }{
214 {
215 name: "selects first option by default",
216 options: []string{"a", "b", "c"},
217 ix: newInteraction(enter()),
218 wantIndex: 0,
219 },
220 {
221 name: "respects default value",
222 options: []string{"a", "b", "c"},
223 defaultValue: "b",
224 ix: newInteraction(enter()),
225 wantIndex: 1,
226 },
227 {
228 name: "invalid default selects first",
229 options: []string{"a", "b", "c"},
230 defaultValue: "z",
231 ix: newInteraction(enter()),
232 wantIndex: 0,
233 },
234 {
235 name: "navigate down one",
236 options: []string{"a", "b", "c"},
237 ix: newInteraction(down(), enter()),
238 wantIndex: 1,
239 },
240 {
241 name: "navigate down two",
242 options: []string{"a", "b", "c"},
243 ix: newInteraction(down(), down(), enter()),
244 wantIndex: 2,
245 },
246 }
247
248 for _, tt := range tests {
249 t.Run(tt.name, func(t *testing.T) {
250 p := newTestHuhPrompter()
251 f, result := p.buildSelectForm("Pick:", tt.defaultValue, tt.options)
252 runForm(t, f, tt.ix)
253 require.Equal(t, tt.wantIndex, *result)
254 })
255 }
256}
257
258func TestHuhPrompterMultiSelect(t *testing.T) {
259 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