Import on the Routing page always added a new group. When the pasted text
carries the id of a group of the user's own (not one magpie found), the
box now says so before it is pressed: the button reads "Replace <name>"
and a line under the box says its models, routing and rules are replaced
and its accounts and folder rules stay. Pressing it posts groups/import
with replace, and provider.ImportGroupOver saves the text's group over
that one, in its place in the list. Matching is by id only; no other group
changes. Kept as the user has them, since the text can't carry them: the
group's accounts, its folder rules (that still fit the new members) and
its on/off switch. A name another group has gets a number. A text whose
id nobody has, a found group's id, or any import that doesn't ask to
replace adds a group as before. ImportGroup is unchanged.
Run on mote at the pushed tree before rebase:
- go test ./internal/provider (Share|ImportGroup): ok; the new
TestImportGroupOverReplacesSameID is red with the match switched off by
hand (replaced=false, id three-2).
- go test ./internal/gui -skip TestMainWindowCorners: ok. TestMainWindowCorners
fails on mote's macOS 27 box and on an untouched origin/main checkout
alike (c360d9d30), so it is not this change; not filed here.
- GOOS=windows go vet ./internal/provider ./internal/gui, gofmt -l: clean.
GOOS=linux go vet of internal/gui can't cross-compile wails (cgo), not run.
- group-import-replace.test.cjs (new, 10 tests: chromium and webkit x en,
zh, zh-TW, ja, de, at 420px): green; red 10 of 10 with the id match
broken by hand. Its checks: Import for an unknown id or a found group's
id, Replace One + the line for an own id, the label survives a redraw,
replace is posted only then, the list keeps its groups.
- group-*.test.cjs, i18n-keys, gui-de/ja/zh-tw, routing-accounts-narrow,
routing-save (407 tests, chromium and webkit): all pass. A wider run of
group/routing/i18n/gui-* files at concurrency 3 was cut at 444 tests with
one red, routing-accounts-narrow, chromium en, which passes alone (load
from other sessions on mote); the rest of that wide run was not finished.
Not tried: a real account's group pasted into a real magpie; the TUI/CLI
have no import, so nothing there changed.
71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// issennknight on Discord: pasting a shared group whose id is a group of
|
|
// the user's updates that group instead of adding another. Only that group
|
|
// changes; what the text can't carry (accounts' folder rules, the order,
|
|
// the switch) stays; an id the user has no group of adds one as before.
|
|
func TestImportGroupOverReplacesSameID(t *testing.T) {
|
|
shareHome(t, Provider{ID: "a", Name: "A", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x", "y", "z"}})
|
|
for _, g := range []Group{
|
|
{ID: "one", Name: "One", Members: []string{"a/x"}, Rules: []Rule{{Use: "a/x", Folders: []string{"~/mine"}}}},
|
|
{ID: "two", Name: "Two", Members: []string{"a/z"}},
|
|
{ID: "three", Name: "Three", Members: []string{"a/z"}},
|
|
} {
|
|
if err := SaveGroup(g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := SwitchGroup("one", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
text, _ := json.Marshal(SharedGroup{Magpie: ShareMark, Version: ShareVersion, Group: Group{
|
|
ID: "one", Name: "Three", Members: []string{"a/y", "a/x"}, Routing: Rotate}})
|
|
before := len(Groups())
|
|
res, err := ImportGroupOver(string(text))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !res.Replaced || res.ID != "one" || len(Groups()) != before {
|
|
t.Fatalf("replaced=%v id=%q groups %d -> %d", res.Replaced, res.ID, before, len(Groups()))
|
|
}
|
|
g := Groups()[slices.IndexFunc(Groups(), func(g Group) bool { return g.ID == "one" })]
|
|
if !slices.Equal(g.Members, []string{"a/y", "a/x"}) || g.Routing != Rotate {
|
|
t.Fatalf("not replaced: %+v", g)
|
|
}
|
|
if g.Name != "Three 2" {
|
|
t.Errorf("a name another group has: %q", g.Name)
|
|
}
|
|
if !g.Disabled || len(g.Rules) != 1 || !g.Rules[0].ByFolder() {
|
|
t.Errorf("the switch or the folder rule did not stay: %+v", g)
|
|
}
|
|
if two := sharedAt(t, "two"); !slices.Equal(two.Members, []string{"a/z"}) || two.Name != "Two" {
|
|
t.Errorf("another group changed: %+v", two)
|
|
}
|
|
i, j := slices.IndexFunc(Groups(), func(g Group) bool { return g.ID == "one" }), slices.IndexFunc(Groups(), func(g Group) bool { return g.ID == "two" })
|
|
if i > j {
|
|
t.Errorf("it moved in the list: %d %d", i, j)
|
|
}
|
|
|
|
// no group of that id: added, as ImportGroup does
|
|
text, _ = json.Marshal(SharedGroup{Magpie: ShareMark, Version: ShareVersion, Group: Group{
|
|
ID: "elsewhere", Name: "Elsewhere", Members: []string{"a/y"}}})
|
|
res, err = ImportGroupOver(string(text))
|
|
if err != nil || res.Replaced || len(Groups()) != before+1 {
|
|
t.Fatalf("added: %+v %v groups %d", res, err, len(Groups()))
|
|
}
|
|
|
|
// without asking to replace, the same id adds another group
|
|
text, _ = json.Marshal(SharedGroup{Magpie: ShareMark, Version: ShareVersion, Group: Group{
|
|
ID: "one", Name: "One", Members: []string{"a/y"}}})
|
|
res, err = ImportGroup(string(text))
|
|
if err != nil || res.Replaced || res.ID == "one" {
|
|
t.Fatalf("plain import: %+v %v", res, err)
|
|
}
|
|
}
|