diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 00:51:15 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 00:51:15 +0200 |
| commit | 5418ba6bc5c653b6a99572c6ece6abbf57836c43 (patch) | |
| tree | ae0a430c468890770d20f531c3a026937c9bb948 /gui/internal/model/plan_test.go | |
| parent | ca0b703526151149d060d6d38f307e9e38c3dcd2 (diff) | |
| download | krino-5418ba6bc5c653b6a99572c6ece6abbf57836c43.tar.gz krino-5418ba6bc5c653b6a99572c6ece6abbf57836c43.zip | |
gui: coloured actions with headers, a filter over the plan, bulk trash or delete
Diffstat (limited to 'gui/internal/model/plan_test.go')
| -rw-r--r-- | gui/internal/model/plan_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gui/internal/model/plan_test.go b/gui/internal/model/plan_test.go index 746ddfc..ecbb81d 100644 --- a/gui/internal/model/plan_test.go +++ b/gui/internal/model/plan_test.go @@ -313,3 +313,51 @@ func equal(a, b []string) bool { } return true } + +// TestReplaceSelected: one choice for every checked file at once - trash +// them, or delete them - changing the plan and nothing on disk until Apply +// (his request, 2026-09-17). +func TestReplaceSelected(t *testing.T) { + conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n" + e, h := sandboxDir(t, conf, map[string]string{"a.pdf": "one", "b.pdf": "two", "c.pdf": "three"}) + tab := planTab(t, e) + tab.SelectNone() + for i, r := range tab.Rows { + if r.Rel != "c.pdf" { + tab.Toggle(i) + } + } + n, err := tab.ReplaceSelected(plan.Trash) + if err != nil { + t.Fatal(err) + } + if n != 2 { + t.Errorf("changed %d files, want the 2 checked", n) + } + for _, r := range tab.Rows { + want := plan.Trash + if r.Rel == "c.pdf" { + want = plan.Move + } + if len(r.Steps) == 0 || r.Steps[0].Kind != want { + t.Errorf("%s: steps = %+v, want %s", r.Rel, r.Steps, want) + } + } + // Still nothing on disk. + for _, name := range []string{"a.pdf", "b.pdf", "c.pdf"} { + if _, err := os.Stat(filepath.Join(h, "dl", name)); err != nil { + t.Errorf("%s was touched before Apply: %v", name, err) + } + } + if _, err := tab.Apply(context.Background()); err != nil { + t.Fatal(err) + } + if entries, _ := os.ReadDir(filepath.Join(h, ".local", "share", "Trash", "files")); len(entries) != 2 { + t.Errorf("the Trash holds %d files, want 2", len(entries)) + } + // The unchecked file was declined, so it is where it was, and its plan + // still says move - the choice was made for the checked files only. + if _, err := os.Stat(filepath.Join(h, "dl", "c.pdf")); err != nil { + t.Errorf("the unchecked file did not stay put: %v", err) + } +} |
