main 5041353

standalone_runtime_test.go RawHistoryFolder

1package ui
2
3import (
4	"context"
5	"errors"
6	stdurl "net/url"
7	"path/filepath"
8	"testing"
9
10	urlutil "github.com/bnema/dumber/internal/domain/url"
11)
12
13type standaloneTestLocalPathResolver struct {
14	paths map[string]string
15}
16
17func (r standaloneTestLocalPathResolver) ResolveExistingPath(_ context.Context, input string) (string, bool, error) {
18	absPath, ok := r.paths[input]
19	return absPath, ok, nil
20}
21
22func TestNewStandaloneOmniboxRuntimeUsesExplicitLocalPathResolver(t *testing.T) {
23	absFile := filepath.Join(string(filepath.Separator), "tmp", "page.html")
24	runtime := NewStandaloneOmniboxRuntime(context.Background(), &Dependencies{
25		LocalPathResolver: standaloneTestLocalPathResolver{paths: map[string]string{"page.html": absFile}},
26	}, nil)
27
28	got := runtime.OmniboxCfg.NormalizeNavigationURL(context.Background(), "page.html")
29	want := (&stdurl.URL{Scheme: "file", Path: absFile}).String()
30	if got != want {
31		t.Fatalf("NormalizeNavigationURL(page.html) = %q, want %q", got, want)
32	}
33}
34
35func TestHandleStandaloneOmniboxNavigation_UsesFreshBrowserWindowForHTTP(t *testing.T) {
36	browserURL := ""
37	externalURL := ""
38	err := handleStandaloneOmniboxNavigation(&Dependencies{
39		LaunchBrowserURL: func(_ context.Context, uri string) error {
40			browserURL = uri
41			return nil
42		},
43		LaunchExternalURL: func(uri string) {
44			externalURL = uri
45		},
46	}, context.Background(), "https://example.com")
47
48	if err != nil {
49		t.Fatalf("expected no error, got %v", err)
50	}
51	if browserURL != "https://example.com" {
52		t.Fatalf("expected browser launcher to receive URL, got %q", browserURL)
53	}
54	if externalURL != "" {
55		t.Fatalf("expected external launcher to be unused, got %q", externalURL)
56	}
57}
58
59func TestHandleStandaloneOmniboxNavigation_UsesExternalLauncherForCustomScheme(t *testing.T) {
60	browserURL := ""
61	externalURL := ""
62	err := handleStandaloneOmniboxNavigation(&Dependencies{
63		LaunchBrowserURL: func(_ context.Context, uri string) error {
64			browserURL = uri
65			return nil
66		},
67		LaunchExternalURL: func(uri string) {
68			externalURL = uri
69		},
70	}, context.Background(), "vscode://file/tmp/demo")
71
72	if err != nil {
73		t.Fatalf("expected no error, got %v", err)
74	}
75	if externalURL != "vscode://file/tmp/demo" {
76		t.Fatalf("expected external launcher to receive URL, got %q", externalURL)
77	}
78	if browserURL != "" {
79		t.Fatalf("expected browser launcher to be unused, got %q", browserURL)
80	}
81}
82
83func TestHandleStandaloneOmniboxNavigation_UsesExternalLauncherForMailto(t *testing.T) {
84	browserURL := ""
85	externalURL := ""
86	err := handleStandaloneOmniboxNavigation(&Dependencies{
87		LaunchBrowserURL: func(_ context.Context, uri string) error {
88			browserURL = uri
89			return nil
90		},
91		LaunchExternalURL: func(uri string) {
92			externalURL = uri
93		},
94	}, context.Background(), "mailto:foo@example.com")
95
96	if err != nil {
97		t.Fatalf("expected no error, got %v", err)
98	}
99	if externalURL != "mailto:foo@example.com" {
100		t.Fatalf("expected external launcher to receive URL, got %q", externalURL)
101	}
102	if browserURL != "" {
103		t.Fatalf("expected browser launcher to be unused, got %q", browserURL)
104	}
105}
106
107func TestHandleStandaloneOmniboxNavigation_ReturnsBrowserLaunchError(t *testing.T) {
108	wantErr := context.DeadlineExceeded
109
110	err := handleStandaloneOmniboxNavigation(&Dependencies{
111		LaunchBrowserURL: func(context.Context, string) error {
112			return wantErr
113		},
114	}, context.Background(), "https://example.com")
115
116	if err == nil {
117		t.Fatal("expected browser launch error")
118	}
119	if !errors.Is(err, wantErr) {
120		t.Fatalf("expected error %v, got %v", wantErr, err)
121	}
122}
123
124func TestStandaloneExternalSchemeRules_HTTPIsNotExternal(t *testing.T) {
125	if urlutil.IsExternalScheme("https://example.com") {
126		t.Fatalf("expected http url to stay in dumber")
127	}
128}
129
130func TestStandaloneExternalSchemeRules_CustomSchemeIsExternal(t *testing.T) {
131	if !urlutil.IsExternalScheme("spotify://track/123") {
132		t.Fatalf("expected custom scheme to be external")
133	}
134}
135
136func TestStandaloneExternalSchemeRules_InternalSchemesStayInternal(t *testing.T) {
137	for _, rawURL := range []string{"dumb://history", "dumb://error", "file:///tmp/demo", "about:blank", "data:text/plain,hi"} {
138		if urlutil.IsExternalScheme(rawURL) {
139			t.Fatalf("expected %q to stay internal", rawURL)
140		}
141	}
142}

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