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

Function TestHuhPrompterConfirm

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

Source from the content-addressed store, hash-verified

314}
315
316func TestHuhPrompterConfirm(t *testing.T) {
317 tests := []struct {
318 name string
319 defaultValue bool
320 ix interaction
321 wantResult bool
322 }{
323 {
324 name: "default false submitted as-is",
325 ix: newInteraction(enter()),
326 wantResult: false,
327 },
328 {
329 name: "default true submitted as-is",
330 defaultValue: true,
331 ix: newInteraction(enter()),
332 wantResult: true,
333 },
334 {
335 name: "toggle from false to true with left arrow",
336 ix: newInteraction(left(), enter()),
337 wantResult: true,
338 },
339 {
340 name: "toggle from true to false with right arrow",
341 defaultValue: true,
342 ix: newInteraction(right(), enter()),
343 wantResult: false,
344 },
345 {
346 name: "accept with y key",
347 ix: newInteraction(pressY(), enter()),
348 wantResult: true,
349 },
350 {
351 name: "reject with n key",
352 defaultValue: true,
353 ix: newInteraction(pressN(), enter()),
354 wantResult: false,
355 },
356 }
357
358 for _, tt := range tests {
359 t.Run(tt.name, func(t *testing.T) {
360 p := newTestHuhPrompter()
361 f, result := p.buildConfirmForm("Sure?", tt.defaultValue)
362 runForm(t, f, tt.ix)
363 require.Equal(t, tt.wantResult, *result)
364 })
365 }
366}
367
368func TestHuhPrompterPassword(t *testing.T) {
369 tests := []struct {

Callers

nothing calls this directly

Calls 11

newInteractionFunction · 0.85
enterFunction · 0.85
leftFunction · 0.85
rightFunction · 0.85
pressYFunction · 0.85
pressNFunction · 0.85
newTestHuhPrompterFunction · 0.85
runFormFunction · 0.85
buildConfirmFormMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected