Configurable grid + snap-to-grid in the layout system (#45)
Build image / build-and-push (push) Successful in 7s

Closes #44. Two independent grids (garden + per-bed), each with a size and a snap toggle; snapping defaults off. See PR #45 for details.

Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #45.
This commit is contained in:
2026-07-19 07:07:14 +00:00
committed by steve
parent 9968c06243
commit e74fb308c1
23 changed files with 581 additions and 88 deletions
+46
View File
@@ -57,6 +57,7 @@ func TestCreateGardenValidation(t *testing.T) {
{Name: "X", WidthCM: math.NaN()}, // NaN slips past naive < / >
{Name: "X", HeightCM: math.Inf(1)}, // +Inf
{Name: "X", WidthCM: math.SmallestNonzeroFloat64}, // subnormal, > 0 but < 1 cm
{Name: "X", GridSizeCM: maxGardenCM + 1}, // grid over the cap
}
for i, in := range cases {
if _, err := s.CreateGarden(context.Background(), owner, in); !errors.Is(err, domain.ErrInvalidInput) {
@@ -70,6 +71,51 @@ func TestCreateGardenValidation(t *testing.T) {
}
}
func TestGardenGridSettings(t *testing.T) {
s := newTestService(t, openConfig())
owner := seedUser(t, s, "[email protected]")
ctx := context.Background()
// An omitted grid size lands the default; snap defaults off.
g, err := s.CreateGarden(ctx, owner, GardenInput{Name: "G"})
if err != nil {
t.Fatalf("CreateGarden: %v", err)
}
if g.GridSizeCM != defaultGardenGridCM {
t.Errorf("grid = %v, want default %d", g.GridSizeCM, defaultGardenGridCM)
}
if g.SnapToGrid {
t.Error("snap should default off")
}
// An update sets an explicit grid and turns snap on; both persist.
up, err := s.UpdateGarden(ctx, owner, g.ID, GardenInput{
Name: "G", WidthCM: g.WidthCM, HeightCM: g.HeightCM, UnitPref: g.UnitPref,
GridSizeCM: 25, SnapToGrid: true,
}, g.Version)
if err != nil {
t.Fatalf("UpdateGarden: %v", err)
}
got, err := s.GetGarden(ctx, owner, g.ID)
if err != nil {
t.Fatalf("GetGarden: %v", err)
}
if got.GridSizeCM != 25 || !got.SnapToGrid {
t.Errorf("persisted grid=%v snap=%v, want 25/true", got.GridSizeCM, got.SnapToGrid)
}
// An update omitting the grid size (0) is re-defaulted, not stored as 0.
up2, err := s.UpdateGarden(ctx, owner, g.ID, GardenInput{
Name: "G", WidthCM: g.WidthCM, HeightCM: g.HeightCM, UnitPref: g.UnitPref,
}, up.Version)
if err != nil {
t.Fatalf("UpdateGarden(reset): %v", err)
}
if up2.GridSizeCM != defaultGardenGridCM || up2.SnapToGrid {
t.Errorf("after omit grid=%v snap=%v, want default/false", up2.GridSizeCM, up2.SnapToGrid)
}
}
func TestListGardensOwnedOnly(t *testing.T) {
s := newTestService(t, openConfig())
alice := seedUser(t, s, "[email protected]")