1package core
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "github.com/bnema/neferwl/internal/ports"
9)
10
11// stepScenes steps only the screen and returns the scene of each output.
12func stepScenes(t *testing.T, c *Core, only *screen) map[string]ports.Scene {
13 t.Helper()
14 if err := c.step(context.Background(), only); err != nil {
15 t.Fatal(err)
16 }
17 out := map[string]ports.Scene{}
18 for _, s := range <-c.ch.Scenes {
19 out[s.Output] = s
20 }
21 return out
22}
23
24// While the focus pulse runs on the focused output, a flip of another output
25// keeps the focused output's Seq; its own flip samples the pulse.
26func TestFlipOfOtherOutputKeepsPulseSeq(t *testing.T) {
27 c, ic := pulseCore(t)
28 a := c.cur()
29 c.addScreen(ports.OutputInfo{Name: "B", Width: 300, Height: 200})
30 b := c.screens[1]
31 for id := WindowID(3); id <= 5; id++ {
32 b.mon.AddWindow(id)
33 }
34 indicatorScene(t, c)
35
36 // A pulse on window 1 of A.
37 a.mon.Current().FocusID(1)
38 indicatorScene(t, c)
39 ic.now = ic.now.Add(pulseSettle)
40 if !c.pulseTick() {
41 t.Fatal("no pulse after settle")
42 }
43 // A camera transition runs on B.
44 w := b.mon.Current()
45 w.shift = 100
46 w.motion = newMotion(viewSpring(w.shift, 0), ic.now, 1)
47
48 ic.now = ic.now.Add(pulseRise / 2)
49 first := stepScenes(t, c, a)
50 if pulseOf(first["A"], 1) <= 0 {
51 t.Fatalf("no pulse on A: %v", pulseOf(first["A"], 1))
52 }
53 ic.now = ic.now.Add(10 * time.Millisecond)
54 second := stepScenes(t, c, b)
55 if second["A"].Seq != first["A"].Seq || !second["A"].SameAs(first["A"]) {
56 t.Fatalf("A changed on a flip of B: Seq %d, was %d", second["A"].Seq, first["A"].Seq)
57 }
58 if second["B"].SameAs(first["B"]) {
59 t.Fatal("B did not move on its own flip")
60 }
61 ic.now = ic.now.Add(10 * time.Millisecond)
62 third := stepScenes(t, c, a)
63 if third["A"].Seq <= second["A"].Seq || pulseOf(third["A"], 1) == pulseOf(second["A"], 1) {
64 t.Fatalf("A did not sample the pulse on its own flip: Seq %d, was %d", third["A"].Seq, second["A"].Seq)
65 }
66 if third["B"].Seq != second["B"].Seq {
67 t.Fatalf("B changed on a flip of A: Seq %d, was %d", third["B"].Seq, second["B"].Seq)
68 }
69}