Draw one menu on every page
Each page wrote its own nav: the same links in a different order, some missing, the current page sometimes listed and sometimes not. A shared "nav" template now draws it everywhere — Cluster, People, Quotas, Usage, Mirror for an administrator, then Chat, Your keys and Sign out — with the current page marked by aria-current. Pages rendered outside the account pages (the dashboard, node logs) get it through the request context their admin wrapper sets. The admin listener's own page keeps its metrics/pprof/api links. The chat and key pages said "project proj-3kq7…"; they now show the project's path, and the key page no longer repeats the email. A test renders several admin pages and requires the same menu on each. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c22c3a309b
commit
c9cd25efc2
23 files changed
+209
-44
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/mirror"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
var menuRe = regexp.MustCompile(`(?s)<nav class="menu".*?</nav>`)
|
||||
|
||||
// Every admin page drew its own menu, and no two agreed: different links, in a
|
||||
// different order, the current page sometimes there and sometimes not.
|
||||
func TestEveryPageDrawsTheSameMenu(t *testing.T) {
|
||||
a := fakeAccounts{user: store.User{ID: "u1", Email: "a@example.com", IsAdmin: true}}
|
||||
p := NewAccountPages(a, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
mux := http.NewServeMux()
|
||||
p.RegisterAdminUsers(mux, &fakeAdmin{})
|
||||
p.RegisterAdminQuotas(mux, oneTeam(), pricedYes{})
|
||||
p.RegisterAdminMirror(mux, MirrorDeps{Mirror: &fakeMirror{models: []mirror.Status{}}})
|
||||
|
||||
pages := map[string]string{
|
||||
"/admin/users": "People", "/admin/quotas": "Quotas", "/admin/mirror": "Mirror",
|
||||
}
|
||||
var first string
|
||||
for path, current := range pages {
|
||||
body := mirrorGet(t, mux, path).Body.String()
|
||||
menu := menuRe.FindString(body)
|
||||
if menu == "" {
|
||||
t.Fatalf("%s draws no menu", path)
|
||||
}
|
||||
if !strings.Contains(menu, `aria-current="page">`+current+`<`) {
|
||||
t.Errorf("%s does not mark itself in the menu:\n%s", path, menu)
|
||||
}
|
||||
plain := strings.ReplaceAll(menu, ` aria-current="page"`, "")
|
||||
if first == "" {
|
||||
first = plain
|
||||
} else if plain != first {
|
||||
t.Errorf("%s draws a different menu:\n%s\nfrom:\n%s", path, plain, first)
|
||||
}
|
||||
}
|
||||
for _, link := range []string{"/admin", "/admin/users", "/admin/quotas", "/admin/usage",
|
||||
"/admin/mirror", "/chat", "/profile", "/logout"} {
|
||||
if !strings.Contains(first, `"`+link+`"`) {
|
||||
t.Errorf("the menu lacks %s", link)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user