vcom/internal/ui/qa_fixes_test.go
vrubelroman e5c6b279f6 fix(ui): offer permanent deletion when the trash refuses an item
With the trash as the default delete, F8 on a file the trash cannot take
(another filesystem than the home trash, a broken trash) only showed an
error (QA-1). The delete job now opens a confirmation in the same flow to
delete the remaining items permanently; Esc/n keeps them. Nothing is
deleted without that explicit confirmation.

sshtest.IsolatedHome also isolates XDG_DATA_HOME so no test can reach the
real trash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 03:53:36 +03:00

63 lines
1.9 KiB
Go

package ui
// Developer C (v0.2.8 QA fixes): tests for fixes that need more than the QA
// tests in qa_*_test.go.
import (
"os"
"path/filepath"
"testing"
"time"
"vcom/internal/testutil/teadriver"
)
// QA-1: when the trash refuses an item (another filesystem without a
// usable trash, a broken trash), the same flow offers permanent deletion;
// nothing is deleted without the explicit confirmation.
func TestQA1TrashFailureOffersPermanentDelete(t *testing.T) {
for _, tc := range []struct {
name string
answer string
deleted bool
}{
{"confirm", "enter", true},
{"y", "y", true},
{"cancel", "esc", false},
{"n", "n", false},
} {
t.Run(tc.name, func(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "a.txt"), "x")
writeFile(t, filepath.Join(dir, "b.txt"), "y")
d := newDriver(t, dir, t.TempDir())
// A file where the trash directory should be: MoveToTrash fails.
writeFile(t, filepath.Join(os.Getenv("HOME"), ".local", "share", "Trash"), "not a dir")
m := cur(t, d)
for _, e := range m.activePane().Entries {
if !e.IsParent {
m.activePane().EnsureMarked(e.Path)
}
}
d = teadriver.New(t, m, 160, 40, teadriver.WithoutInit(), teadriver.WithLongCmd(300*time.Millisecond))
d.Press("f8", "enter")
d.Settle(settle)
if !exists(filepath.Join(dir, "a.txt")) || !exists(filepath.Join(dir, "b.txt")) {
t.Fatal("files deleted before confirmation")
}
if !d.ScreenContains("Delete permanently?") || !d.ScreenContains("Not in trash: 2") {
t.Fatalf("permanent delete not offered:\n%s", d.Screen())
}
d.Press(tc.answer)
d.Settle(settle)
for _, n := range []string{"a.txt", "b.txt"} {
if got := exists(filepath.Join(dir, n)); got == tc.deleted {
t.Fatalf("%s exists=%v after %q (status %q)", n, got, tc.answer, cur(t, d).status)
}
}
if cur(t, d).modal.kind != modalNone {
t.Fatalf("dialog still open:\n%s", d.Screen())
}
})
}
}