v0.15.0 6b178f8

login_dialog_test.go RawHistoryFolder

1package modes
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/bnema/zut/packages/tui"
8)
9
10func TestLoginDialogProviderPickerFiltersLikeModelPicker(t *testing.T) {
11	d := newLoginDialog()
12	d.step = loginStepProvider
13	d.method = "apikey"
14	d.status = map[string]string{}
15	for _, r := range "llamacpp" {
16		d.HandleKey(tui.Key{Kind: tui.KeyRune, Rune: r})
17	}
18	options := d.providerOptions()
19	if len(options) != 1 || options[0] != "llama.cpp" {
20		t.Fatalf("options = %v", options)
21	}
22	d.HandleKey(tui.Key{Kind: tui.KeyEnter})
23	if d.step != loginStepLlamaURL {
24		t.Fatalf("step = %v", d.step)
25	}
26}
27
28func TestLoginDialogProviderPickerShowsNoMatches(t *testing.T) {
29	d := newLoginDialog()
30	d.step = loginStepProvider
31	d.method = "apikey"
32	d.status = map[string]string{}
33	d.providerQuery = "not-a-provider"
34	if options := d.providerOptions(); len(options) != 0 {
35		t.Fatalf("options = %v", options)
36	}
37	d.HandleKey(tui.Key{Kind: tui.KeyPageDown})
38	if d.cursor != 0 {
39		t.Fatalf("cursor = %d", d.cursor)
40	}
41	if action := d.HandleKey(tui.Key{Kind: tui.KeyEnter}); action != (loginDialogAction{}) {
42		t.Fatalf("action = %+v", action)
43	}
44}
45
46func TestLoginDialogLlamaCPPValidatesURLAndAcceptsOptionalKey(t *testing.T) {
47	d := newLoginDialog()
48	d.step = loginStepLlamaURL
49	d.provider = "llama.cpp"
50	d.method = "apikey"
51	d.llamaEd = tui.NewEditor("")
52
53	d.llamaEd.SetValue("file:///tmp/router")
54	if action := d.HandleKey(tui.Key{Kind: tui.KeyEnter}); action.SaveLlama || d.step != loginStepLlamaURL {
55		t.Fatalf("invalid URL advanced dialog: action=%+v step=%v", action, d.step)
56	}
57	if !strings.Contains(d.message, "http or https") {
58		t.Fatalf("validation message = %q", d.message)
59	}
60
61	d.llamaEd.SetValue("http://127.0.0.1:8080/v1/")
62	d.HandleKey(tui.Key{Kind: tui.KeyEnter})
63	if d.step != loginStepLlamaKey || d.llamaURL != "http://127.0.0.1:8080" {
64		t.Fatalf("step=%v URL=%q", d.step, d.llamaURL)
65	}
66	action := d.HandleKey(tui.Key{Kind: tui.KeyEnter})
67	if !action.SaveLlama || action.LlamaURL != "http://127.0.0.1:8080" || action.LlamaAPIKey != "" {
68		t.Fatalf("action = %+v", action)
69	}
70}
71
72func TestLoginDialogCursorPosMatchesPaddedInputRow(t *testing.T) {
73	d := newLoginDialog()
74	d.Open(t.TempDir())
75	d.method = "oauth"
76	d.provider = "anthropic"
77	d.ShowWaiting("https://example.com/oauth/authorize?code_challenge=abc&state=xyz")
78
79	lines := padDialogFrame(d.Render(tui.Theme{}, 80))
80	row, _ := d.CursorPos(80)
81	if row < 0 || row >= len(lines) {
82		t.Fatalf("CursorPos row = %d outside rendered lines %d", row, len(lines))
83	}
84	if got := stripANSIBytes(lines[row]); !strings.Contains(got, "▌") {
85		t.Fatalf("CursorPos row %d = %q; want editor input row", row, got)
86	}
87}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close