Fix button timing and event decoding and avoid redundant menu refreshes
This commit is contained in:
8 files changed
+276
-44
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user