Files
MujicaUI/chart/calendar_heatmap_test.go
T
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

99 lines
2.8 KiB
Go

package chart
import (
"testing"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/datetime"
)
func calendarValues() map[core.Date]float64 {
m := map[core.Date]float64{}
d := core.Date{Year: 2026, Month: time.January, Day: 1}
for i := range 365 {
if i%3 == 0 {
m[d.AddDays(i)] = float64(i % 11)
}
}
return m
}
func TestCalendarHeatmapKeysAndYear(t *testing.T) {
year := 2026
values := 0
start := datetime.WeekStartMonday
h := &chartHarness{build: func(c *ui.Context) ChartResult {
r := CalendarHeatmap(c, &year, calendarValues(), CalendarHeatmapOptions{Frame: ChartFrame{Label: "Prayers"}, WeekStart: start})
if r.ValueChanged() {
values++
}
return r
}}
tt := ui.NewTester(h.view, 560, 420)
tabTo(t, tt, "Prayers")
tt.Key(0, ui.KeyRight)
if got := chartReadout(tt); got != "2026-01-01 · 0" {
t.Fatalf("first day %q", got)
}
tt.Key(0, ui.KeyRight) // a week later
tt.Key(0, ui.KeyDown) // a day later
if got := chartReadout(tt); got != "2026-01-09 · no value" {
t.Fatalf("week and day %q", got)
}
tt.Key(0, ui.KeyEnd)
if got := chartReadout(tt); got != "2026-12-31 · no value" {
t.Fatalf("End %q", got)
}
if err := tt.Click("Next year"); err != nil {
t.Fatal(err)
}
if year != 2027 || values != 1 || !tt.HasText("2027") {
t.Fatalf("year %d events %d", year, values)
}
}
func TestCalendarHeatmapWeekStartHover(t *testing.T) {
year := 2026 // 1 January 2026 is a Thursday
for _, tc := range []struct {
start datetime.WeekStart
row int
}{{datetime.WeekStartSunday, 4}, {datetime.WeekStartMonday, 3}} {
h := &chartHarness{build: func(c *ui.Context) ChartResult {
return CalendarHeatmap(c, &year, calendarValues(), CalendarHeatmapOptions{Frame: ChartFrame{Label: "Prayers"}, WeekStart: tc.start})
}}
tt := ui.NewTester(h.view, 560, 420)
b := h.box(tt)
plotY := b.Y + b.H - 20 - 8 - 240 // above the readout line and gap
step := min((b.W-36)/53, float32(240-48)/7)
tt.Move(b.X+32+step/2, plotY+18+float32(tc.row)*step+step/2)
if got := chartReadout(tt); got != "2026-01-01 · 0" {
t.Fatalf("start %d: row %d reads %q", tc.start, tc.row, got)
}
}
}
func TestCalendarHeatmapBadYear(t *testing.T) {
defer func() {
if recover() == nil {
t.Fatal("no panic")
}
}()
year := 0
ui.NewTester(func(c *ui.Context) {
core.Use(c, core.Settings{})
CalendarHeatmap(c, &year, nil, CalendarHeatmapOptions{Frame: ChartFrame{Label: "x"}})
}, 300, 300)
}
func TestCalendarHeatmapSnapshot(t *testing.T) {
snapshot(t, "calendar_heatmap", 600, 260, func(c *ui.Context) {
year := 2026
ui.Column(c).Padding(16).Children(func() {
CalendarHeatmap(c, &year, calendarValues(), CalendarHeatmapOptions{Frame: ChartFrame{Label: "Prayers", Height: 150}, WeekStart: datetime.WeekStartMonday})
})
})
}