v0.33.0 62a09f5

register_test.go RawHistoryFolder

1package handlers
2
3import (
4	"context"
5	"encoding/json"
6	"testing"
7
8	"github.com/bnema/dumber/internal/application/port"
9	"github.com/bnema/dumber/internal/application/port/mocks"
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/mock"
12	"github.com/stretchr/testify/require"
13)
14
15func TestRegisterAccentHandlers_NilRouter(t *testing.T) {
16	handler := mocks.NewMockAccentKeyHandler(t)
17	err := RegisterAccentHandlers(context.Background(), nil, handler)
18	require.Error(t, err)
19	assert.Contains(t, err.Error(), "router")
20}
21
22func TestRegisterAccentHandlers_NilHandler(t *testing.T) {
23	router := mocks.NewMockWebUIHandlerRouter(t)
24	err := RegisterAccentHandlers(context.Background(), router, nil)
25	require.Error(t, err)
26	assert.Contains(t, err.Error(), "handler")
27}
28
29func TestRegisterAccentHandlers_Success(t *testing.T) {
30	router := mocks.NewMockWebUIHandlerRouter(t)
31	handler := mocks.NewMockAccentKeyHandler(t)
32
33	router.EXPECT().RegisterHandler("accent_key_press", mock.AnythingOfType("port.WebUIMessageHandlerFunc")).Return(nil)
34	router.EXPECT().RegisterHandler("accent_key_release", mock.AnythingOfType("port.WebUIMessageHandlerFunc")).Return(nil)
35
36	err := RegisterAccentHandlers(context.Background(), router, handler)
37	require.NoError(t, err)
38}
39
40func TestRegisterAccentHandlers_KeyPress(t *testing.T) {
41	ctx := context.Background()
42
43	// Use a real router to capture the handler and invoke it.
44	var captured port.WebUIMessageHandler
45	router := mocks.NewMockWebUIHandlerRouter(t)
46	router.EXPECT().RegisterHandler("accent_key_press", mock.AnythingOfType("port.WebUIMessageHandlerFunc")).
47		Run(func(_ string, h port.WebUIMessageHandler) { captured = h }).
48		Return(nil)
49	router.EXPECT().RegisterHandler("accent_key_release", mock.AnythingOfType("port.WebUIMessageHandlerFunc")).Return(nil)
50
51	handler := mocks.NewMockAccentKeyHandler(t)
52	handler.EXPECT().OnKeyPressed(ctx, 'e', true).Return(false)
53
54	err := RegisterAccentHandlers(ctx, router, handler)
55	require.NoError(t, err)
56	require.NotNil(t, captured)
57
58	payload := json.RawMessage(`{"char":"e","shift":true}`)
59	_, err = captured.Handle(ctx, 0, payload)
60	require.NoError(t, err)
61}

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 8

Tags 42

↑↓ moveenter openesc close