017c3c38fe
Address friction points identified in a full interface audit: - Re-add status badge to dashboard tiles so run state is visible at a glance - Add active nav indicator and SSE connection health monitor (live/stale) - Show manual registration form by default instead of hiding behind <details> - Add copy-to-clipboard buttons on SSH hold command and quick-register one-liner - Replace tooltip-only profile descriptions with inline visible text - Clarify non-destructive toggle with explicit stage impact description - Replace disabled "Start vetting" button with actionable offline guidance - Swap browser confirm() dialogs for styled inline confirmations - Add colored badge to spec diffs summary visible when collapsed - Add distinct "cancelled" mood for cancelled runs (vs idle) - Add match count to log search and aria-label for accessibility - Add styled 404 page rendered inside the app shell Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
173 lines
5.3 KiB
Go
173 lines
5.3 KiB
Go
package templates
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"vetting/internal/model"
|
|
)
|
|
|
|
func TestHumanAgoFrom(t *testing.T) {
|
|
now := time.Date(2026, 4, 17, 12, 0, 0, 0, time.UTC)
|
|
cases := []struct {
|
|
name string
|
|
ago time.Duration
|
|
want string
|
|
}{
|
|
{"just now", 5 * time.Second, "online"},
|
|
{"edge-just-under-minute", 59 * time.Second, "online"},
|
|
{"one minute", 60 * time.Second, "1m ago"},
|
|
{"five minutes", 5 * time.Minute, "5m ago"},
|
|
{"fifty-nine minutes", 59 * time.Minute, "59m ago"},
|
|
{"one hour", 1 * time.Hour, "1h ago"},
|
|
{"eight hours", 8 * time.Hour, "8h ago"},
|
|
{"one day", 24 * time.Hour, "1d ago"},
|
|
{"three days", 72 * time.Hour, "3d ago"},
|
|
// Clock skew: "future" heartbeat clamps to "online" rather than
|
|
// printing "-3m ago" or panicking.
|
|
{"future clamps to online", -5 * time.Second, "online"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := humanAgoFrom(now, now.Add(-tc.ago))
|
|
if got != tc.want {
|
|
t.Fatalf("humanAgoFrom(%v) = %q, want %q", tc.ago, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestHostTile_OverlayLink asserts the tile includes the tile-link <a>
|
|
// that makes the whole card clickable, and that the dashboard tile is
|
|
// stripped down to just hostname + last-seen badge — no action controls
|
|
// or run-state UI clogging the dashboard at scale.
|
|
func TestHostTile_OverlayLink(t *testing.T) {
|
|
now := time.Now()
|
|
data := TileData{
|
|
Host: model.Host{ID: 42, Name: "tile-test", MAC: "aa:bb:cc:dd:ee:ff"},
|
|
LastSeenAt: &now,
|
|
Latest: &model.Run{State: model.StateCompleted},
|
|
}
|
|
var buf strings.Builder
|
|
if err := HostTile(data).Render(context.Background(), &buf); err != nil {
|
|
t.Fatalf("render: %v", err)
|
|
}
|
|
html := buf.String()
|
|
if !strings.Contains(html, `href="/hosts/42"`) {
|
|
t.Fatalf("tile missing overlay href: %s", html)
|
|
}
|
|
if !strings.Contains(html, `class="tile-link"`) {
|
|
t.Fatalf("tile missing tile-link class: %s", html)
|
|
}
|
|
// Dropped content that used to live on the tile — confirm it has
|
|
// actually moved off so the slim-down is real. tile-status is
|
|
// intentionally re-added as a minimal status badge (issue #11).
|
|
for _, dropped := range []string{
|
|
`tile-meta`, `tile-log`, `tile-actions`, `tile-hold`,
|
|
`tile-primary-action`, `tile-start-form`,
|
|
`tile-nd-toggle`, `tile-cancel-form`,
|
|
`/hosts/42/start`, `/hosts/42/cancel`,
|
|
`Start vetting`, `Non-destructive`, `Cancel run`, `View report`,
|
|
} {
|
|
if strings.Contains(html, dropped) {
|
|
t.Errorf("slim tile still contains dropped content %q", dropped)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestHostTile_NoStageStrip: the tile no longer carries the Phase 3
|
|
// per-stage mini run-view — the runs-table on /hosts/{id} owns the
|
|
// stage-strip now. Guards against the regression that would bring
|
|
// `tile-steplist` / `tile-step-name` / `tile-run-duration` back.
|
|
func TestHostTile_NoStageStrip(t *testing.T) {
|
|
now := time.Now()
|
|
latest := &model.Run{
|
|
ID: 17,
|
|
State: model.StateSMART,
|
|
StartedAt: now.Add(-3 * time.Minute),
|
|
}
|
|
data := TileData{
|
|
Host: model.Host{ID: 42, Name: "tile-test", MAC: "aa:bb:cc:dd:ee:ff"},
|
|
Latest: latest,
|
|
LastSeenAt: &now,
|
|
}
|
|
var buf strings.Builder
|
|
if err := HostTile(data).Render(context.Background(), &buf); err != nil {
|
|
t.Fatalf("render: %v", err)
|
|
}
|
|
html := buf.String()
|
|
for _, dropped := range []string{
|
|
`tile-steplist`,
|
|
`tile-step-name`,
|
|
`tile-step-dot`,
|
|
`tile-run-id`,
|
|
`tile-run-duration`,
|
|
`tile-meta-row`,
|
|
} {
|
|
if strings.Contains(html, dropped) {
|
|
t.Errorf("host tile leaked dropped class %q: %s", dropped, html)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestTileStatusCancelledFromHold: a run that entered FailedHolding and
|
|
// was later Cancelled by the operator should read as a failure, not a
|
|
// plain cancel. The discriminator is FailedStage being set — mid-stage
|
|
// cancels leave it empty.
|
|
func TestTileStatusCancelledFromHold(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
run *model.Run
|
|
wantStatus string
|
|
wantMood string
|
|
}{
|
|
{
|
|
name: "cancelled from hold shows failed",
|
|
run: &model.Run{State: model.StateCancelled, FailedStage: "Storage"},
|
|
wantStatus: "Failed (cancelled)",
|
|
wantMood: "fail",
|
|
},
|
|
{
|
|
name: "mid-stage cancel gets cancelled mood",
|
|
run: &model.Run{State: model.StateCancelled},
|
|
wantStatus: "Cancelled",
|
|
wantMood: "cancelled",
|
|
},
|
|
{
|
|
name: "failed-holding itself still reads as FailedHolding",
|
|
run: &model.Run{State: model.StateFailedHolding, FailedStage: "Storage"},
|
|
wantStatus: string(model.StateFailedHolding),
|
|
wantMood: "fail",
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := tileStatus(tc.run); got != tc.wantStatus {
|
|
t.Errorf("tileStatus = %q, want %q", got, tc.wantStatus)
|
|
}
|
|
if got := tileMood(tc.run); got != tc.wantMood {
|
|
t.Errorf("tileMood = %q, want %q", got, tc.wantMood)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLastSeenLabelAndClass(t *testing.T) {
|
|
if got := lastSeenLabel(nil); got != "never" {
|
|
t.Fatalf("label nil = %q, want never", got)
|
|
}
|
|
if got := lastSeenClass(nil); got != "offline" {
|
|
t.Fatalf("class nil = %q, want offline", got)
|
|
}
|
|
recent := time.Now().Add(-5 * time.Second)
|
|
if got := lastSeenClass(&recent); got != "online" {
|
|
t.Fatalf("class recent = %q, want online", got)
|
|
}
|
|
stale := time.Now().Add(-10 * time.Minute)
|
|
if got := lastSeenClass(&stale); got != "stale" {
|
|
t.Fatalf("class stale = %q, want stale", got)
|
|
}
|
|
}
|