main 5041353

omnibox_suggestions_test.go RawHistoryFolder

1package component
2
3import "testing"
4
5func TestGhostCompletion(t *testing.T) {
6	history := []Suggestion{
7		{URL: "https://www.google.com/url?q=https://x"},
8		{URL: "https://github.com/bnema/dumber"},
9	}
10	favorites := []Favorite{{URL: "https://gitlab.com/"}}
11
12	tests := []struct {
13		name       string
14		req        ghostCompletionRequest
15		wantFull   string
16		wantSuffix string
17		wantOK     bool
18	}{
19		{
20			name:       "host-like input completes to the domain, not the redirect URL",
21			req:        ghostCompletionRequest{EntryText: "goo", Mode: ViewModeHistory, MaxResults: 5, Suggestions: history},
22			wantFull:   "google.com",
23			wantSuffix: "gle.com",
24			wantOK:     true,
25		},
26		{
27			name:       "leading whitespace is ignored",
28			req:        ghostCompletionRequest{EntryText: "  gith", Mode: ViewModeHistory, MaxResults: 5, Suggestions: history},
29			wantFull:   "github.com",
30			wantSuffix: "ub.com",
31			wantOK:     true,
32		},
33		{
34			name:   "hidden rows never complete",
35			req:    ghostCompletionRequest{EntryText: "gith", Mode: ViewModeHistory, MaxResults: 1, Suggestions: history},
36			wantOK: false,
37		},
38		{
39			name:       "favorites mode uses favorites",
40			req:        ghostCompletionRequest{EntryText: "gitl", Mode: ViewModeFavorites, MaxResults: 5, Favorites: favorites},
41			wantFull:   "gitlab.com",
42			wantSuffix: "ab.com",
43			wantOK:     true,
44		},
45		{
46			name: "explicit selection completes from the selected URL, not the best match",
47			req: ghostCompletionRequest{
48				EntryText: "gi", SelectedURL: "https://gitlab.com/", HasExplicitSelection: true,
49				Mode: ViewModeHistory, MaxResults: 5, Suggestions: history,
50			},
51			wantFull:   "gitlab.com",
52			wantSuffix: "tlab.com",
53			wantOK:     true,
54		},
55		{
56			name:   "blank input shows nothing",
57			req:    ghostCompletionRequest{EntryText: "   ", Mode: ViewModeHistory, MaxResults: 5, Suggestions: history},
58			wantOK: false,
59		},
60	}
61
62	for _, tt := range tests {
63		t.Run(tt.name, func(t *testing.T) {
64			full, suffix, ok := ghostCompletion(tt.req)
65			if ok != tt.wantOK || full != tt.wantFull || suffix != tt.wantSuffix {
66				t.Fatalf("ghostCompletion() = (%q, %q, %v), want (%q, %q, %v)",
67					full, suffix, ok, tt.wantFull, tt.wantSuffix, tt.wantOK)
68			}
69		})
70	}
71}
72
73func TestNavigableCount(t *testing.T) {
74	limit := OmniboxListDefaults.MaxResults
75	tests := []struct {
76		name                          string
77		bangMode                      bool
78		mode                          ViewMode
79		bangs, suggestions, favorites int
80		want                          int
81	}{
82		{"history capped at results limit", false, ViewModeHistory, 0, limit + 5, 30, limit},
83		{"favorites capped at results limit", false, ViewModeFavorites, 0, 3, 30, limit},
84		{"bangs win over view mode", true, ViewModeHistory, 2, 8, 0, 2},
85		{"empty list", false, ViewModeFavorites, 4, 4, 0, 0},
86	}
87	for _, tt := range tests {
88		t.Run(tt.name, func(t *testing.T) {
89			got := navigableCount(tt.bangMode, tt.mode, tt.bangs, tt.suggestions, tt.favorites)
90			if got != tt.want {
91				t.Fatalf("navigableCount() = %d, want %d", got, tt.want)
92			}
93		})
94	}
95}

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