navigate_test.go RawHistoryFolder

1package usecase
2
3import (
4	"context"
5	"errors"
6	"math"
7	"testing"
8
9	portmocks "github.com/bnema/dumber/internal/application/port/mocks"
10	"github.com/bnema/dumber/internal/domain/entity"
11	"github.com/stretchr/testify/mock"
12	"github.com/stretchr/testify/require"
13)
14
15func newLoadingNavigator(t *testing.T, url string, err error) *portmocks.MockPageNavigator {
16	t.Helper()
17	nav := portmocks.NewMockPageNavigator(t)
18	nav.EXPECT().LoadURI(mock.Anything, url).Return(err).Once()
19	return nav
20}
21
22func TestNavigateUseCase_ExecuteLoadsURLAndReturnsDefaultZoom(t *testing.T) {
23	ctx := context.Background()
24	wv := newLoadingNavigator(t, "https://example.com", nil)
25	uc := NewNavigateUseCase(entity.ZoomDefault)
26
27	out, err := uc.Execute(ctx, NavigateInput{URL: "https://example.com", PaneID: "pane-1", WebView: wv})
28
29	require.NoError(t, err)
30	require.InDelta(t, entity.ZoomDefault, out.AppliedZoom, 0.0001)
31}
32
33func TestNavigateUseCase_ExecuteUsesConfiguredOrFallbackZoom(t *testing.T) {
34	tests := []struct {
35		name           string
36		configuredZoom float64
37		wantZoom       float64
38	}{
39		{name: "zero falls back", configuredZoom: 0, wantZoom: entity.ZoomDefault},
40		{name: "negative falls back", configuredZoom: -0.5, wantZoom: entity.ZoomDefault},
41		{name: "NaN falls back", configuredZoom: math.NaN(), wantZoom: entity.ZoomDefault},
42		{name: "positive infinity falls back", configuredZoom: math.Inf(1), wantZoom: entity.ZoomDefault},
43		{name: "positive is preserved", configuredZoom: 1.25, wantZoom: 1.25},
44	}
45
46	for _, tt := range tests {
47		t.Run(tt.name, func(t *testing.T) {
48			ctx := context.Background()
49			wv := newLoadingNavigator(t, "https://example.com", nil)
50			uc := NewNavigateUseCase(tt.configuredZoom)
51
52			out, err := uc.Execute(ctx, NavigateInput{URL: "https://example.com", PaneID: "pane-1", WebView: wv})
53
54			require.NoError(t, err)
55			require.InDelta(t, tt.wantZoom, out.AppliedZoom, 0.0001)
56		})
57	}
58}
59
60func TestNavigateUseCase_ExecuteReturnsLoadError(t *testing.T) {
61	ctx := context.Background()
62	loadErr := errors.New("load failed")
63	wv := newLoadingNavigator(t, "https://example.com", loadErr)
64	uc := NewNavigateUseCase(entity.ZoomDefault)
65
66	out, err := uc.Execute(ctx, NavigateInput{URL: "https://example.com", PaneID: "pane-1", WebView: wv})
67
68	require.Nil(t, out)
69	require.ErrorIs(t, err, loadErr)
70	require.Contains(t, err.Error(), "failed to load URL")
71}
72
73func TestNavigateUseCase_ReloadHonoursBypassCache(t *testing.T) {
74	ctx := context.Background()
75	uc := NewNavigateUseCase(entity.ZoomDefault)
76
77	nav := portmocks.NewMockPageNavigator(t)
78	nav.EXPECT().ReloadBypassCache(mock.Anything).Return(nil).Once()
79	require.NoError(t, uc.Reload(ctx, nav, true))
80
81	nav = portmocks.NewMockPageNavigator(t)
82	nav.EXPECT().Reload(mock.Anything).Return(nil).Once()
83	require.NoError(t, uc.Reload(ctx, nav, false))
84}

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