summaryrefslogtreecommitdiff
path: root/internal/hexaiaction/tui_delegate_test.go
blob: 4bdb35962e5587a2b5fcc31cfe65a3f32844f95a (plain)
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
package hexaiaction

import (
	"bytes"
	"regexp"
	"testing"

	"github.com/charmbracelet/bubbles/list"
)

func stripANSI(s string) string {
	re := regexp.MustCompile(`\x1b\[[0-9;]*m`)
	return re.ReplaceAllString(s, "")
}

func TestOneLineDelegate_Render(t *testing.T) {
	items := []list.Item{item{title: "Rewrite selection", kind: ActionRewrite, hotkey: 'r'}}
	m := list.New(items, oneLineDelegate{}, 0, 0)
	m.Select(0)
	var b bytes.Buffer
	oneLineDelegate{}.Render(&b, m, 0, items[0])
	out := stripANSI(b.String())
	if !regexp.MustCompile(`> \w`).MatchString(out) {
		t.Fatalf("expected cursor prefix in %q", out)
	}
	if !regexp.MustCompile(`Rewrite selection`).MatchString(out) {
		t.Fatalf("expected title in %q", out)
	}
	if !regexp.MustCompile(`\(r\)`).MatchString(out) {
		t.Fatalf("expected hotkey in %q", out)
	}
}