Fix button timing and event decoding and avoid redundant menu refreshes

This commit is contained in:
maze committed 2026-10-29 19:07:17 +01:00
1 parent 62b32c15cf
commit 494fa41420
8 files changed
+276 -44

No files matched your search

+33
View File
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/BeatGlow/beatglow/app"
"github.com/BeatGlow/beatglow/hardware"
)
type navigationTestLayout struct {
@@ -35,3 +36,35 @@ func TestSettingsReturnsToActiveLayout(t *testing.T) {
}
}
}
type inputTestLayout struct {
navigationTestLayout
onPress func(app.Context)
presses int
}
func (l *inputTestLayout) HandleButtonPress(ctx app.Context) {
l.presses++
if l.onPress != nil {
l.onPress(ctx)
}
}
func (l *inputTestLayout) HandleButtonLongPress(ctx app.Context) { l.HandleButtonPress(ctx) }
func TestButtonEventIsNotRedispatchedAfterScreenChange(t *testing.T) {
for _, long := range []bool{false, true} {
first := &inputTestLayout{navigationTestLayout: navigationTestLayout{name: "first"}}
second := &inputTestLayout{navigationTestLayout: navigationTestLayout{name: "second"}}
c := &controllerContext{layouts: []app.Layout{first, second}}
c.Show(first)
first.onPress = func(ctx app.Context) { ctx.Show(second) }
if long {
c.handleInput(hardware.RotaryLongPressEvent{})
} else {
c.handleInput(hardware.RotaryPressEvent{})
}
if first.presses != 1 || second.presses != 0 {
t.Fatalf("event was redispatched: first=%d second=%d", first.presses, second.presses)
}
}
}