A team's members, quota and spend were on three pages that linked to each other. They are three tabs of one page now, each at its old address, and choosing anything in the tree opens its limits, capacity and use beside it, editable in place. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
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{
|
|
// Limits and usage are tabs of the people page, which they mark.
|
|
"/admin/users": "People", "/admin/quotas": "People", "/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/mirror", "/chat", "/profile", "/logout"} {
|
|
if !strings.Contains(first, `"`+link+`"`) {
|
|
t.Errorf("the menu lacks %s", link)
|
|
}
|
|
}
|
|
}
|