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

Function TestHuhPrompterMultiSelect

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

Source from the content-addressed store, hash-verified

214}
215
216func TestHuhPrompterMultiSelect(t *testing.T) {
217 tests := []struct {
218 name string
219 options []string
220 defaults []string
221 ix interaction
222 wantResult []int
223 }{
224 {
225 name: "no defaults and no toggles returns empty",
226 options: []string{"a", "b", "c"},
227 ix: newInteraction(enter()),
228 wantResult: []int{},
229 },
230 {
231 name: "defaults are pre-selected",
232 options: []string{"a", "b", "c"},
233 defaults: []string{"a", "c"},
234 ix: newInteraction(enter()),
235 wantResult: []int{0, 2},
236 },
237 {
238 name: "toggle first option",
239 options: []string{"a", "b", "c"},
240 ix: newInteraction(toggle(), enter()),
241 wantResult: []int{0},
242 },
243 {
244 name: "toggle multiple options",
245 options: []string{"a", "b", "c"},
246 ix: newInteraction(
247 toggle(), // toggle a
248 down(), // move to b
249 down(), // move to c
250 toggle(), // toggle c
251 enter(),
252 ),
253 wantResult: []int{0, 2},
254 },
255 {
256 name: "invalid defaults are excluded",
257 options: []string{"a", "b"},
258 defaults: []string{"z"},
259 ix: newInteraction(enter()),
260 wantResult: []int{},
261 },
262 }
263
264 for _, tt := range tests {
265 t.Run(tt.name, func(t *testing.T) {
266 p := newTestHuhPrompter()
267 f, result := p.buildMultiSelectForm("Pick:", tt.defaults, tt.options)
268 runForm(t, f, tt.ix)
269 require.Equal(t, tt.wantResult, *result)
270 })
271 }
272}
273

Callers

nothing calls this directly

Calls 9

newInteractionFunction · 0.85
enterFunction · 0.85
toggleFunction · 0.85
downFunction · 0.85
newTestHuhPrompterFunction · 0.85
runFormFunction · 0.85
buildMultiSelectFormMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected