package ui import ( "testing" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func TestDeleteDialogDefaultsAreSafe(t *testing.T) { a := newTestApp(t) var calls [][2]bool _, form := a.newDeleteDialog("Heat (1995)", "3 GB on disk", func(files, exclude bool) { calls = append(calls, [2]bool{files, exclude}) }) var focus func(p tview.Primitive) focus = func(p tview.Primitive) { p.Focus(focus) } form.Focus(focus) press := func(k tcell.Key) { form.InputHandler()(tcell.NewEventKey(k, 0, 0), focus) } space := func() { form.InputHandler()(tcell.NewEventKey(tcell.KeyRune, ' ', 0), focus) } // Both boxes start unticked and the focus starts on Cancel: a stray Enter does nothing. press(tcell.KeyEnter) if len(calls) != 0 { t.Fatalf("Enter on the initial focus deleted: %v", calls) } // Moving to Delete and confirming removes the entry only. form.SetFocus(form.GetFormItemCount()) press(tcell.KeyRight) press(tcell.KeyEnter) if len(calls) != 1 || calls[0] != [2]bool{false, false} { t.Fatalf("calls = %v, want one call without files and exclusion", calls) } // Ticking the boxes is passed on. form.SetFocus(0) space() // delete files press(tcell.KeyDown) space() // exclusion press(tcell.KeyDown) press(tcell.KeyDown) // Delete button press(tcell.KeyEnter) if len(calls) != 2 || calls[1] != [2]bool{true, true} { t.Errorf("calls = %v, want the second with both ticked", calls) } }