▍ humdrum codex / ticktock v0.0.2

test(day): cover enter-gating, date nav, and empty-day render through the Model

4db04e5ba9eff65dea9747162f0ccbed0f580488
humdrum-tiv <45084903+humdrum-tiv@users.noreply.github.com> · 2026-07-07 17:33

parent 29791a13

1 files changed

internal/tui/day/model_test.go +68 −0
@@ -98,3 +98,71 @@ 	if len(up.Tags) != 2 || up.Tags[0] != "a" || up.Tags[1] != "b" {
 		t.Errorf("tags = %v, want [a b]", up.Tags)
 	}
 }
+
+// loaded builds a Model with entries already loaded and the cursor at row i.
+func loaded(entries []store.Entry, i int) Model {
+	fs := &fakeStore{days: map[string][]store.Entry{"2026-07-07": entries}}
+	m := New(fs, "2026-07-07")
+	tm, _ := m.Update(entriesMsg{entries: entries})
+	m = tm.(Model)
+	m.tbl.SetCursor(i)
+	return m
+}
+
+func TestEnterOnEndedRowOpensEditor(t *testing.T) {
+	m := loaded(sample(), 0) // 2026-07-07-01, ended
+	tm, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
+	m = tm.(Model)
+	if !m.editing {
+		t.Fatal("enter on an ended row should open the editor")
+	}
+	if m.editKey != "2026-07-07-01" {
+		t.Errorf("editKey = %q, want 2026-07-07-01", m.editKey)
+	}
+	if m.form == nil {
+		t.Error("form should be constructed")
+	}
+}
+
+func TestEnterOnRunningRowIsIgnored(t *testing.T) {
+	d := func(h, mi int) time.Time { return time.Date(2026, 7, 7, h, mi, 0, 0, time.Local) }
+	entries := []store.Entry{
+		{Key: "2026-07-07-01", Start: d(9, 1), End: d(9, 51), Project: "ARCHER",
+			Description: "Admin", Duration: 50 * time.Minute},
+		{Key: "2026-07-07-02", Start: d(9, 51), Project: "ARCHER", // no End => running
+			Description: "Standup"},
+	}
+	m := loaded(entries, 1) // cursor on the running row
+	tm, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
+	m = tm.(Model)
+	if m.editing {
+		t.Fatal("enter on a running row must not open the editor")
+	}
+}
+
+func TestDateNavShiftsAndReloads(t *testing.T) {
+	m := loaded(sample(), 0)
+	tm, cmd := m.Update(tea.KeyMsg{Type: tea.KeyLeft})
+	m = tm.(Model)
+	if m.date != "2026-07-06" {
+		t.Errorf("left => date %q, want 2026-07-06", m.date)
+	}
+	if cmd == nil {
+		t.Error("left should return a reload command")
+	}
+	tm, _ = m.Update(tea.KeyMsg{Type: tea.KeyRight})
+	if got := tm.(Model).date; got != "2026-07-07" {
+		t.Errorf("right => date %q, want 2026-07-07", got)
+	}
+}
+
+func TestEmptyDayRendersNoEntries(t *testing.T) {
+	m := loaded(nil, 0)
+	view := m.View()
+	if !bytes.Contains([]byte(view), []byte("no entries")) {
+		t.Errorf("empty day view missing 'no entries':\n%s", view)
+	}
+	if !bytes.Contains([]byte(view), []byte("TOTAL 0m")) {
+		t.Errorf("empty day view missing 'TOTAL 0m':\n%s", view)
+	}
+}