v0.33.0 62a09f5

webui_contract_test.go RawHistoryFolder

1package handlers
2
3import (
4	"context"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/mock"
9	"github.com/stretchr/testify/require"
10
11	"github.com/bnema/dumber/internal/application/dto"
12	"github.com/bnema/dumber/internal/application/port"
13	"github.com/bnema/dumber/internal/application/port/mocks"
14	"github.com/bnema/dumber/internal/infrastructure/handlers/homepage"
15)
16
17// TestWebUIContract_EveryMessageHasAHandlerAndMatchingCallbacks checks both
18// directions of the WebUI message contract: every declared message has a Go
19// handler, and every handler registers with the declared callbacks.
20func TestWebUIContract_EveryMessageHasAHandlerAndMatchingCallbacks(t *testing.T) {
21	ctx := context.Background()
22	registered := map[string]port.WebUICallbacks{}
23
24	router := mocks.NewMockWebUIHandlerRouter(t)
25	router.EXPECT().
26		RegisterHandlerWithCallbacks(mock.Anything, mock.Anything, mock.Anything, "", mock.Anything).
27		Run(func(msgType, success, failure, _ string, _ port.WebUIMessageHandler) {
28			registered[msgType] = port.WebUICallbacks{Success: success, Failure: failure}
29		}).
30		Return(nil)
31
32	require.NoError(t, homepage.RegisterHandlers(ctx, router, homepage.Config{
33		HistoryUC:   mocks.NewMockHomepageHistory(t),
34		FavoritesUC: mocks.NewMockHomepageFavorites(t),
35	}))
36	require.NoError(t, RegisterConfigHandlers(ctx, router, func(context.Context, dto.WebUIConfig) error { return nil }))
37	require.NoError(t, RegisterKeybindingsHandlers(ctx, router, &KeybindingsHandler{}))
38
39	assert.Equal(t, port.WebUIMessageCallbacks, registered)
40}
41
42func TestRegisterWebUIMessage_RejectsUnknownType(t *testing.T) {
43	router := mocks.NewMockWebUIHandlerRouter(t)
44
45	err := port.RegisterWebUIMessage(router, "not_a_message", port.WebUIMessageHandlerFunc(nil))
46
47	var unknown *port.UnknownWebUIMessageError
48	require.ErrorAs(t, err, &unknown)
49}

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