Per m's Q1 pick (b) (2026-05-29): legacy `/`, `/dashboard`, `/calendar`,
`/timeline`, `/graph` become `/views/{system-slug}`. Old routes
301-redirect to the new ones with chip params preserved; the legacy
?view=<uuid> param from 5i is resolved through the uuid → slug map
when present so old bookmarks land on the right user view.
System views (web/system_views.go):
- SystemView struct (Slug / Name / Icon / URL) — code-resident, never
rows in projax.views.
- AllSystemViews() returns the canonical five: tree, dashboard,
calendar, timeline, graph. Display order matches the existing
sidebar.
- LookupSystemView(slug) returns the matching entry or nil; the
reserved-slug list in store.IsReservedViewSlug (slice A) is kept
in sync.
- legacyRedirect(systemSlug) handler 301s with chip-param preservation
+ uuid → slug resolution for any leftover ?view=<uuid>.
Routes (web/server.go):
- GET /views/tree → handleTree (was GET /)
- GET /views/dashboard → handleDashboard
- GET /views/timeline → handleTimeline
- GET /views/calendar → handleCalendar
- GET /views/graph → handleGraph
- GET / → 301 → /views/tree
- GET /dashboard → 301 → /views/dashboard
- GET /timeline → 301 → /views/timeline
- GET /calendar → 301 → /views/calendar
- GET /graph → 301 → /views/graph
- POST action endpoints (/dashboard/task/*, /dashboard/pin, /admin/*)
stay where they are — those are RPC-ish, not page renders.
handleTree: dropped the `r.URL.Path != "/"` guard — the only entry
point now is /views/tree, mounted via the new route. Slice F removes
any residual references; this slice keeps the handler reachable.
computeChipCounts grew a `base string` arg so chip URLs anchor on the
caller's route (/views/tree for the system tree, /views/{slug} for
saved views). PageViewTypes recognises both legacy and /views/ keys
during the transition.
Template hrefs / hx-gets bulk-updated to the new URLs:
- layout.tmpl: every sidebar + bottom-nav entry points at
/views/{system-slug}. Active-state checks updated alongside.
- tree_section.tmpl, tree_card.tmpl, tree_kanban.tmpl: clear-filter
/ clear-all hrefs → /views/tree.
- calendar*.tmpl, timeline_section.tmpl, graph.tmpl,
dashboard_section.tmpl: every internal nav + filter link points at
the /views/{slug} surface.
- detail.tmpl, error.tmpl: cancel / back-to-tree → /views/tree.
Test-source updates (per the 5c sharpened rule):
- ~100 test paths bulk-rewritten from /dashboard /calendar /timeline
/graph (and `/`) to their /views/{slug} counterparts. The
behaviour-preservation contract holds: status codes + body shapes
for the rendered pages stay the same; only the URL anchoring the
test changes.
- layout_test.go: sidebar href assertions updated to /views/{slug}.
- view_type_test.go (Q2 + Q3 follow-up): PageViewTypes lookup table
updated to use the new route keys.
- 2 deliberate behaviour-change assertions land: TestLegacyRedirects
expects 301 on the old URLs (was 200); TestTreeRenders fetches
/views/tree (the new home) instead of /.
Internal go-source URL emissions (dashboard.go, calendar.go,
timeline.go) updated to the new BasePath so chip + refresh URLs round
through /views/{slug} correctly.
New tests:
- TestSystemViewLookup — AllSystemViews shape + LookupSystemView
round-trip + unknown-slug nil.
- TestLegacyRedirects — every legacy URL 301s to its new home with
chip params preserved.
- TestLegacyViewUUIDRedirect — old `?view=<uuid>` URLs land on the
resolved slug per m's Q3 pick.
95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package web_test
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/m/projax/web"
|
|
)
|
|
|
|
// TestSystemViewLookup verifies the code-resident lookup returns the
|
|
// expected slugs in display order, and that LookupSystemView round-trips
|
|
// each entry.
|
|
func TestSystemViewLookup(t *testing.T) {
|
|
all := web.AllSystemViews()
|
|
wantSlugs := []string{"tree", "dashboard", "calendar", "timeline", "graph"}
|
|
if len(all) != len(wantSlugs) {
|
|
t.Fatalf("AllSystemViews len = %d, want %d", len(all), len(wantSlugs))
|
|
}
|
|
for i, sv := range all {
|
|
if sv.Slug != wantSlugs[i] {
|
|
t.Errorf("position %d: slug = %q, want %q", i, sv.Slug, wantSlugs[i])
|
|
}
|
|
if sv.URL != "/views/"+sv.Slug {
|
|
t.Errorf("position %d: URL = %q, want /views/%s", i, sv.URL, sv.Slug)
|
|
}
|
|
round := web.LookupSystemView(sv.Slug)
|
|
if round == nil || round.Slug != sv.Slug {
|
|
t.Errorf("LookupSystemView(%q) round-trip failed", sv.Slug)
|
|
}
|
|
}
|
|
if web.LookupSystemView("not-a-system-slug") != nil {
|
|
t.Error("LookupSystemView should return nil for unknown slugs")
|
|
}
|
|
}
|
|
|
|
// TestLegacyRedirects verifies the slice C URL migration: each legacy
|
|
// route 301-redirects to its /views/{slug} counterpart with chip params
|
|
// preserved.
|
|
func TestLegacyRedirects(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
cases := []struct {
|
|
path, want string
|
|
}{
|
|
{"/", "/views/tree"},
|
|
{"/dashboard", "/views/dashboard"},
|
|
{"/calendar", "/views/calendar"},
|
|
{"/timeline", "/views/timeline"},
|
|
{"/graph", "/views/graph"},
|
|
// chip params survive the redirect:
|
|
{"/dashboard?tag=work", "/views/dashboard?tag=work"},
|
|
{"/timeline?from=2026-05-01", "/views/timeline?from=2026-05-01"},
|
|
}
|
|
for _, tc := range cases {
|
|
code, body := get(t, h, tc.path)
|
|
if code != 301 {
|
|
t.Errorf("GET %s status=%d body=%q, want 301", tc.path, code, body)
|
|
}
|
|
if !strings.Contains(body, `href="`+tc.want+`"`) {
|
|
t.Errorf("GET %s body=%q, want redirect to %q", tc.path, body, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestLegacyViewUUIDRedirect — when a legacy URL carries the 5i overlay
|
|
// `?view=<uuid>` param, the redirect resolves the uuid to the current
|
|
// slug (per m's Q3 pick), so old bookmarks land on the right user view.
|
|
func TestLegacyViewUUIDRedirect(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
ctx := context.Background()
|
|
stamp := strings.ReplaceAll(time.Now().UTC().Format("150405.000"), ".", "")
|
|
slug := "p5j-c-legacy-" + stamp
|
|
defer pool.Exec(context.Background(), `DELETE FROM projax.views WHERE slug = $1`, slug)
|
|
var id string
|
|
if err := pool.QueryRow(ctx, `
|
|
INSERT INTO projax.views (slug, name, filter_json)
|
|
VALUES ($1, 'Legacy', '{"view_type":"list"}'::jsonb)
|
|
RETURNING id`, slug).Scan(&id); err != nil {
|
|
t.Fatalf("seed view: %v", err)
|
|
}
|
|
// Old-style URL: /?view=<uuid>
|
|
code, body := get(t, h, "/?view="+id)
|
|
if code != 301 {
|
|
t.Fatalf("GET /?view=<uuid> status=%d body=%q want 301", code, body)
|
|
}
|
|
if !strings.Contains(body, "/views/"+slug) {
|
|
t.Errorf("redirect should resolve uuid → slug; got body=%q", body)
|
|
}
|
|
}
|