main 3d41bc5

app_test.go RawHistoryFolder

1package app
2
3import (
4	"context"
5	"errors"
6	"testing"
7
8	"github.com/bnema/nefercap/internal/core"
9	portsmocks "github.com/bnema/nefercap/internal/mocks/ports"
10	"github.com/bnema/nefercap/internal/ports"
11)
12
13func TestScreenshotWithoutVideoWriter(t *testing.T) {
14	ctx := context.Background()
15	target := ports.Target{OutputID: 1}
16	frame := ports.Frame{Pixels: make([]byte, 16), Width: 2, Height: 2, Stride: 8, Format: ports.XRGB8888}
17	source := portsmocks.NewMockSource(t)
18	writer := portsmocks.NewMockScreenshotWriter(t)
19	source.EXPECT().Capture(ctx, target).Return(frame, nil).Once()
20	writer.EXPECT().Save(ctx, frame, "shot.png").Return(nil).Once()
21	if err := core.New(source, writer, nil).Run(ctx, ports.Selection{Mode: ports.Screenshot, Target: target, Path: "shot.png"}); err != nil {
22		t.Fatal(err)
23	}
24}
25
26func TestDiscoveryError(t *testing.T) {
27	ctx, cancel := context.WithCancel(context.Background())
28	defer cancel()
29	deadline := discoveryError(ctx, "list outputs", context.DeadlineExceeded)
30	if !errors.Is(deadline, context.DeadlineExceeded) || deadline == context.DeadlineExceeded {
31		t.Fatalf("timeout lost phase: %v", deadline)
32	}
33	cancel()
34	if err := discoveryError(ctx, "connect Wayland", context.Canceled); err != context.Canceled {
35		t.Fatalf("signal wrapped: %v", err)
36	}
37	real := errors.New("protocol failure")
38	if err := discoveryError(ctx, "list outputs", real); !errors.Is(err, real) || err == real {
39		t.Fatalf("failure lost phase: %v", err)
40	}
41}
42
43func TestResolveOutput(t *testing.T) {
44	outputs := []ports.Output{{ID: 1, Name: "DP-1"}, {ID: 2, Name: "HDMI-A-1"}}
45	got, err := resolveOutput(outputs, "HDMI-A-1")
46	if err != nil || got.ID != 2 {
47		t.Fatalf("named output: %v, %v", got, err)
48	}
49	if _, err := resolveOutput(outputs, ""); err == nil {
50		t.Fatal("ambiguous default accepted")
51	}
52	if _, err := resolveOutput(outputs, "missing"); !errors.Is(err, ports.ErrOutputNotFound) {
53		t.Fatalf("missing output: %v", err)
54	}
55	if _, err := resolveOutput(nil, ""); err == nil {
56		t.Fatal("empty default accepted")
57	}
58	got, err = resolveOutput(outputs[:1], "")
59	if err != nil || got.ID != 1 {
60		t.Fatalf("single output: %v, %v", got, err)
61	}
62}
63
64func TestResolveOutputAllocations(t *testing.T) {
65	outputs := []ports.Output{{ID: 1, Name: "DP-1"}}
66	if allocs := testing.AllocsPerRun(1000, func() {
67		if _, err := resolveOutput(outputs, "DP-1"); err != nil {
68			panic(err)
69		}
70	}); allocs != 0 {
71		t.Fatalf("output lookup: %g allocations", allocs)
72	}
73}

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 9

↑↓ moveenter openesc close