v0.30.0 eb3068f

omnibox_favorite_icon_test.go RawHistoryFolder

1package component
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7)
8
9func TestOmniboxFavoriteStarSize(t *testing.T) {
10	assert.Equal(t, 18, favoriteStarSize(1.0))
11	assert.Equal(t, 27, favoriteStarSize(1.5))
12}
13
14func TestOmniboxFavoriteStarVisibility(t *testing.T) {
15	assert.True(t, shouldShowFavoriteStar(Suggestion{IsFavorite: true}))
16	assert.False(t, shouldShowFavoriteStar(Suggestion{IsFavorite: false}))
17}
18
19func TestShouldApplyEmptyResultsState(t *testing.T) {
20	tests := []struct {
21		name     string
22		rowCount int
23		visible  bool
24		want     bool
25	}{
26		{name: "negative rows uses empty state", rowCount: -1, visible: false, want: true},
27		{name: "zero rows uses empty state", rowCount: 0, visible: false, want: true},
28		{name: "positive rows clears empty state", rowCount: 2, visible: true, want: false},
29	}
30
31	for _, tt := range tests {
32		t.Run(tt.name, func(t *testing.T) {
33			assert.Equal(t, tt.want, shouldApplyEmptyResultsState(tt.rowCount, tt.visible))
34		})
35	}
36}
37
38func TestResolveFavoriteRowIndicatorUpdate(t *testing.T) {
39	tests := []struct {
40		name        string
41		mode        ViewMode
42		index       int
43		expectedURL string
44		suggestions []Suggestion
45		isFavorite  bool
46		want        favoriteRowIndicatorUpdate
47	}{
48		{
49			name:        "matching history row keeps update and shows star",
50			mode:        ViewModeHistory,
51			index:       0,
52			expectedURL: "https://example.com",
53			suggestions: []Suggestion{{URL: "https://example.com"}},
54			isFavorite:  true,
55			want:        favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: true},
56		},
57		{
58			name:        "matching history row keeps update and hides star when removed",
59			mode:        ViewModeHistory,
60			index:       0,
61			expectedURL: "https://example.com",
62			suggestions: []Suggestion{{URL: "https://example.com"}},
63			isFavorite:  false,
64			want:        favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: false},
65		},
66		{
67			name:        "mismatched URL skips stale row update",
68			mode:        ViewModeHistory,
69			index:       0,
70			expectedURL: "https://expected.example.com",
71			suggestions: []Suggestion{{URL: "https://current.example.com"}},
72			isFavorite:  true,
73			want:        favoriteRowIndicatorUpdate{},
74		},
75		{
76			name:        "favorites mode never applies history row update",
77			mode:        ViewModeFavorites,
78			index:       0,
79			expectedURL: "https://example.com",
80			suggestions: []Suggestion{{URL: "https://example.com"}},
81			isFavorite:  true,
82			want:        favoriteRowIndicatorUpdate{},
83		},
84		{
85			name:        "out of range index skips update",
86			mode:        ViewModeHistory,
87			index:       1,
88			expectedURL: "https://example.com",
89			suggestions: []Suggestion{{URL: "https://example.com"}},
90			isFavorite:  true,
91			want:        favoriteRowIndicatorUpdate{},
92		},
93	}
94
95	for _, tt := range tests {
96		t.Run(tt.name, func(t *testing.T) {
97			got := resolveFavoriteRowIndicatorUpdate(tt.mode, tt.index, tt.expectedURL, tt.suggestions, tt.isFavorite)
98			assert.Equal(t, tt.want, got)
99		})
100	}
101}

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