app_clipboard_test.go RawHistoryFolder

1package ui
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	portmocks "github.com/bnema/dumber/internal/application/port/mocks"
11	"github.com/bnema/dumber/internal/application/usecase"
12	"github.com/bnema/dumber/internal/domain/entity"
13	repomocks "github.com/bnema/dumber/internal/domain/repository/mocks"
14	"github.com/stretchr/testify/mock"
15	"github.com/stretchr/testify/require"
16)
17
18func TestNew_DoesNotWireClipboardOrchestratorWhenClipboardMissing(t *testing.T) {
19	ctx := context.Background()
20	engine := portmocks.NewMockEngine(t)
21	var registerDeps port.HandlerDependencies
22	engine.EXPECT().RegisterHandlers(mock.Anything, mock.Anything).
23		Run(func(_ context.Context, deps port.HandlerDependencies) {
24			registerDeps = deps
25		}).
26		Return(nil).
27		Once()
28	runtimeConfig := portmocks.NewMockRuntimeConfigProvider(t)
29	runtimeConfig.EXPECT().
30		Current().
31		Return(entity.RuntimeConfigSnapshot{}).
32		Once()
33
34	deps := &Dependencies{
35		Ctx:           ctx,
36		RuntimeConfig: runtimeConfig,
37		Engine:        engine,
38		HandlerDeps: port.HandlerDeps{
39			SaveConfig:                 func(context.Context, dto.WebUIConfig) error { return nil },
40			SaveOmniboxInitialBehavior: func(context.Context, entity.OmniboxInitialBehavior) error { return nil },
41		},
42		Clipboard: nil,
43	}
44
45	app, err := New(deps)
46	require.NoError(t, err)
47	require.NotNil(t, app)
48	require.Nil(t, registerDeps.ClipboardTextOrchestrator)
49}
50
51func TestNew_ClosesHistoryRecorderWhenRegisterHandlersFails(t *testing.T) {
52	ctx := context.Background()
53	engine := portmocks.NewMockEngine(t)
54	registerErr := errors.New("register failed")
55	engine.EXPECT().RegisterHandlers(mock.Anything, mock.Anything).Return(registerErr).Once()
56	runtimeConfig := portmocks.NewMockRuntimeConfigProvider(t)
57	runtimeConfig.EXPECT().Current().Return(entity.RuntimeConfigSnapshot{}).Once()
58	historyRepo := repomocks.NewMockHistoryRepository(t)
59	historyRecorder := usecase.NewHistoryRecorderUseCase(historyRepo, nil)
60
61	deps := &Dependencies{
62		Ctx:               ctx,
63		RuntimeConfig:     runtimeConfig,
64		Engine:            engine,
65		HistoryRecorderUC: historyRecorder,
66		HandlerDeps: port.HandlerDeps{
67			SaveConfig:                 func(context.Context, dto.WebUIConfig) error { return nil },
68			SaveOmniboxInitialBehavior: func(context.Context, entity.OmniboxInitialBehavior) error { return nil },
69		},
70	}
71
72	app, err := New(deps)
73	require.Nil(t, app)
74	require.ErrorIs(t, err, registerErr)
75
76	historyRecorder.RecordHistory(ctx, "pane-1", "https://example.com/leak-check")
77	historyRecorder.Close()
78}
79
80func TestNew_WiresClipboardOrchestratorWhenClipboardPresent(t *testing.T) {
81	ctx := context.Background()
82	engine := portmocks.NewMockEngine(t)
83	clipboard := portmocks.NewMockClipboard(t)
84	var registerDeps port.HandlerDependencies
85	engine.EXPECT().RegisterHandlers(mock.Anything, mock.Anything).
86		Run(func(_ context.Context, deps port.HandlerDependencies) {
87			registerDeps = deps
88		}).
89		Return(nil).
90		Once()
91	runtimeConfig := portmocks.NewMockRuntimeConfigProvider(t)
92	runtimeConfig.EXPECT().
93		Current().
94		Return(entity.RuntimeConfigSnapshot{}).
95		Once()
96
97	deps := &Dependencies{
98		Ctx:           ctx,
99		RuntimeConfig: runtimeConfig,
100		Engine:        engine,
101		HandlerDeps: port.HandlerDeps{
102			SaveConfig:                 func(context.Context, dto.WebUIConfig) error { return nil },
103			SaveOmniboxInitialBehavior: func(context.Context, entity.OmniboxInitialBehavior) error { return nil },
104		},
105		Clipboard: clipboard,
106	}
107
108	app, err := New(deps)
109	require.NoError(t, err)
110	require.NotNil(t, app)
111	require.NotNil(t, registerDeps.ClipboardTextOrchestrator)
112}

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