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

Function TestHuhPrompterConfirm

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

Source from the content-addressed store, hash-verified

272}
273
274func TestHuhPrompterConfirm(t *testing.T) {
275 tests := []struct {
276 name string
277 defaultValue bool
278 ix interaction
279 wantResult bool
280 }{
281 {
282 name: "default false submitted as-is",
283 ix: newInteraction(enter()),
284 wantResult: false,
285 },
286 {
287 name: "default true submitted as-is",
288 defaultValue: true,
289 ix: newInteraction(enter()),
290 wantResult: true,
291 },
292 {
293 name: "toggle from false to true with left arrow",
294 ix: newInteraction(left(), enter()),
295 wantResult: true,
296 },
297 {
298 name: "toggle from true to false with right arrow",
299 defaultValue: true,
300 ix: newInteraction(right(), enter()),
301 wantResult: false,
302 },
303 {
304 name: "accept with y key",
305 ix: newInteraction(pressY(), enter()),
306 wantResult: true,
307 },
308 {
309 name: "reject with n key",
310 defaultValue: true,
311 ix: newInteraction(pressN(), enter()),
312 wantResult: false,
313 },
314 }
315
316 for _, tt := range tests {
317 t.Run(tt.name, func(t *testing.T) {
318 p := newTestHuhPrompter()
319 f, result := p.buildConfirmForm("Sure?", tt.defaultValue)
320 runForm(t, f, tt.ix)
321 require.Equal(t, tt.wantResult, *result)
322 })
323 }
324}
325
326func TestHuhPrompterPassword(t *testing.T) {
327 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