diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-09 22:02:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-09 22:02:59 +0300 |
| commit | 662dcfd7ca96d0d4157f9d30b04518db5adfbe45 (patch) | |
| tree | 7b1537b3aa27e233ce1b2a31e5c0a5395b5d5a68 /internal/tui/dashboard/model_test.go | |
| parent | eed407b0e252a0105619daf79b8bc236ff5f487d (diff) | |
show auto-reset countdown and document the cycle
Renders the next-tick countdown ("12s/30s") in the dashboard chrome so
users can see when aggregates will clear, and adds a dedicated H-help
line spelling out the cycle keys (off → 10s → 30s → 1m → 2m → 5m).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'internal/tui/dashboard/model_test.go')
| -rw-r--r-- | internal/tui/dashboard/model_test.go | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/internal/tui/dashboard/model_test.go b/internal/tui/dashboard/model_test.go index 2fb59f5..a6c4455 100644 --- a/internal/tui/dashboard/model_test.go +++ b/internal/tui/dashboard/model_test.go @@ -1699,14 +1699,20 @@ func TestSetFocusedReturnsNilWhenTimerDisabled(t *testing.T) { } // TestAutoResetStatusAddsPausedSuffixWhenBlurred locks in the chrome -// label contract: enabled+focused -> "auto-reset: 30s", -// enabled+blurred -> "auto-reset: 30s (paused)", disabled stays "off" -// regardless of focus. +// label contract: +// - enabled+focused -> "auto-reset: <remaining>/30s" (countdown). +// - enabled+blurred -> "auto-reset: 30s (paused)". +// - disabled stays "auto-reset: off" regardless of focus. +// +// The countdown value can fluctuate by a second between SetAutoResetInterval +// and the status read, so we accept "30s/30s" or "29s/30s" rather than +// pinning an exact remaining string. func TestAutoResetStatusAddsPausedSuffixWhenBlurred(t *testing.T) { m := NewModelWithConfig(nil, nil, 250, common.DefaultKeyMap()) m.SetAutoResetInterval(30 * time.Second) - if got, want := m.autoResetStatus(), "auto-reset: 30s"; got != want { - t.Fatalf("focused enabled status = %q, want %q", got, want) + got := m.autoResetStatus() + if got != "auto-reset: 30s/30s" && got != "auto-reset: 29s/30s" { + t.Fatalf("focused enabled status = %q, want auto-reset: 30s/30s or 29s/30s", got) } m.SetFocused(false) @@ -1724,3 +1730,32 @@ func TestAutoResetStatusAddsPausedSuffixWhenBlurred(t *testing.T) { t.Fatalf("focused disabled status = %q, want %q", got, want) } } + +// TestFormatAutoResetRemainingFormats exercises the duration formatter +// used by the chrome countdown: sub-minute durations stay in seconds, +// whole minutes drop the trailing "0s", and mixed values use "MmSs". +// Zero/negative remaining (deadline elapsed before the next tick) and +// the zero armedAt sentinel both render "0s" so the status line never +// shows an empty placeholder. +func TestFormatAutoResetRemainingFormats(t *testing.T) { + now := time.Now() + cases := []struct { + name string + armedAt time.Time + every time.Duration + want string + }{ + {"sub-minute", now, 12 * time.Second, "12s"}, + {"whole minute", now, 2 * time.Minute, "2m"}, + {"mixed", now, time.Minute + 23*time.Second, "1m23s"}, + {"zero armedAt", time.Time{}, 30 * time.Second, "0s"}, + {"elapsed deadline", now.Add(-5 * time.Second), 1 * time.Second, "0s"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if got := formatAutoResetRemaining(tc.armedAt, tc.every); got != tc.want { + t.Fatalf("formatAutoResetRemaining(%v, %v) = %q, want %q", tc.armedAt, tc.every, got, tc.want) + } + }) + } +} |
