floating_session_registry_test.go RawHistoryFolder

1package ui
2
3import (
4	"maps"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/require"
9
10	"github.com/bnema/dumber/internal/domain/entity"
11)
12
13func TestFloatingSessionRegistry(t *testing.T) {
14	tab1, tab2 := entity.TabID("tab-1"), entity.TabID("tab-2")
15	gmail := newFloatingPaneSession(tab1, "profile:gmail")
16	blank := newFloatingPaneSession(tab1, "profile:blank")
17	other := newFloatingPaneSession(tab2, "profile:gmail")
18	blank.pane.Show()
19
20	r := floatingSessionRegistry{
21		floatingSessionMapKey(tab1, "profile:gmail"): gmail,
22		floatingSessionMapKey(tab1, "profile:blank"): blank,
23		floatingSessionMapKey(tab2, "profile:gmail"): other,
24		floatingSessionMapKey(tab2, "profile:nil"):   nil,
25	}
26
27	t.Run("forTab skips other tabs and nil sessions", func(t *testing.T) {
28		assert.Len(t, r.forTabSnapshot(tab1), 2)
29		assert.Len(t, r.forTabSnapshot(tab2), 1)
30		assert.Len(t, maps.Collect(r.all()), 3, "all skips nil sessions")
31	})
32
33	t.Run("forTab does not allocate", func(t *testing.T) {
34		allocs := testing.AllocsPerRun(100, func() {
35			for range r.forTab(tab1) {
36			}
37		})
38		assert.Zero(t, allocs)
39	})
40
41	t.Run("byPaneID maps the pane to its owning key", func(t *testing.T) {
42		key, session, ok := r.byPaneID(other.paneID)
43		require.True(t, ok)
44		assert.Same(t, other, session)
45		assert.Equal(t, tab2, key.tabID)
46
47		_, _, ok = r.byPaneID("")
48		assert.False(t, ok)
49	})
50
51	t.Run("visibleForTab returns only the shown session", func(t *testing.T) {
52		_, session, ok := r.visibleForTab(tab1)
53		require.True(t, ok)
54		assert.Same(t, blank, session)
55
56		key, _, ok := r.visibleForTab(tab2)
57		assert.False(t, ok)
58		assert.Equal(t, tab2, key.tabID, "miss still reports the tab")
59	})
60
61	t.Run("tabIDs is distinct and sorted", func(t *testing.T) {
62		assert.Equal(t, []entity.TabID{tab1, tab2}, r.tabIDs())
63	})
64}

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