1package daemon
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/require"
7
8 "github.com/bnema/vev/internal/domain"
9 "github.com/bnema/vev/internal/protocol"
10)
11
12// TestSelectTabMovesOnlyThisAttachmentView proves the picker's in-place tab
13// switch: an exact tab selects it on the requesting attachment, a peer keeps
14// its own view, and an unknown or malformed tab leaves the view untouched.
15func TestSelectTabMovesOnlyThisAttachmentView(t *testing.T) {
16 tests := []struct {
17 name string
18 request func(second domain.TabStableID) protocol.SelectTab
19 moves bool
20 }{
21 {name: "exact tab", request: func(second domain.TabStableID) protocol.SelectTab { return protocol.SelectTab{TabID: second} }, moves: true},
22 {name: "unknown tab", request: func(domain.TabStableID) protocol.SelectTab { return protocol.SelectTab{TabID: "t_missing"} }},
23 {name: "malformed tab", request: func(domain.TabStableID) protocol.SelectTab { return protocol.SelectTab{} }},
24 }
25 for _, tt := range tests {
26 t.Run(tt.name, func(t *testing.T) {
27 d, sess, ac, _, releases := newManualTabSession(t, 2)
28 for _, release := range releases {
29 defer release()
30 }
31 peer := addMultiplexTestAttachment(t, sess, domain.Geometry{Size: domain.Size{Cols: 90, Rows: 30}})
32 rc := d.attachCoordinator(sess, nil, ac, true)
33 d.attachCoordinator(sess, nil, peer, true)
34 token := sess.captureAttachmentCapability(ac, ac.transport())
35 token.lease = rc.attachmentLease(ac)
36 ac.installTestAttachmentCapability(token)
37
38 first := domain.TabStableID(sess.tabs[0].stableID)
39 second := domain.TabStableID(sess.tabs[1].stableID)
40 require.True(t, sess.selectAttachmentTab(ac, first))
41 require.True(t, sess.selectAttachmentTab(peer, first))
42 before := ac.viewSnapshot()
43
44 require.False(t, d.handleAttachmentClientMessage(token, tt.request(second)))
45
46 if tt.moves {
47 require.Equal(t, second, ac.viewSnapshot().tabID)
48 } else {
49 require.Equal(t, before, ac.viewSnapshot(), "a refused selection never repairs the view")
50 }
51 require.Equal(t, first, peer.viewSnapshot().tabID, "the peer attachment keeps its own view")
52 })
53 }
54}