v2.30.0-pre3 63e7f3a

naming_test.go RawHistoryFolder

1package preview
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8)
9
10func TestExtractPreviewName(t *testing.T) {
11	tests := []struct {
12		name     string
13		tag      string
14		patterns []string
15		want     string
16	}{
17		{"simple prefix", "preview-login", []string{"preview-*"}, "login"},
18		{"pr prefix", "pr-42", []string{"pr-*"}, "42"},
19		{"multi-word", "preview-login-redesign", []string{"preview-*"}, "login-redesign"},
20		{"second pattern matches", "pr-99", []string{"preview-*", "pr-*"}, "99"},
21		{"no match", "v1.0.0", []string{"preview-*"}, "v1.0.0"},
22	}
23	for _, tt := range tests {
24		t.Run(tt.name, func(t *testing.T) {
25			assert.Equal(t, tt.want, ExtractPreviewName(tt.tag, tt.patterns))
26		})
27	}
28}
29
30func TestGeneratePreviewDomain(t *testing.T) {
31	tests := []struct {
32		name        string
33		baseRoute   string
34		previewName string
35		separator   string
36		want        string
37		wantErr     bool
38	}{
39		{"flat default", "myapp.example.com", "login", "--", "myapp--login.example.com", false},
40		{"flat with dashes", "my-app.example.com", "feat-123", "--", "my-app--feat-123.example.com", false},
41		{"multi-level base", "myapp.sub.example.com", "feat", "--", "myapp--feat.sub.example.com", false},
42		{"invalid domain", "nodot", "feat", "--", "", true},
43	}
44	for _, tt := range tests {
45		t.Run(tt.name, func(t *testing.T) {
46			got, err := GeneratePreviewDomain(tt.baseRoute, tt.previewName, tt.separator)
47			if tt.wantErr {
48				assert.Error(t, err)
49			} else {
50				assert.NoError(t, err)
51				assert.Equal(t, tt.want, got)
52			}
53		})
54	}
55}
56
57func TestSanitizeBranchName(t *testing.T) {
58	tests := []struct {
59		name   string
60		branch string
61		want   string
62	}{
63		{"feature branch", "feat/login-redesign", "login-redesign"},
64		{"fix branch", "fix/bug-123", "bug-123"},
65		{"simple", "main", "main"},
66		{"nested", "feat/ui/button", "ui-button"},
67		{"uppercase", "Feat/MyBranch", "mybranch"},
68		{"dots and underscores", "feat/my_branch.name", "my-branch-name"},
69		{"special chars", "feat/hello@world!", "helloworld"},
70		{"long branch", strings.Repeat("a", 70), strings.Repeat("a", 63)},
71		{"consecutive dashes", "feat/a--b--c", "a-b-c"},
72		{"empty branch", "", ""},
73		{"whitespace branch", "   ", ""},
74	}
75	for _, tt := range tests {
76		t.Run(tt.name, func(t *testing.T) {
77			assert.Equal(t, tt.want, SanitizeBranchName(tt.branch))
78		})
79	}
80}

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 7

Tags 106

↑↓ moveenter openesc close