v0.2.97 d25ea2b

confirm_dialog_test.go RawHistoryFolder

1package modes
2
3import (
4	"context"
5	"encoding/json"
6	"strings"
7	"testing"
8
9	"github.com/patriceckhart/zot/packages/core"
10	"github.com/patriceckhart/zot/packages/tui"
11)
12
13func TestConfirmDialogAllowsToolExpansion(t *testing.T) {
14	resp := make(chan core.ConfirmDecision, 1)
15	dialog := newConfirmDialog()
16	dialog.Enqueue(&confirmRequest{
17		toolName: "edit",
18		preview:  "large edit",
19		resp:     resp,
20	})
21	args, err := json.Marshal(map[string]any{
22		"path": "sample.ts",
23		"edits": []map[string]string{{
24			"oldText": "old",
25			"newText": strings.Repeat("const value = 1\n", 20),
26		}},
27	})
28	if err != nil {
29		t.Fatal(err)
30	}
31	view := &tui.View{
32		ToolCalls: []tui.ToolCallView{{
33			ID:         "call-1",
34			Name:       "edit",
35			RawJSONBuf: string(args),
36			LivePath:   "sample.ts",
37		}},
38	}
39	i := &Interactive{
40		view:          view,
41		confirmDialog: dialog,
42		dirty:         make(chan struct{}, 1),
43	}
44	if rendered := strings.Join(view.Build(80), "\n"); !strings.Contains(rendered, "ctrl+o to expand") {
45		t.Fatalf("test preview was not initially collapsed:\n%s", rendered)
46	}
47
48	i.handleKey(context.Background(), tui.Key{Kind: tui.KeyCtrlO})
49
50	if !i.view.ExpandAll {
51		t.Fatal("ctrl+o did not expand tool previews while confirmation was active")
52	}
53	if rendered := strings.Join(view.Build(80), "\n"); strings.Contains(rendered, "ctrl+o to expand") {
54		t.Fatalf("live edit preview remained collapsed after ctrl+o:\n%s", rendered)
55	}
56	if !dialog.Active() {
57		t.Fatal("ctrl+o closed the confirmation dialog")
58	}
59	select {
60	case decision := <-resp:
61		t.Fatalf("ctrl+o unexpectedly answered confirmation: %+v", decision)
62	default:
63	}
64
65	i.handleKey(context.Background(), tui.Key{Kind: tui.KeyCtrlO})
66	if i.view.ExpandAll {
67		t.Fatal("second ctrl+o did not collapse tool previews during confirmation")
68	}
69	if rendered := strings.Join(view.Build(80), "\n"); !strings.Contains(rendered, "ctrl+o to expand") {
70		t.Fatalf("live edit preview remained expanded after second ctrl+o:\n%s", rendered)
71	}
72	if !dialog.Active() {
73		t.Fatal("second ctrl+o closed the confirmation dialog")
74	}
75}

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 477

↑↓ moveenter openesc close