fix: render test coverage for blockSize 15/60 + today date comparison
affb3038a2324ce45e4551613b61d1f57989398c
humdrum-tiv <45084903+humdrum-tiv@users.noreply.github.com> · 2026-07-29 18:09
parent c67b9321
2 files changed
internal/cli/today.go +2 −2
@@ -23,10 +23,10 @@ client, err := RequireClient()
if err != nil {
return err
}
- isToday := date == ""
- if isToday {
+ if date == "" {
date = Today()
}
+ isToday := date == Today()
d, err := client.GetDay(date, TZ())
if err != nil {
return err
internal/render/grid_test.go +29 −17
@@ -1,6 +1,7 @@
package render
import (
+ "fmt"
"strings"
"testing"
@@ -9,22 +10,33 @@ "github.com/humdrum-tiv/dots-cli/internal/day"
)
func TestGridStructure(t *testing.T) {
- d := &api.DayData{
- BlockSize: 30,
- Types: []day.ActivityType{
- {ID: "t1", Name: "archer", Color: "#c04000"},
- },
- Blocks: map[int]string{28: "t1"},
- PlanBlocks: map[int]string{29: "t1"},
- }
- out := Grid(d, 29)
- // 48 slots at blockSize 30 → 6 rows of 8 (4h per row), each labeled with its start hour.
- for _, label := range []string{"0:00", "4:00", "8:00", "12:00", "16:00", "20:00"} {
- if !strings.Contains(out, label) {
- t.Fatalf("missing row label %s in:\n%s", label, out)
- }
- }
- if !strings.Contains(out, "archer") {
- t.Fatalf("missing legend entry:\n%s", out)
+ rowLabels := []string{"0:00", "4:00", "8:00", "12:00", "16:00", "20:00"}
+
+ for _, blockSize := range []int{15, 30, 60} {
+ t.Run(fmt.Sprintf("blockSize=%d", blockSize), func(t *testing.T) {
+ d := &api.DayData{
+ BlockSize: blockSize,
+ Types: []day.ActivityType{
+ {ID: "t1", Name: "archer", Color: "#c04000"},
+ },
+ Blocks: map[int]string{0: "t1"},
+ PlanBlocks: map[int]string{1: "t1"},
+ }
+ out := Grid(d, 0)
+
+ for _, label := range rowLabels {
+ if !strings.Contains(out, label) {
+ t.Errorf("blockSize %d: missing row label %q in output:\n%s", blockSize, label, out)
+ }
+ }
+ if !strings.Contains(out, "archer") {
+ t.Errorf("blockSize %d: missing legend entry for %q in output:\n%s", blockSize, "archer", out)
+ }
+
+ gotRows := strings.Count(strings.TrimRight(out, "\n"), "\n") - 1 // minus blank line before legend
+ if gotRows != 6 {
+ t.Errorf("blockSize %d: expected 6 rows, got %d", blockSize, gotRows)
+ }
+ })
}
}