v0.31.0 d5e0505

mirror_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"testing"
7
8	"github.com/stretchr/testify/assert"
9	"github.com/stretchr/testify/mock"
10
11	"bnema.dev/ermite/internal/domain"
12	"bnema.dev/ermite/internal/ports/mocks"
13)
14
15func TestMirrorBadge(t *testing.T) {
16	repo := repoName(t, "proj")
17	admin := domain.TokenPrincipal(domain.Token{ID: "admin", Scopes: []domain.Scope{domain.ScopeRepoAdmin}, Repos: []domain.RepoName{repo}})
18	reader := domain.TokenPrincipal(domain.Token{ID: "reader", Scopes: []domain.Scope{domain.ScopeRepoRead}})
19	for _, tc := range []struct {
20		name   string
21		p      domain.Principal
22		state  domain.MirrorState
23		shown  bool
24		lookup bool
25	}{
26		{"owner failing", domain.Owner(), domain.MirrorFailing, true, true},
27		{"admin paused", admin, domain.MirrorPaused, true, true},
28		{"anonymous", domain.Anonymous(), domain.MirrorFailing, false, false},
29		{"reader", reader, domain.MirrorFailing, false, false},
30		{"ok", admin, domain.MirrorOK, false, true},
31		{"disabled", admin, domain.MirrorDisabled, false, true},
32	} {
33		t.Run(tc.name, func(t *testing.T) {
34			w := mocks.NewMirrorWarner(t)
35			if tc.lookup {
36				w.EXPECT().Badge(mock.Anything, tc.p, repo).Return(tc.state, "main diverged on remote")
37			}
38			s := &Server{cfg: Config{Mirrors: w}}
39			badge := s.mirrorBadge(domain.ContextWithPrincipal(t.Context(), tc.p), repo)
40			out := renderRail(t, SummaryPage{Mirror: badge})
41			if tc.shown {
42				assert.Contains(t, out, `aria-labelledby="r-mirror"`)
43				assert.Contains(t, out, "Mirror "+string(tc.state))
44				assert.Contains(t, out, "main diverged on remote")
45				assert.Contains(t, out, "ermite mirror status proj")
46			} else {
47				assert.Nil(t, badge)
48				assert.NotContains(t, out, `id="r-mirror"`)
49			}
50		})
51	}
52	assert.Nil(t, (&Server{}).mirrorBadge(domain.ContextWithPrincipal(t.Context(), domain.Owner()), repo))
53}

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