package web_test import ( "strings" "testing" ) // TestAdminIndexRenders proves /admin returns 200 with the three card links // visible. Counts come from the live DB (orphan + total item counts run // against projax.items_unified, so they reflect whatever m has seeded). func TestAdminIndexRenders(t *testing.T) { srv, pool := mustServer(t) defer pool.Close() h := srv.Routes() code, body := get(t, h, "/admin") if code != 200 { t.Fatalf("GET /admin → %d body=%s", code, body) } for _, want := range []string{ `Classify orphans`, `href="/admin/classify"`, `Bulk edit`, `href="/admin/bulk"`, // CalDAV card title renders regardless of config; the link is only // emitted when DAV_URL is configured. mustServer leaves CalDAV nil, // so we only assert the card text exists (with a "DAV_URL not // configured" stub instead of a link). `CalDAV calendars`, `admin-cards`, `admin-system`, // system panel scaffold `Last migration`, `MCP`, } { if !strings.Contains(body, want) { t.Errorf("/admin missing %q", want) } } } // TestLayoutHasAdminNavLink proves the header nav across every chrome-bearing // route exposes /admin. Without the link the index page is invisible — m // reported that as the headline bug. func TestLayoutHasAdminNavLink(t *testing.T) { srv, pool := mustServer(t) defer pool.Close() h := srv.Routes() for _, path := range []string{"/", "/dashboard", "/graph", "/admin/bulk", "/admin/classify"} { _, body := get(t, h, path) if !strings.Contains(body, `href="/admin"`) { t.Errorf("GET %s: nav missing /admin link", path) } } } // TestAdminCountsReflectStore: seed an item, render /admin, item count // goes up by 1. Stale-cache regression guard. func TestAdminCountsReflectStore(t *testing.T) { srv, pool := mustServer(t) defer pool.Close() h := srv.Routes() // Baseline. _, before := get(t, h, "/admin") // Count occurrences of "items in scope" — the bulk card's label. The card // renders Count + CountLabel; assert the label is present and that we can // parse the number on either side of the strong tag. if !strings.Contains(before, "items in scope") { t.Fatalf("baseline /admin missing 'items in scope' label") } }