action_test.go RawHistoryFolder

1package palette
2
3import (
4	"testing"
5	"time"
6
7	"github.com/bnema/vev/internal/usecase/command"
8)
9
10func TestParseActionExactEffectiveToken(t *testing.T) {
11	results := CommandResults([]command.Command{
12		{Code: "BCK", Arguments: command.ArgumentsNone},
13		{Code: "JRS", Arguments: command.ArgumentsRequired, ContextHint: command.ContextHintRecentSessions},
14		{Code: "CNS", Arguments: command.ArgumentsOptional},
15	})
16	tests := []struct {
17		name  string
18		input string
19		ok    bool
20		code  string
21		args  []string
22	}{
23		{name: "static token ignores case and whitespace", input: "  bCk  ", ok: true, code: "BCK"},
24		{name: "required arguments accept repeated whitespace", input: " JRS   2 ", ok: true, code: "JRS", args: []string{"2"}},
25		{name: "partial token rejected", input: "JR", ok: false},
26		{name: "concatenated token rejected", input: "JRS2", ok: false},
27		{name: "static arguments rejected", input: "BCK 2", ok: false},
28		{name: "missing required argument rejected", input: "JRS", ok: false},
29		{name: "optional argument omitted", input: "CNS", ok: true, code: "CNS"},
30		{name: "optional argument provided", input: "CNS toto", ok: true, code: "CNS", args: []string{"toto"}},
31	}
32	for _, tt := range tests {
33		t.Run(tt.name, func(t *testing.T) {
34			action, ok := ParseAction(results, tt.input)
35			if ok != tt.ok {
36				t.Fatalf("ParseAction(%q) ok = %v, want %v", tt.input, ok, tt.ok)
37			}
38			if !ok {
39				return
40			}
41			if action.Command.Code != tt.code || !sameStrings(action.Args, tt.args) {
42				t.Fatalf("ParseAction(%q) = %#v, want %s %#v", tt.input, action, tt.code, tt.args)
43			}
44		})
45	}
46}
47
48func TestArgumentCommandKeepsExactRowVisible(t *testing.T) {
49	cmd := command.Command{Code: "JRS", Arguments: command.ArgumentsRequired}
50	if got, ok := ArgumentCommand(CommandResults([]command.Command{cmd}), "JRS 1"); !ok || got.Code != "JRS" {
51		t.Fatalf("ArgumentCommand() = %#v, %v; want JRS, true", got, ok)
52	}
53}
54
55func TestArgumentResultReturnsTheMatchingRowAndCommand(t *testing.T) {
56	jrs := command.Command{Code: "JRS", Arguments: command.ArgumentsRequired}
57	results := []Result{NewStoppedSessionResult(testExactTarget("JRS", 1), time.Time{}), NewCommandResult(jrs)}
58
59	result, got, ok := argumentResult(results, "jrs 1")
60
61	if !ok || result.Kind() != ResultKindCommand || got.Code != jrs.Code {
62		t.Fatalf("argumentResult() = %#v, %#v, %v; want matching JRS row and command", result, got, ok)
63	}
64}
65
66func sameStrings(a, b []string) bool {
67	if len(a) != len(b) {
68		return false
69	}
70	for i := range a {
71		if a[i] != b[i] {
72			return false
73		}
74	}
75	return true
76}

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