presentation_test.go RawHistoryFolder

1package ui
2
3import (
4	"testing"
5
6	"github.com/bnema/vev/internal/domain"
7	"github.com/stretchr/testify/require"
8)
9
10func TestResolvePresentation(t *testing.T) {
11	tests := []struct {
12		name          string
13		base          domain.Size
14		bounds, inner domain.Rect
15		want          Presentation
16	}{
17		{
18			name:   "79 columns becomes full-width drawer",
19			base:   domain.Size{Cols: 79, Rows: 24},
20			bounds: domain.Rect{X: 8, Y: 6, Width: 63, Height: 11},
21			inner:  domain.Rect{X: 9, Y: 7, Width: 61, Height: 9},
22			want: Presentation{
23				Mode:    PresentationDrawer,
24				Bounds:  domain.Rect{X: 0, Y: 12, Width: 79, Height: 11},
25				Inner:   domain.Rect{X: 0, Y: 13, Width: 79, Height: 10},
26				Borders: BorderTop,
27			},
28		},
29		{
30			name:   "80 columns preserves preferred geometry",
31			base:   domain.Size{Cols: 80, Rows: 24},
32			bounds: domain.Rect{X: 8, Y: 3, Width: 64, Height: 18},
33			inner:  domain.Rect{X: 9, Y: 4, Width: 62, Height: 16},
34			want: Presentation{
35				Mode:    PresentationFloating,
36				Bounds:  domain.Rect{X: 8, Y: 3, Width: 64, Height: 18},
37				Inner:   domain.Rect{X: 9, Y: 4, Width: 62, Height: 16},
38				Borders: BorderAll,
39			},
40		},
41		{
42			name:   "100 percent height preserves three rows and bottom bar",
43			base:   domain.Size{Cols: 79, Rows: 24},
44			bounds: domain.Rect{Width: 79, Height: 24},
45			inner:  domain.Rect{X: 1, Y: 1, Width: 77, Height: 22},
46			want: Presentation{
47				Mode:    PresentationDrawer,
48				Bounds:  domain.Rect{X: 0, Y: 3, Width: 79, Height: 20},
49				Inner:   domain.Rect{X: 0, Y: 4, Width: 79, Height: 19},
50				Borders: BorderTop,
51			},
52		},
53		{
54			name:   "preferred height larger than available is capped",
55			base:   domain.Size{Cols: 79, Rows: 10},
56			bounds: domain.Rect{X: -100, Y: -100, Width: 1000, Height: 1000},
57			inner:  domain.Rect{X: -99, Y: -99, Width: 998, Height: 998},
58			want: Presentation{
59				Mode:    PresentationDrawer,
60				Bounds:  domain.Rect{X: 0, Y: 3, Width: 79, Height: 6},
61				Inner:   domain.Rect{X: 0, Y: 4, Width: 79, Height: 5},
62				Borders: BorderTop,
63			},
64		},
65		{
66			name:   "negative preferred height becomes empty drawer",
67			base:   domain.Size{Cols: 79, Rows: 24},
68			bounds: domain.Rect{Height: -1},
69			inner:  domain.Rect{Height: -3},
70			want: Presentation{
71				Mode:    PresentationDrawer,
72				Bounds:  domain.Rect{X: 0, Y: 23, Width: 79, Height: 0},
73				Inner:   domain.Rect{X: 0, Y: 23, Width: 79, Height: 0},
74				Borders: BorderTop,
75			},
76		},
77		{
78			name:   "four-row terminal reserves all protected rows",
79			base:   domain.Size{Cols: 79, Rows: 4},
80			bounds: domain.Rect{Width: 79, Height: 4},
81			inner:  domain.Rect{X: 1, Y: 1, Width: 77, Height: 2},
82			want: Presentation{
83				Mode:    PresentationDrawer,
84				Bounds:  domain.Rect{X: 0, Y: 3, Width: 79},
85				Inner:   domain.Rect{X: 0, Y: 3, Width: 79},
86				Borders: BorderTop,
87			},
88		},
89		{
90			name:   "one-row terminal is panic-free and empty",
91			base:   domain.Size{Cols: 1, Rows: 1},
92			bounds: domain.Rect{Width: 1, Height: 1},
93			inner:  domain.Rect{X: 1, Y: 1},
94			want: Presentation{
95				Mode:    PresentationDrawer,
96				Bounds:  domain.Rect{X: 0, Y: 0, Width: 1},
97				Inner:   domain.Rect{X: 0, Y: 0, Width: 1},
98				Borders: BorderTop,
99			},
100		},
101		{name: "zero frame is empty", base: domain.Size{}, want: Presentation{}},
102		{name: "negative columns are empty", base: domain.Size{Cols: -1, Rows: 24}, want: Presentation{}},
103		{name: "negative rows are empty", base: domain.Size{Cols: 79, Rows: -1}, want: Presentation{}},
104	}
105
106	for _, tt := range tests {
107		t.Run(tt.name, func(t *testing.T) {
108			require.Equal(t, tt.want, ResolvePresentation(tt.base, tt.bounds, tt.inner))
109		})
110	}
111}

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 12

Tags 11

↑↓ moveenter openesc close