-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathui_focus_test.go
More file actions
108 lines (92 loc) · 3.28 KB
/
ui_focus_test.go
File metadata and controls
108 lines (92 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"context"
"strings"
"testing"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func TestFocusComponentUpdatesHelpTextAndBorders(t *testing.T) {
state := newUITestState()
treeView := state.components[TrChat].(*tview.TreeView)
chatView := state.components[ViChat].(*tview.List)
helpView := state.components[TvHelp].(*tview.TextView)
state.focusComponent(TrChat)
if got := helpView.GetText(true); !strings.Contains(got, "Tree") {
t.Fatalf("expected tree help text, got %q", got)
}
if got := treeView.GetBorderColor(); got != tcell.ColorYellow {
t.Fatalf("expected focused tree border color, got %v", got)
}
state.focusComponent(ViChat)
if got := helpView.GetText(true); !strings.Contains(got, "Msgs") {
t.Fatalf("expected message help text, got %q", got)
}
if got := chatView.GetBorderColor(); got != tcell.ColorYellow {
t.Fatalf("expected focused message border color, got %v", got)
}
if got := treeView.GetBorderColor(); got == tcell.ColorYellow {
t.Fatalf("expected tree border to be inactive, got %v", got)
}
}
func TestFocusMessagesPaneRequiresFocusableChatPane(t *testing.T) {
state := newUITestState()
state.focusComponent(TrChat)
state.chatPaneFocusable = false
state.focusMessagesPane()
if state.focusedComponent != TrChat {
t.Fatalf("expected focus to remain on tree, got %s", state.focusedComponent)
}
state.chatPaneFocusable = true
state.focusMessagesPane()
if state.focusedComponent != ViChat {
t.Fatalf("expected focus to move to messages, got %s", state.focusedComponent)
}
}
func TestHandleTreeSelectionChangeParentShowsHintAndClearsConversation(t *testing.T) {
state := newUITestState()
state.setCurrentConversation(ConversationTarget{ID: "19:chat", Title: "Incident Review"})
state.chatPaneFocusable = true
parentNode := tview.NewTreeNode("CyberSec")
parentNode.AddChild(tview.NewTreeNode("General"))
state.handleTreeSelectionChange(parentNode)
if _, ok, _, _ := state.currentConversationSnapshot(); ok {
t.Fatal("expected current conversation to be cleared for parent selection")
}
if state.chatPaneFocusable {
t.Fatal("expected chat pane to become unfocusable while showing a hint")
}
chatList := state.components[ViChat].(*tview.List)
mainText, secondaryText := chatList.GetItemText(0)
if !strings.Contains(mainText, "CyberSec") {
t.Fatalf("expected team-specific hint text, got %q", mainText)
}
if !strings.Contains(secondaryText, "Right expands") {
t.Fatalf("expected navigation hint, got %q", secondaryText)
}
}
func TestChatKeyHandlerReturnsFocusToTree(t *testing.T) {
state := newUITestState()
state.chatPaneFocusable = true
state.focusComponent(ViChat)
handler := state.chatKeyHandler()
if got := handler(tcell.NewEventKey(tcell.KeyTab, 0, tcell.ModNone)); got != nil {
t.Fatalf("expected tab to be handled, got %v", got)
}
if state.focusedComponent != TrChat {
t.Fatalf("expected focus to return to tree, got %s", state.focusedComponent)
}
}
func newUITestState() *AppState {
state := &AppState{
app: tview.NewApplication(),
logger: discardLogger,
messageLimit: defaultMessageLimit,
pages: tview.NewPages(),
components: map[string]tview.Primitive{},
}
state.initRuntime(context.Background())
root := state.createMainView()
state.app.SetRoot(root, true)
return state
}