1package core
2
3import (
4 "slices"
5 "testing"
6 "time"
7
8 "github.com/bnema/neferwl/internal/ports"
9)
10
11func TestOverviewStashInputNavigation(t *testing.T) {
12 for _, input := range []string{"swipe", "finger", "wheel", "bind"} {
13 t.Run(input, func(t *testing.T) {
14 c, _, sc, _ := stashRig(t, true)
15 m := sc.mon
16 w := m.Current()
17 before := stashIDs(w)
18 m.ToggleOverview()
19 var at time.Duration
20 move := func(dx, dy int, cancelled bool) {
21 t.Helper()
22 switch input {
23 case "swipe":
24 at += time.Second
25 c.swipeBegin(ports.SwipeBegin{Fingers: 3, Time: at})
26 for range 3 {
27 at += 8 * time.Millisecond
28 c.swipeUpdate(ports.SwipeUpdate{DX: float64(dx) * 40, DY: float64(dy) * 40, Time: at})
29 }
30 c.swipeEnd(ports.SwipeEnd{Cancelled: cancelled, Time: at})
31 case "finger", "wheel":
32 source := ports.AxisFinger
33 if input == "wheel" {
34 source = ports.AxisWheel
35 }
36 m.overviewScroll(ports.PointerAxis{Source: source,
37 Horizontal: ports.ScrollAxis{Set: dx != 0, Value: float64(dx) * 70, V120: int32(dx * 120)},
38 Vertical: ports.ScrollAxis{Set: dy != 0, Value: float64(dy) * 70, V120: int32(dy * 120)}})
39 c.scrollStop(ports.PointerAxis{Vertical: ports.ScrollAxis{Stop: true}})
40 case "bind":
41 a := ActionFocusWorkspaceDown
42 if dy < 0 {
43 a = ActionFocusWorkspaceUp
44 } else if dx > 0 {
45 a = ActionFocusColumnRight
46 }
47 m.overviewFocus(a)
48 }
49 }
50 if input == "swipe" {
51 move(0, -1, true)
52 if m.cardAt(w) != 2 {
53 t.Fatal("cancelled swipe changed selection")
54 }
55 }
56 move(0, -1, false)
57 if m.cardAt(w) != 1 {
58 t.Fatalf("up selected card %d, want 1", m.cardAt(w))
59 }
60 move(0, 1, false)
61 move(0, 1, false)
62 if m.Current() != w || m.cardAt(w) != 2 || !slices.Equal(stashIDs(w), before) {
63 t.Fatal("down escaped or reordered the stash")
64 }
65 move(1, 0, false)
66 if m.cardAt(w) >= 0 {
67 t.Fatal("right did not leave the stash")
68 }
69 })
70 }
71}