Support start/stop timer, manual durations, grouped reports, and per-ticket edit/delete of time entries with undo. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package command_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"task/internal/command"
|
|
"task/internal/ticket"
|
|
)
|
|
|
|
func TestHistoryPersistsAcrossOpen(t *testing.T) {
|
|
dir := t.TempDir()
|
|
store := ticket.NewJSONStore(dir)
|
|
path := command.HistoryPath(dir)
|
|
|
|
h1, err := command.OpenHistory(path, store, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := h1.Do(&command.CreateTicket{
|
|
Store: store,
|
|
Ticket: ticket.Ticket{
|
|
Title: "Persist me", ProjectID: "inbox", Status: ticket.StatusTodo,
|
|
},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(path); err != nil {
|
|
t.Fatalf("history file missing: %v", err)
|
|
}
|
|
|
|
h2, err := command.OpenHistory(path, store, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !h2.CanUndo() {
|
|
t.Fatal("expected undo after reload")
|
|
}
|
|
if err := h2.Undo(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
list, err := store.List("inbox")
|
|
if err != nil || len(list) != 0 {
|
|
t.Fatalf("after persistent undo: %v len=%d", err, len(list))
|
|
}
|
|
}
|
|
|
|
func TestHistoryCapsAtMax(t *testing.T) {
|
|
dir := t.TempDir()
|
|
store := ticket.NewJSONStore(dir)
|
|
h, err := command.OpenHistory(filepath.Join(dir, "history.json"), store, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for i := 0; i < command.MaxHistory+5; i++ {
|
|
if err := h.Do(&command.CreateTicket{
|
|
Store: store,
|
|
Ticket: ticket.Ticket{
|
|
Title: "t", ProjectID: "inbox", Status: ticket.StatusTodo,
|
|
},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// Count undos available
|
|
n := 0
|
|
for h.CanUndo() {
|
|
if err := h.Undo(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
n++
|
|
if n > command.MaxHistory+1 {
|
|
t.Fatal("undo stack larger than cap")
|
|
}
|
|
}
|
|
if n != command.MaxHistory {
|
|
t.Fatalf("undo count = %d, want %d", n, command.MaxHistory)
|
|
}
|
|
}
|