xonecas.io
62159
Sy

symb / files

symb / internal / tui / toolview_test.go

2.2 KB
1package tui
2
3import (
4	"testing"
5
6	tea "charm.land/bubbletea/v2"
7	"github.com/xonecas/symb/internal/provider"
8)
9
10// TestToolViewModalOpensOnViewClick verifies that clicking the [view] button
11// on a tool result entry opens the tool view modal.
12func TestToolViewModalOpensOnViewClick(t *testing.T) {
13	initTheme("vulcan")
14	m := New(nil, nil, nil, nil, "test", nil, "s", nil, nil, nil, "p", nil, nil, nil, provider.Options{}, "vulcan")
15	updated, _ := m.Update(tea.WindowSizeMsg{Width: 120, Height: 40})
16	m = updated.(Model)
17
18	// Inject a tool result entry.
19	entry := convEntry{
20		display:  m.styles.ToolArrow.Render("←") + m.styles.BgFill.Render("  ") + m.styles.Dim.Render("Read foo.go") + m.styles.BgFill.Render("  ") + m.styles.Clickable.Render("view"),
21		kind:     entryToolResult,
22		full:     "Read foo.go\nsome content",
23		toolName: "Read",
24	}
25	m.convEntries = append(m.convEntries, entry)
26	m.frameLines = nil
27
28	// Place the click at the [view] label: last 4 visible chars of the display.
29	lines := m.wrappedConvLines()
30	if len(lines) == 0 {
31		t.Fatal("no conv lines")
32	}
33	convX := m.layout.conv.Min.X
34	convY := m.layout.conv.Min.Y
35
36	// col within conv pane pointing at "view" (last 4 chars of display).
37	import_lipgloss_width := func(s string) int {
38		// inline: strip ANSI and count runes
39		n := 0
40		inEsc := false
41		for _, r := range s {
42			if inEsc {
43				if r == 'm' {
44					inEsc = false
45				}
46				continue
47			}
48			if r == '\x1b' {
49				inEsc = true
50				continue
51			}
52			n++
53		}
54		return n
55	}
56	lw := import_lipgloss_width(entry.display)
57	viewCol := lw - 2 // somewhere inside "view"
58
59	clickX := convX + viewCol
60	clickY := convY
61
62	// MouseClickMsg sets convSel; MouseReleaseMsg fires the click handler returning a Cmd.
63	u1, _ := m.Update(tea.MouseClickMsg{X: clickX, Y: clickY, Button: tea.MouseLeft})
64	m = u1.(Model)
65	u2, cmd := m.Update(tea.MouseReleaseMsg{X: clickX, Y: clickY, Button: tea.MouseLeft})
66	m = u2.(Model)
67
68	// The cmd carries openToolViewMsg; dispatch it.
69	if cmd == nil {
70		t.Fatal("expected a Cmd from the release, got nil")
71	}
72	msg := cmd()
73	u3, _ := m.Update(msg)
74	m = u3.(Model)
75
76	if m.toolViewModal == nil {
77		t.Fatal("toolViewModal is nil after dispatching openToolViewMsg")
78	}
79}