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.
258 lines
9.3 KiB
Go
258 lines
9.3 KiB
Go
package web_test
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestDashboardDefaultViewIsTiles asserts the default landing surface on
|
|
// /dashboard (no ?view= param) is the Tiles tab — m's Phase 5h pick.
|
|
func TestDashboardDefaultViewIsTiles(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
code, body := get(t, h, "/views/dashboard")
|
|
if code != 200 {
|
|
t.Fatalf("GET /dashboard → %d", code)
|
|
}
|
|
if !strings.Contains(body, `class="dash-tiles"`) {
|
|
t.Errorf("default view should be Tiles — body lacks 'class=\"dash-tiles\"'")
|
|
}
|
|
if strings.Contains(body, `class="card card-tasks"`) {
|
|
t.Errorf("default view should NOT render the Tasks 5-card layout")
|
|
}
|
|
}
|
|
|
|
// TestDashboardTabsRenderAllThree confirms the tab strip shows the three
|
|
// expected entries (Tiles / Tasks / Events) and marks the active one.
|
|
func TestDashboardTabsRenderAllThree(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
cases := []struct {
|
|
url string
|
|
activeTab string
|
|
activeLabel string
|
|
}{
|
|
{"/views/dashboard", "tiles", "Tiles"},
|
|
{"/views/dashboard?view=tasks", "tasks", "Tasks"},
|
|
{"/views/dashboard?view=events", "events", "Events"},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.activeTab, func(t *testing.T) {
|
|
code, body := get(t, h, c.url)
|
|
if code != 200 {
|
|
t.Fatalf("GET %s → %d", c.url, code)
|
|
}
|
|
if !strings.Contains(body, `class="dash-tabs"`) {
|
|
t.Errorf("expected dash-tabs nav element")
|
|
}
|
|
for _, label := range []string{"Tiles", "Tasks", "Events"} {
|
|
if !strings.Contains(body, label+"</a>") {
|
|
t.Errorf("tab strip missing label %q", label)
|
|
}
|
|
}
|
|
// Each <a class="dash-tab ..."> carries many HTMX attrs between
|
|
// the class and the label; look for the active class + the
|
|
// label somewhere later in the body. Approximate but stable.
|
|
activeIdx := strings.Index(body, `class="dash-tab active"`)
|
|
if activeIdx < 0 {
|
|
t.Fatalf("no active tab marker in body")
|
|
}
|
|
// Active label must appear after the active class marker AND
|
|
// within a reasonable window (one tab worth of HTML, ~300 chars).
|
|
window := body[activeIdx:]
|
|
if cut := strings.Index(window, `class="dash-tab"`); cut > 0 {
|
|
window = window[:cut]
|
|
}
|
|
if !strings.Contains(window, c.activeLabel) {
|
|
t.Errorf("active tab should be %q — active-class window does not contain it", c.activeLabel)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestDashboardTasksViewFallback confirms that ?view=tasks renders the
|
|
// today's 5-card layout (cards), not the tile grid.
|
|
func TestDashboardTasksViewFallback(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, body := get(t, h, "/views/dashboard?view=tasks")
|
|
if strings.Contains(body, `class="dash-tiles"`) {
|
|
t.Errorf("view=tasks should NOT render the Tiles grid")
|
|
}
|
|
// Cards either render with chrome or collapse to muted notes; either
|
|
// shape proves the cards partial dispatched, not Tiles.
|
|
if !strings.Contains(body, "No open tasks") {
|
|
t.Errorf("view=tasks with no deps should show collapsed 'No open tasks' note")
|
|
}
|
|
}
|
|
|
|
// TestDashboardEventsViewRenders confirms that ?view=events renders the
|
|
// promoted Events surface (dash-events-view) and not the cards or tiles.
|
|
// Also asserts the slice-5 polish: the empty state copy invites the user
|
|
// to link a CalDAV calendar so the dedicated tab doesn't feel broken.
|
|
func TestDashboardEventsViewRenders(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, body := get(t, h, "/views/dashboard?view=events")
|
|
if !strings.Contains(body, `class="dash-events-view"`) {
|
|
t.Errorf("view=events should render the promoted Events surface")
|
|
}
|
|
if strings.Contains(body, `class="dash-tiles"`) {
|
|
t.Errorf("view=events should NOT render the Tiles grid")
|
|
}
|
|
if strings.Contains(body, `class="card card-tasks"`) {
|
|
t.Errorf("view=events should NOT render the Tasks 5-card layout")
|
|
}
|
|
if !strings.Contains(body, "Link a CalDAV calendar") {
|
|
t.Errorf("empty-state copy should invite linking a calendar")
|
|
}
|
|
}
|
|
|
|
// TestDashboardUnknownViewFallsBackToTiles confirms graceful default
|
|
// behaviour: an unknown ?view= value renders Tiles, not a 404 or empty.
|
|
func TestDashboardUnknownViewFallsBackToTiles(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
code, body := get(t, h, "/views/dashboard?view=gibberish")
|
|
if code != 200 {
|
|
t.Fatalf("GET /dashboard?view=gibberish → %d", code)
|
|
}
|
|
if !strings.Contains(body, `class="dash-tiles"`) {
|
|
t.Errorf("unknown view should fall back to Tiles")
|
|
}
|
|
}
|
|
|
|
// TestDashboardTilesViewShowsRollupForSeededItem seeds an item, asserts
|
|
// the Tiles view renders a tile for it (the rollup runs across every
|
|
// active item, regardless of links).
|
|
func TestDashboardTilesViewShowsRollupForSeededItem(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 := "tile-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[], 'tile 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)
|
|
|
|
code, body := get(t, h, "/views/dashboard")
|
|
if code != 200 {
|
|
t.Fatalf("GET /dashboard → %d", code)
|
|
}
|
|
if !strings.Contains(body, `data-item-path="dev.`+slug+`"`) {
|
|
t.Errorf("expected tile for dev.%s on default Tiles view", slug)
|
|
}
|
|
// Title is rendered as text inside <a class="tile-title">…</a> with
|
|
// surrounding whitespace; a substring check is enough.
|
|
if !strings.Contains(body, "tile target") {
|
|
t.Errorf("expected tile title 'tile target' to appear in body")
|
|
}
|
|
}
|
|
|
|
// TestDashboardCacheKeySeparatesViews ensures the cache layer keys by
|
|
// (filter, view): the same filter under different views must hit
|
|
// independent cache entries. We prove this by priming /dashboard, then
|
|
// /views/dashboard?view=tasks, and asserting both report "fresh" on their
|
|
// first call (i.e. they don't share a cache slot).
|
|
func TestDashboardCacheKeySeparatesViews(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, body1 := get(t, h, "/views/dashboard")
|
|
if !strings.Contains(body1, "fresh") {
|
|
t.Fatalf("first /dashboard load should be fresh")
|
|
}
|
|
_, body2 := get(t, h, "/views/dashboard?view=tasks")
|
|
if !strings.Contains(body2, "fresh") {
|
|
t.Errorf("first /views/dashboard?view=tasks load should be fresh — sharing a cache slot with Tiles would mark it cached")
|
|
}
|
|
}
|
|
|
|
// TestDashboardScopeChipRendersOnTilesOnly asserts the scope chip
|
|
// (◇ current / ○ all) renders next to the tab strip on Tiles view
|
|
// only — Tasks and Events tabs don't have a scope concept.
|
|
func TestDashboardScopeChipRendersOnTilesOnly(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, tiles := get(t, h, "/views/dashboard")
|
|
if !strings.Contains(tiles, `class="dash-scope-chip"`) {
|
|
t.Errorf("Tiles view should render the scope chip")
|
|
}
|
|
if !strings.Contains(tiles, "◇ current") {
|
|
t.Errorf("default scope chip should show '◇ current'")
|
|
}
|
|
_, tasks := get(t, h, "/views/dashboard?view=tasks")
|
|
if strings.Contains(tasks, `class="dash-scope-chip"`) {
|
|
t.Errorf("Tasks view should NOT render the scope chip")
|
|
}
|
|
_, events := get(t, h, "/views/dashboard?view=events")
|
|
if strings.Contains(events, `class="dash-scope-chip"`) {
|
|
t.Errorf("Events view should NOT render the scope chip")
|
|
}
|
|
}
|
|
|
|
// TestDashboardScopeAllChipFlipsLabel asserts that scope=all renders
|
|
// the chip with the alternate label so m can flip back.
|
|
func TestDashboardScopeAllChipFlipsLabel(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, body := get(t, h, "/views/dashboard?scope=all")
|
|
if !strings.Contains(body, "○ all") {
|
|
t.Errorf("scope=all should render '○ all' chip label")
|
|
}
|
|
if strings.Contains(body, "◇ current") {
|
|
t.Errorf("scope=all should NOT render the '◇ current' label")
|
|
}
|
|
}
|
|
|
|
// TestDashboardScopeAllHidesQuietFold asserts that scope=all puts
|
|
// everything in the primary grid; no Quiet fold should render because
|
|
// nothing is "quiet" under that scope.
|
|
func TestDashboardScopeAllHidesQuietFold(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, body := get(t, h, "/views/dashboard?scope=all")
|
|
if strings.Contains(body, `class="dash-quiet"`) {
|
|
t.Errorf("scope=all should NOT render the Quiet fold — everything is in the primary grid")
|
|
}
|
|
}
|
|
|
|
// TestDashboardScopeChipURLFlips asserts the chip's href flips between
|
|
// ?scope=all and the default /dashboard each toggle.
|
|
func TestDashboardScopeChipURLFlips(t *testing.T) {
|
|
srv, pool := mustServer(t)
|
|
defer pool.Close()
|
|
h := srv.Routes()
|
|
_, defaultBody := get(t, h, "/views/dashboard")
|
|
if !strings.Contains(defaultBody, `href="/views/dashboard?scope=all"`) {
|
|
t.Errorf("default scope chip should link to ?scope=all")
|
|
}
|
|
_, allBody := get(t, h, "/views/dashboard?scope=all")
|
|
if !strings.Contains(allBody, `href="/views/dashboard"`) {
|
|
t.Errorf("scope=all chip should link back to /dashboard (scope=current is default+elided)")
|
|
}
|
|
}
|