1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package form
import (
"testing"
"ticktock/internal/store"
)
func TestSplitTagsTrimsAndDropsEmpty(t *testing.T) {
got := SplitTags(" a , ,b,c ")
want := []string{"a", "b", "c"}
if len(got) != len(want) {
t.Fatalf("got %v want %v", got, want)
}
for i := range want {
if got[i] != want[i] {
t.Fatalf("got %v want %v", got, want)
}
}
}
func TestBuildEntryParsesTimesAndTags(t *testing.T) {
e, err := BuildEntry("2026-07-07", store.Entry{}, Values{
Start: "08:00", End: "09:30", Project: "ARCHER", Desc: "work", Tags: "a, b", Note: "n",
})
if err != nil {
t.Fatal(err)
}
if e.Start.Hour() != 8 || e.End.Hour() != 9 || e.End.Minute() != 30 {
t.Errorf("times wrong: %v..%v", e.Start, e.End)
}
if e.Project != "ARCHER" || e.Description != "work" || e.Notes != "n" {
t.Errorf("fields wrong: %+v", e)
}
if len(e.Tags) != 2 || e.Tags[0] != "a" || e.Tags[1] != "b" {
t.Errorf("tags wrong: %v", e.Tags)
}
}
func TestBuildEntryRejectsBadTime(t *testing.T) {
if _, err := BuildEntry("2026-07-07", store.Entry{}, Values{Start: "8am", End: "09:00"}); err == nil {
t.Fatal("expected error on bad start time")
}
}
func TestAddFormPrefillsStartEndProject(t *testing.T) {
var v Values
_ = AddForm("10:00", "10:30", "ARCHER", &v, Suggest{})
if v.Start != "10:00" || v.End != "10:30" || v.Project != "ARCHER" {
t.Errorf("add-form prefill wrong: %+v", v)
}
if v.Desc != "" || v.Tags != "" || v.Note != "" {
t.Errorf("add-form should leave desc/tags/note empty: %+v", v)
}
}
|