okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(tui): replace pick helpers with explicit branches8499f48

main
1.3 KiB45 linesraw
1// Jump-to-user keyboard navigation is interactive viewport state; headless daemon E2E has no PTY to drive shift+up/down.
2package tui
3
4import (
5	"strings"
6	"testing"
7
8	"albedo/cli/internal/daemon"
9	"github.com/charmbracelet/x/ansi"
10)
11
12func plainRows(lines []string) []string {
13	var rows []string
14	for _, row := range lines {
15		plain := []rune(strings.TrimRight(ansi.Strip(row), " "))
16		rows = append(rows, string(plain[min(railWidth, len(plain)):]))
17	}
18	return rows
19}
20
21func TestJumpToYouLandsOnYourMessages(t *testing.T) {
22	m := newTestChatModel(t, &daemon.Session{ID: "s"})
23	m.SetSize(100, 20)
24	for i := range int64(4) {
25		m.appendSettledEntry(HistoryEntry{Kind: EntryUser, Speaker: "You", Text: "question", Timestamp: 1 + i})
26		m.appendSettledEntry(HistoryEntry{Kind: EntryAssistant, Speaker: "albedo", Text: strings.Repeat("line\n", 15), Timestamp: 1 + i})
27	}
28	m.refreshViewportContent()
29	var landed []string
30	for range 3 {
31		m.jumpToYou(true)
32		landed = append(landed, plainRows(strings.Split(m.Viewport.View(), "\n")[:1])[0])
33	}
34	for _, top := range landed {
35		if top != "you" {
36			t.Fatalf("jump should put your message at the top, got %q", landed)
37		}
38	}
39	for range 4 {
40		m.jumpToYou(false)
41	}
42	if !m.Follow {
43		t.Fatal("jumping forward past your newest message should follow the live transcript")
44	}
45}