v0.2.0 80c61e3

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

Tags 11

↑↓ moveenter openesc close