▍ humdrum codex / ticktock v0.0.2

test(day): cover fmtTockDur and fmtRange (incl. running open-end)

b1293a923a4e83625a5f496bdde6107908baeb14
humdrum-tiv <45084903+humdrum-tiv@users.noreply.github.com> · 2026-07-07 17:40

parent 4db04e5b

1 files changed

internal/tui/day/model_test.go +30 −0
@@ -57,6 +57,36 @@ 		}
 	}
 }
 
+func TestFmtTockDur(t *testing.T) {
+	cases := map[time.Duration]string{
+		50*time.Minute + 35*time.Second: "50m35s",
+		time.Hour + 37*time.Minute:      "1h37m0s",
+		27*time.Minute + 9*time.Second:  "27m9s",
+		2*time.Hour + 3*time.Second:     "2h0m3s",
+	}
+	for in, want := range cases {
+		if got := fmtTockDur(in); got != want {
+			t.Errorf("fmtTockDur(%v) = %q, want %q", in, got, want)
+		}
+	}
+}
+
+func TestFmtRange(t *testing.T) {
+	d := func(h, m int) time.Time { return time.Date(2026, 7, 7, h, m, 0, 0, time.Local) }
+	ended := store.Entry{Start: d(9, 1), End: d(9, 51)}
+	if got := fmtRange(ended); got != "09:01 - 09:51" {
+		t.Errorf("ended range = %q, want %q", got, "09:01 - 09:51")
+	}
+	running := store.Entry{Start: d(9, 51)} // no End
+	got := fmtRange(running)
+	if !bytes.HasPrefix([]byte(got), []byte("09:51 - ")) {
+		t.Errorf("running range = %q, want prefix %q", got, "09:51 - ")
+	}
+	if bytes.Contains([]byte(got), []byte("00:00")) {
+		t.Errorf("running range should not render a zero end time: %q", got)
+	}
+}
+
 func TestDayRendersTableAndTotals(t *testing.T) {
 	fs := &fakeStore{days: map[string][]store.Entry{"2026-07-07": sample()}}
 	tm := teatest.NewTestModel(t, New(fs, "2026-07-07"),