detached 5278df2

repo_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite/internal/domain"
13)
14
15func TestNormalizeTopics(t *testing.T) {
16	t.Parallel()
17	many := func(n int) []string {
18		var out []string
19		for i := range n {
20			out = append(out, "t"+strings.Repeat("x", i))
21		}
22		return out
23	}
24	tests := []struct {
25		name string
26		in   []string
27		want []string
28		bad  bool
29	}{
30		{name: "nil", in: nil, want: nil},
31		{name: "empty", in: []string{}, want: nil},
32		{name: "lowercased", in: []string{"Go"}, want: []string{"go"}},
33		{name: "sorted", in: []string{"zig", "c", "go"}, want: []string{"c", "go", "zig"}},
34		{name: "deduplicated after lowercasing", in: []string{"Go", "go", "GO"}, want: []string{"go"}},
35		{name: "digits and hyphens", in: []string{"3d-printing", "0"}, want: []string{"0", "3d-printing"}},
36		{name: "50 characters", in: []string{strings.Repeat("a", 50)}, want: []string{strings.Repeat("a", 50)}},
37		{name: "exactly 20", in: many(20), want: many(20)},
38		{name: "duplicates do not count twice", in: append(many(20), "t", "tx"), want: many(20)},
39		{name: "21", in: many(21), bad: true},
40		{name: "51 characters", in: []string{strings.Repeat("a", 51)}, bad: true},
41		{name: "empty topic", in: []string{""}, bad: true},
42		{name: "leading hyphen", in: []string{"-go"}, bad: true},
43		{name: "underscore", in: []string{"a_b"}, bad: true},
44		{name: "space", in: []string{"a b"}, bad: true},
45		{name: "dot", in: []string{"a.b"}, bad: true},
46		{name: "non-ASCII", in: []string{"café"}, bad: true},
47		{name: "one bad among good", in: []string{"go", "no!"}, bad: true},
48	}
49	for _, tt := range tests {
50		t.Run(tt.name, func(t *testing.T) {
51			t.Parallel()
52			got, err := domain.NormalizeTopics(tt.in)
53			if tt.bad {
54				require.ErrorIs(t, err, domain.ErrInvalid)
55				assert.Nil(t, got)
56				return
57			}
58			require.NoError(t, err)
59			assert.Equal(t, tt.want, got)
60		})
61	}
62}
63
64func TestRepoEffectiveSettings(t *testing.T) {
65	custom := domain.RepoSettings{AllowedMergeModes: []domain.MergeMode{domain.MergeMode("squash")}, Issues: domain.IssuesPublic}
66	for _, tc := range []struct {
67		name           string
68		settings, want domain.RepoSettings
69	}{
70		{"unset", domain.RepoSettings{}, domain.DefaultRepoSettings()},
71		{"custom", custom, custom},
72	} {
73		t.Run(tc.name, func(t *testing.T) {
74			repo := domain.Repo{Settings: tc.settings}
75			assert.Equal(t, tc.want, repo.EffectiveSettings())
76			assert.Equal(t, tc.settings, repo.Settings)
77		})
78	}
79}
80
81func TestRepoIssuePresentationRules(t *testing.T) {
82	for _, tc := range []struct {
83		mode             domain.IssuesMode
84		enabled, receipt bool
85	}{
86		{"", false, false}, {domain.IssuesOff, false, false},
87		{domain.IssuesOwner, true, false}, {domain.IssuesPublic, true, true},
88	} {
89		t.Run(string(tc.mode), func(t *testing.T) {
90			s := domain.RepoSettings{Issues: tc.mode}
91			assert.Equal(t, tc.enabled, s.IssuesEnabled())
92			assert.Equal(t, tc.receipt, s.ShowsIssueSubmissionReceipt())
93			assert.Equal(t, tc.receipt, s.AcceptsAnonymousIssues())
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 2

Tags 45

↑↓ moveenter openesc close