Files
magpie/internal/provider/groups_delete_test.go
yetone a84f1052e0 groups: several routing groups are removed at once, and the found ones removed are one folded line rather than listed (lc on Discord: 路由组可否关闭自动发现,并且可编辑批量移除,已经移除的不要显示,或者用移除组来替代,这样干净整洁,并且可以彻删) — groups could only be removed one at a time from each editor, and every found group removed stayed under the list as a chip of its own. Select, by New group, puts a box on each group's card: a click on a card picks it, the bar's box picks all or none, and Remove (a second click to confirm, Remove 2? Click again) posts groups/delete {ids}, which provider.DeleteGroups removes all or none: refused before any goes when one isn't there or a group left holds one as a member or classifier, and a group held only by another being removed goes after it. A found group removed stays removed (magpie doesn't make it again), now one line under the list, 3 found groups removed, whose app menu brings one back; with found groups off it isn't shown. magpie group rm takes several ids. Turning found groups off altogether was there already (Find groups on their own, v0.1.603). zh, ja, de strings. TestDeleteGroups, TestGroupsDeleteSeveral; group-bulk-remove.test.cjs (WebKit, en and zh: picking, the two clicks, the post, the folded line and its menu, no click moves the page), failing on the old code (the chips). group-found-off, group-arrange, group-fold, settings-groups and click-scroll pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 03:37:03 +08:00

73 lines
2.1 KiB
Go

package provider
import (
"slices"
"strings"
"testing"
)
// Several groups are removed at once (lc on Discord: they could only be
// removed one at a time): the user's go, the found ones are kept removed,
// a group held by another being removed with it goes after that one, and
// the whole is refused, with none removed, when one isn't there or a group
// left holds one.
func TestDeleteGroups(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
for _, id := range []string{"a", "b"} {
if err := Save(Provider{ID: id, Name: id, Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x", "y", "z"}}); err != nil {
t.Fatal(err)
}
}
for _, g := range []Group{
{Name: "Inner", Members: []string{"a/x", "b/y"}},
{Name: "Outer", Members: []string{"group/inner", "a/z"}},
{Name: "Keep", Members: []string{"group/auto-z", "b/x"}},
} {
if err := SaveGroup(g); err != nil {
t.Fatal(err)
}
}
shown := func() (out []string) {
for _, g := range Groups() {
if !g.Hidden {
out = append(out, g.ID)
}
}
slices.Sort(out)
return out
}
all := []string{"auto-x", "auto-y", "auto-z", "inner", "keep", "outer"}
if got := shown(); !slices.Equal(got, all) {
t.Fatalf("before: %v", got)
}
for _, tc := range []struct {
ids []string
err string
}{
{[]string{"auto-x", "nothing"}, `no group "nothing"`},
{[]string{"auto-x", "inner"}, "inner is in Outer"},
{[]string{"auto-z", "auto-y"}, "auto-z is in Keep"},
} {
if err := DeleteGroups(tc.ids); err == nil || !strings.Contains(err.Error(), tc.err) {
t.Errorf("%v: %v, want …%s", tc.ids, err, tc.err)
}
if got := shown(); !slices.Equal(got, all) {
t.Fatalf("%v refused, yet %v are left", tc.ids, got)
}
}
// inner first, though Outer holds it: Outer goes with it
if err := DeleteGroups([]string{"inner", "auto-x", "outer", "auto-y", "inner"}); err != nil {
t.Fatal(err)
}
if got := shown(); !slices.Equal(got, []string{"auto-z", "keep"}) {
t.Fatalf("after: %v", got)
}
if got := RemovedGroups(); !slices.Equal(got, []string{"auto-x", "auto-y"}) {
t.Fatalf("removed found groups: %v", got)
}
}