Files
magpie/internal/gui/update_notes_test.go
T
yetone 460057a225 gui: a hidden agent put back to its defaults goes under Not set up at once (Hu9956, #842), and a restart to update shows what changed before it restarts (Hu9956, #844) — #842: an agent hidden by hand stayed under Hidden with its Show (the eye) after its model was set back to Default; only turning its switch off and on moved it, since nothing ever dropped its hiding (the server leaves agentsHidden alone). Now when a hidden agent's settings change (wired, added, drift or a field's value) so that nothing is set on it, its hiding is dropped and saved with the arrangement at once, it goes under Not set up without the eye, and the status line says so; a state answer read before that save, still naming it hidden, doesn't hide it again. One hidden while nothing was set on it, and left alone, stays hidden. #844: the header's Update pill and Settings › About's Restart to update restarted on the click, and what the update brought was only in Settings › About › What's new. Now in the window they open a sheet first: Update to v…, What changed since v<current>, every release after this one up to the new one, newest first (the update's own notes at once, the full list when GET /api/update/notes answers: the site's notes feed for (current, latest], the update's notes when the feed is out of reach), Later and Restart to update; only the latter restarts. A failed swap still restarts again at once; the panel keeps its one-click pill. zh, ja, de strings. hidden-agent-cleared.test.cjs (the groups, the hiding saved once, the late answer, no scroll) and update-notes-ask.test.cjs (the pill and the Settings button ask first, both releases' notes, Later sends nothing, the sheet's button restarts, no scroll, no left border) pass on WebKit in en and zh and fail on the old code; looked at in screenshots. TestUpdateNotesRoute (the releases between, the fallback, none) fails on the old code. update-wait.test.cjs now confirms the sheet; it and update-hide, update-auto, update-check, header-centre, header-zoom-fit, show-unset-agent, fold-show-grip, agent-grip, agent-start-pick, agent-path-same, removed-hide, profile-confirm, agent-update-all, gui-ja, gui-de and click-scroll pass on WebKit (click-scroll's pointer subtests are flaky the same on origin/main). go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 11:16:34 +08:00

74 lines
2.5 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/yetone/magpie/internal/update"
)
// Before an update is put in, the page asks what changed (Hu9956, #844):
// every release after this one up to the update's, newest first, without
// their Install sections; the site's list out of reach, the update's own
// notes; no update, none.
func TestUpdateNotesRoute(t *testing.T) {
feed := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("after") != "0.1.604" || r.URL.Query().Get("upto") != "0.1.607" {
t.Errorf("asked %s", r.URL.RawQuery)
}
json.NewEncoder(w).Encode(map[string]any{"releases": []update.Note{
{Version: "0.1.607", Notes: "- seven\n\n### Install\n\nlinks"},
{Version: "0.1.606", Notes: "- six"},
{Version: "0.1.605", Notes: "- five"},
{Version: "0.1.604", Notes: "- four"},
}})
}))
defer feed.Close()
t.Setenv("MAGPIE_NOTES_FEED", feed.URL)
t.Setenv("MAGPIE_UPDATE_FEED", "http://127.0.0.1:1/")
oldV, oldState, oldLatest, oldIn := Version, updates.state, updates.latest, updates.notesIn
defer func() { Version, updates.state, updates.latest, updates.notesIn = oldV, oldState, oldLatest, oldIn }()
Version = "0.1.604"
updates.mu.Lock()
updates.state, updates.latest, updates.notesIn = "ready", &update.Release{Version: "0.1.607", Notes: "- seven only"}, "en"
updates.mu.Unlock()
mux := http.NewServeMux()
updateRoutes(mux, nil)
get := func() (out struct {
Releases []update.Note `json:"releases"`
Error string `json:"error"`
}) {
rw := httptest.NewRecorder()
mux.ServeHTTP(rw, httptest.NewRequest("GET", "/api/update/notes?lang=en", nil))
if rw.Code != 200 {
t.Fatalf("%d %s", rw.Code, rw.Body)
}
json.Unmarshal(rw.Body.Bytes(), &out)
return out
}
j := get()
var vs []string
for _, n := range j.Releases {
vs = append(vs, n.Version)
}
if len(vs) != 3 || vs[0] != "0.1.607" || vs[2] != "0.1.605" || j.Releases[0].Notes != "- seven" {
t.Fatalf("between: %+v", j)
}
// the site's list out of reach: the update's own notes
t.Setenv("MAGPIE_NOTES_FEED", "http://127.0.0.1:1/")
if j := get(); len(j.Releases) != 1 || j.Releases[0].Version != "0.1.607" || j.Releases[0].Notes != "- seven only" {
t.Fatalf("fallback: %+v", j)
}
// no update: no notes
updates.mu.Lock()
updates.state, updates.latest = "latest", nil
updates.mu.Unlock()
if j := get(); len(j.Releases) != 0 || j.Error != "" {
t.Fatalf("none: %+v", j)
}
}