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.
170 lines
5.9 KiB
Go
170 lines
5.9 KiB
Go
package web_test
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestDashboardPinTogglesItem seeds an item with pinned=false, POSTs to
|
|
// /dashboard/pin with pin=true, then asserts the row in projax.items is
|
|
// now pinned and the Tiles view renders the tile with the .pinned class.
|
|
func TestDashboardPinTogglesItem(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
stamp := strings.ReplaceAll(time.Now().UTC().Format("150405.000000"), ".", "")
|
|
slug := "pin-target-" + stamp
|
|
var dev, id string
|
|
if err := pool.QueryRow(ctx, `select id from projax.items where slug='dev' and cardinality(parent_ids)=0`).Scan(&dev); err != nil {
|
|
t.Fatalf("dev: %v", err)
|
|
}
|
|
if err := pool.QueryRow(ctx,
|
|
`insert into projax.items (kind, title, slug, parent_ids)
|
|
values (array['project']::text[], 'pin target', $1, ARRAY[$2]::uuid[])
|
|
returning id`,
|
|
slug, dev,
|
|
).Scan(&id); err != nil {
|
|
t.Fatalf("seed item: %v", err)
|
|
}
|
|
defer pool.Exec(context.Background(), `delete from projax.items where id=$1`, id)
|
|
|
|
// POST pin=true.
|
|
form := url.Values{"id": {id}, "pin": {"true"}}
|
|
code, _ := post(t, h, "/dashboard/pin", form)
|
|
if code != 200 {
|
|
t.Fatalf("POST /dashboard/pin → %d", code)
|
|
}
|
|
var pinned bool
|
|
if err := pool.QueryRow(ctx, `select pinned from projax.items where id=$1`, id).Scan(&pinned); err != nil {
|
|
t.Fatalf("read pinned: %v", err)
|
|
}
|
|
if !pinned {
|
|
t.Errorf("expected pinned=true after POST")
|
|
}
|
|
|
|
// The re-render should mark the tile as .tile-pinned.
|
|
_, body := get(t, h, "/views/dashboard")
|
|
tileIdx := strings.Index(body, `data-item-id="`+id+`"`)
|
|
if tileIdx < 0 {
|
|
t.Fatalf("pinned tile not found in re-render")
|
|
}
|
|
openTag := body[strings.LastIndex(body[:tileIdx], "<article"):tileIdx]
|
|
if !strings.Contains(openTag, "tile-pinned") {
|
|
t.Errorf("tile should carry 'tile-pinned' class — got %q", openTag)
|
|
}
|
|
}
|
|
|
|
// TestDashboardPinUnpinsItem seeds a pinned item, POSTs pin=false, and
|
|
// asserts the row is no longer pinned.
|
|
func TestDashboardPinUnpinsItem(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
stamp := strings.ReplaceAll(time.Now().UTC().Format("150405.000000"), ".", "")
|
|
slug := "unpin-target-" + stamp
|
|
var dev, id string
|
|
if err := pool.QueryRow(ctx, `select id from projax.items where slug='dev' and cardinality(parent_ids)=0`).Scan(&dev); err != nil {
|
|
t.Fatalf("dev: %v", err)
|
|
}
|
|
if err := pool.QueryRow(ctx,
|
|
`insert into projax.items (kind, title, slug, parent_ids, pinned)
|
|
values (array['project']::text[], 'unpin target', $1, ARRAY[$2]::uuid[], true)
|
|
returning id`,
|
|
slug, dev,
|
|
).Scan(&id); err != nil {
|
|
t.Fatalf("seed item: %v", err)
|
|
}
|
|
defer pool.Exec(context.Background(), `delete from projax.items where id=$1`, id)
|
|
|
|
form := url.Values{"id": {id}, "pin": {"false"}}
|
|
code, _ := post(t, h, "/dashboard/pin", form)
|
|
if code != 200 {
|
|
t.Fatalf("POST /dashboard/pin → %d", code)
|
|
}
|
|
var pinned bool
|
|
if err := pool.QueryRow(ctx, `select pinned from projax.items where id=$1`, id).Scan(&pinned); err != nil {
|
|
t.Fatalf("read pinned: %v", err)
|
|
}
|
|
if pinned {
|
|
t.Errorf("expected pinned=false after POST pin=false")
|
|
}
|
|
}
|
|
|
|
// TestDashboardPinRequiresID asserts the handler rejects missing-id
|
|
// requests with 400 rather than silently no-op'ing.
|
|
func TestDashboardPinRequiresID(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
form := url.Values{"pin": {"true"}}
|
|
code, _ := post(t, h, "/dashboard/pin", form)
|
|
if code != 400 {
|
|
t.Errorf("expected 400 for missing id, got %d", code)
|
|
}
|
|
}
|
|
|
|
// TestDashboardPinInvalidatesCache asserts a pin flip busts the
|
|
// dashboard cache so subsequent renders reflect the new pinned state.
|
|
// The pin handler invalidates then re-renders, which re-populates the
|
|
// cache with FRESH data — so the next external GET serves the new
|
|
// state (the assertion is on data correctness, not the cached label).
|
|
func TestDashboardPinInvalidatesCache(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
stamp := strings.ReplaceAll(time.Now().UTC().Format("150405.000000"), ".", "")
|
|
slug := "cache-pin-" + stamp
|
|
var dev, id string
|
|
if err := pool.QueryRow(ctx, `select id from projax.items where slug='dev' and cardinality(parent_ids)=0`).Scan(&dev); err != nil {
|
|
t.Fatalf("dev: %v", err)
|
|
}
|
|
if err := pool.QueryRow(ctx,
|
|
`insert into projax.items (kind, title, slug, parent_ids)
|
|
values (array['project']::text[], 'cache pin', $1, ARRAY[$2]::uuid[])
|
|
returning id`,
|
|
slug, dev,
|
|
).Scan(&id); err != nil {
|
|
t.Fatalf("seed item: %v", err)
|
|
}
|
|
defer pool.Exec(context.Background(), `delete from projax.items where id=$1`, id)
|
|
|
|
// Prime the cache — first GET caches an unpinned tile state.
|
|
_, primed := get(t, h, "/views/dashboard")
|
|
tileIdx := strings.Index(primed, `data-item-id="`+id+`"`)
|
|
if tileIdx < 0 {
|
|
t.Fatalf("seeded tile missing from primed dashboard")
|
|
}
|
|
openTag := primed[strings.LastIndex(primed[:tileIdx], "<article"):tileIdx]
|
|
if strings.Contains(openTag, "tile-pinned") {
|
|
t.Fatalf("setup: fresh tile should not be pinned yet — got %q", openTag)
|
|
}
|
|
|
|
// Flip pin.
|
|
form := url.Values{"id": {id}, "pin": {"true"}}
|
|
_, _ = post(t, h, "/dashboard/pin", form)
|
|
|
|
// Next GET must reflect the new pinned state — proves the cache
|
|
// entry for the previous (unpinned) state was invalidated.
|
|
_, after := get(t, h, "/views/dashboard")
|
|
tileIdx2 := strings.Index(after, `data-item-id="`+id+`"`)
|
|
if tileIdx2 < 0 {
|
|
t.Fatalf("tile missing from post-pin dashboard")
|
|
}
|
|
openTag2 := after[strings.LastIndex(after[:tileIdx2], "<article"):tileIdx2]
|
|
if !strings.Contains(openTag2, "tile-pinned") {
|
|
t.Errorf("pin flip should invalidate cache so next GET shows pinned tile — got %q", openTag2)
|
|
}
|
|
}
|