v0.31.0 bf0756b

engine_runtime_test.go RawHistoryFolder

1package cef
2
3import (
4	"context"
5	"errors"
6	"testing"
7
8	"github.com/bnema/dumber/internal/application/dto"
9	"github.com/bnema/dumber/internal/application/port"
10	"github.com/stretchr/testify/require"
11)
12
13type stubAccentHandler struct{}
14
15func (stubAccentHandler) OnKeyPressed(context.Context, rune, bool) bool { return true }
16func (stubAccentHandler) OnKeyReleased(context.Context, rune)           {}
17
18func TestEngineRegisterHandlers_UsesInjectedRegistrar(t *testing.T) {
19	called := false
20	eng := &Engine{
21		messageRouter: NewMessageRouter(context.Background()),
22		registerHandlers: func(context.Context, port.WebUIHandlerRouter, port.HandlerDependencies) error {
23			called = true
24			return nil
25		},
26	}
27	require.NoError(t, eng.RegisterHandlers(context.Background(), port.HandlerDependencies{}))
28	require.True(t, called)
29}
30
31func TestEngineRegisterAccentHandlers_UsesInjectedRegistrar(t *testing.T) {
32	called := false
33	eng := &Engine{
34		messageRouter: NewMessageRouter(context.Background()),
35		registerAccentHandlers: func(context.Context, port.WebUIHandlerRouter, port.AccentKeyHandler) error {
36			called = true
37			return nil
38		},
39	}
40	require.NoError(t, eng.RegisterAccentHandlers(context.Background(), stubAccentHandler{}))
41	require.True(t, called)
42}
43
44func TestEngineRegisterHandlers_PropagatesRegistrarError(t *testing.T) {
45	want := errors.New("boom")
46	eng := &Engine{
47		messageRouter: NewMessageRouter(context.Background()),
48		registerHandlers: func(context.Context, port.WebUIHandlerRouter, port.HandlerDependencies) error {
49			return want
50		},
51	}
52	err := eng.RegisterHandlers(context.Background(), port.HandlerDependencies{})
53	require.ErrorIs(t, err, want)
54}
55
56func TestEngineRegisterHandlers_StoresClipboardWiring(t *testing.T) {
57	orchestrator := &recordingClipboardTextOrchestrator{}
58	onCopied := func(int) {}
59	eng := &Engine{
60		messageRouter: NewMessageRouter(context.Background()),
61		registerHandlers: func(context.Context, port.WebUIHandlerRouter, port.HandlerDependencies) error {
62			return nil
63		},
64	}
65
66	require.NoError(t, eng.RegisterHandlers(context.Background(), port.HandlerDependencies{
67		ClipboardTextOrchestrator: orchestrator,
68		OnClipboardCopied:         onCopied,
69	}))
70	require.Same(t, orchestrator, eng.clipboardTextOrchestrator)
71	require.NotNil(t, eng.onClipboardCopied)
72}
73
74func TestEngineClipboardSelectionUpdate_ForwardsViewID(t *testing.T) {
75	orchestrator := &recordingClipboardTextOrchestrator{}
76	eng := &Engine{clipboardTextOrchestrator: orchestrator}
77
78	eng.handleClipboardSelectionUpdate(99, "selected")
79
80	require.Equal(t, dto.SelectionClipboardInput{Text: "selected", SourceEngine: dto.ClipboardSourceCEF, ViewID: 99}, orchestrator.selection)
81}
82
83func TestEngineExplicitClipboardCopy_ForwardsViewID(t *testing.T) {
84	orchestrator := &recordingClipboardTextOrchestrator{}
85	eng := &Engine{clipboardTextOrchestrator: orchestrator}
86
87	eng.handleExplicitClipboardBridgeText(77, "copy", "copied")
88
89	require.Equal(t, dto.ExplicitClipboardInput{Text: "copied", SourceEngine: dto.ClipboardSourceCEF, ViewID: 77, Action: "copy", NativeHandled: false}, orchestrator.explicit)
90}
91
92type recordingClipboardTextOrchestrator struct {
93	selection dto.SelectionClipboardInput
94	explicit  dto.ExplicitClipboardInput
95}
96
97func (r *recordingClipboardTextOrchestrator) HandleSelectionUpdate(_ context.Context, input dto.SelectionClipboardInput) error {
98	r.selection = input
99	return nil
100}
101
102func (r *recordingClipboardTextOrchestrator) HandleExplicitCopy(_ context.Context, input dto.ExplicitClipboardInput) error {
103	r.explicit = input
104	return nil
105}

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