1package core_test
2
3import (
4 "testing"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9// A publish that changes nothing on an output keeps that output's Seq, so
10// its owner does not recompose; a real change takes a new one.
11func TestSceneSeqKeptWhenNothingChanged(t *testing.T) {
12 r := startSwipe(t, nil)
13 first := r.mapWindow(t, 1)[0]
14 if first.Seq == 0 {
15 t.Fatal("scene without Seq")
16 }
17 // Focus-column-left at the left edge changes nothing but still publishes.
18 again := r.key(t, "Left", ports.ModAlt)[0]
19 if again.Seq != first.Seq || !again.SameAs(first) {
20 t.Fatalf("Seq %d, want the held %d", again.Seq, first.Seq)
21 }
22 next := r.mapWindow(t, 2)[0]
23 if next.Seq <= first.Seq || len(next.Windows) != 2 {
24 t.Fatalf("Seq %d after mapping a window (was %d), %d windows", next.Seq, first.Seq, len(next.Windows))
25 }
26}
27
28// A key that starts a transition can publish a scene that draws what the
29// previous one did (the springs start there): it still gets a fresh Seq, or
30// the outputs would drop it and the motion would wait for the fallback timer
31// to begin.
32func TestAnimatingKeyGetsFreshSeq(t *testing.T) {
33 tests := []struct {
34 name string
35 edit func(*ports.Config)
36 // setup returns the scene before the key.
37 setup func(*testing.T, *swipeRig) ports.Scene
38 sym string
39 mods ports.Mods
40 // same: the key's scene draws what the previous one did.
41 same bool
42 }{
43 {"width change", func(c *ports.Config) { c.Binds["Cmd+Ctrl+Right"] = "set-column-width +10%" },
44 func(t *testing.T, r *swipeRig) ports.Scene {
45 twoColumns(t, r)
46 return r.key(t, "Left", ports.ModAlt)[0]
47 }, "Right", ports.ModAlt | ports.ModCtrl, true},
48 {"focus scroll", nil, func(t *testing.T, r *swipeRig) ports.Scene {
49 threeColumns(t, r)
50 return r.key(t, "Left", ports.ModAlt)[0] // 2 is on screen: no scroll
51 }, "Left", ports.ModAlt, false},
52 }
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 r := startSwipe(t, tt.edit)
56 prev := tt.setup(t, r)
57 s := r.key(t, tt.sym, tt.mods)[0]
58 if s.SameAs(prev) != tt.same {
59 t.Fatalf("scene right after the key same as the previous one: %t, want %t", s.SameAs(prev), tt.same)
60 }
61 if s.Seq <= prev.Seq {
62 t.Fatalf("Seq %d right after the key, want a new one (was %d)", s.Seq, prev.Seq)
63 }
64 })
65 }
66}
67
68// A key that animates nothing keeps its output's Seq.
69func TestNoOpKeyKeepsSeqWithAnimationsOn(t *testing.T) {
70 r := startSwipe(t, nil)
71 threeColumns(t, r)
72 first := r.key(t, "Right", ports.ModAlt)[0] // 3 is the last column
73 for range 2 {
74 if s := r.key(t, "Right", ports.ModAlt)[0]; s.Seq != first.Seq || !s.SameAs(first) {
75 t.Fatalf("Seq %d on a key at the edge, want the held %d", s.Seq, first.Seq)
76 }
77 }
78}