(t *testing.T)
| 314 | } |
| 315 | |
| 316 | func 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 | |
| 368 | func TestHuhPrompterPassword(t *testing.T) { |
| 369 | tests := []struct { |
nothing calls this directly
no test coverage detected