main 5041353

omnibox_favorite_icon_test.go RawHistoryFolder

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

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