v0.29.0 21b3150

native_popup_window_test.go RawHistoryFolder

1package ui
2
3import (
4	"context"
5	"errors"
6	"testing"
7
8	"github.com/bnema/dumber/internal/application/port"
9	portmocks "github.com/bnema/dumber/internal/application/port/mocks"
10	"github.com/bnema/dumber/internal/ui/coordinator/content"
11	layoutmocks "github.com/bnema/dumber/internal/ui/layout/mocks"
12	"github.com/bnema/dumber/internal/ui/window"
13	"github.com/bnema/puregotk/v4/gtk"
14	"github.com/stretchr/testify/assert"
15	"github.com/stretchr/testify/require"
16)
17
18type popupDestroySpy struct {
19	destroyed bool
20}
21
22func (p *popupDestroySpy) Destroy() {
23	p.destroyed = true
24}
25
26func TestPrepareNativePopupContentWidget_ExpandsWrappedWidget(t *testing.T) {
27	widget := layoutmocks.NewMockWidget(t)
28	gtkWidget := &gtk.Widget{}
29	widget.EXPECT().GtkWidget().Return(gtkWidget).Once()
30	widget.EXPECT().SetHexpand(true).Once()
31	widget.EXPECT().SetVexpand(true).Once()
32
33	got, err := prepareNativePopupContentWidget(widget)
34	require.NoError(t, err)
35	assert.Same(t, gtkWidget, got)
36}
37
38func TestPrepareNativePopupContentWidget_ErrorsWhenWrappedGTKWidgetMissing(t *testing.T) {
39	widget := layoutmocks.NewMockWidget(t)
40	widget.EXPECT().GtkWidget().Return(nil).Once()
41
42	got, err := prepareNativePopupContentWidget(widget)
43	require.Error(t, err)
44	assert.Nil(t, got)
45}
46
47func TestOpenNativePopupWindow_DestroysWebViewWhenPopupShellCreationFails(t *testing.T) {
48	oldNewPopupWindow := newPopupWindow
49	t.Cleanup(func() {
50		newPopupWindow = oldNewPopupWindow
51	})
52
53	expectedErr := errors.New("boom")
54	newPopupWindow = func(context.Context, *gtk.Application) (*window.PopupWindow, error) {
55		return nil, expectedErr
56	}
57
58	wv := portmocks.NewMockWebView(t)
59	wv.EXPECT().IsDestroyed().Return(false).Once()
60	wv.EXPECT().Destroy().Once()
61
62	app := &App{gtkApp: &gtk.Application{}}
63	err := app.openNativePopupWindow(context.Background(), content.NativePopupInput{PopupWebView: wv})
64	require.ErrorIs(t, err, expectedErr)
65}
66
67func TestDestroyFailedNativePopupSetup_DestroysWebViewAndShell(t *testing.T) {
68	wv := portmocks.NewMockWebView(t)
69	wv.EXPECT().IsDestroyed().Return(false).Once()
70	wv.EXPECT().Destroy().Once()
71
72	shell := &popupDestroySpy{}
73	destroyFailedNativePopupSetup(shell, wv)
74
75	assert.True(t, shell.destroyed)
76}
77
78func TestReleaseNativePopupWindow_DestroysWebViewAndRemovesState(t *testing.T) {
79	wv := portmocks.NewMockWebView(t)
80	wv.EXPECT().IsDestroyed().Return(false).Once()
81	wv.EXPECT().Destroy().Once()
82
83	app := &App{nativePopupWindows: map[port.WebViewID]*nativePopupWindow{
84		port.WebViewID(1): {
85			popupID: port.WebViewID(1),
86			webView: wv,
87		},
88	}}
89
90	app.releaseNativePopupWindow(port.WebViewID(1), false, false)
91	_, ok := app.nativePopupWindows[port.WebViewID(1)]
92	assert.False(t, ok)
93}

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 9

Tags 42

↑↓ moveenter openesc close