main 5041353

vim_mode_policy_test.go RawHistoryFolder

1package usecase
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7)
8
9func TestVimModePolicyEvaluate(t *testing.T) {
10	tests := []struct {
11		name  string
12		input VimModePolicyInput
13		want  VimModePolicyTransition
14	}{
15		{
16			name: "activation stays allowed while page editable focused",
17			input: VimModePolicyInput{
18				Trigger:             VimModePolicyTriggerActivationAttempt,
19				PageEditableFocused: true,
20			},
21			want: VimModePolicyTransitionStay,
22		},
23		{
24			name: "activation stays allowed when page is not editable",
25			input: VimModePolicyInput{
26				Trigger:             VimModePolicyTriggerActivationAttempt,
27				PageEditableFocused: false,
28			},
29			want: VimModePolicyTransitionStay,
30		},
31		{
32			name: "active page editable focus exits vim mode",
33			input: VimModePolicyInput{
34				Trigger:              VimModePolicyTriggerPageEditableFocusChanged,
35				VimModeActive:        true,
36				PageEditableFocused:  true,
37				EventInActiveContext: true,
38			},
39			want: VimModePolicyTransitionExit,
40		},
41		{
42			name: "background page editable focus does not exit vim mode",
43			input: VimModePolicyInput{
44				Trigger:              VimModePolicyTriggerPageEditableFocusChanged,
45				VimModeActive:        true,
46				PageEditableFocused:  true,
47				EventInActiveContext: false,
48			},
49			want: VimModePolicyTransitionStay,
50		},
51		{
52			name: "overlay focus exits vim mode",
53			input: VimModePolicyInput{
54				Trigger:       VimModePolicyTriggerOverlayFocus,
55				VimModeActive: true,
56			},
57			want: VimModePolicyTransitionExit,
58		},
59		{
60			name: "omnibox focus exits vim mode",
61			input: VimModePolicyInput{
62				Trigger:       VimModePolicyTriggerOmniboxFocus,
63				VimModeActive: true,
64			},
65			want: VimModePolicyTransitionExit,
66		},
67		{
68			name: "find bar focus exits vim mode",
69			input: VimModePolicyInput{
70				Trigger:       VimModePolicyTriggerFindBarFocus,
71				VimModeActive: true,
72			},
73			want: VimModePolicyTransitionExit,
74		},
75		{
76			name: "context change preserves vim mode when scoped context stays valid",
77			input: VimModePolicyInput{
78				Trigger:                 VimModePolicyTriggerContextChanged,
79				VimModeActive:           true,
80				PreserveOnContextChange: true,
81			},
82			want: VimModePolicyTransitionStay,
83		},
84		{
85			name: "context change exits vim mode when scoped context is lost",
86			input: VimModePolicyInput{
87				Trigger:                 VimModePolicyTriggerContextChanged,
88				VimModeActive:           true,
89				PreserveOnContextChange: false,
90			},
91			want: VimModePolicyTransitionExit,
92		},
93		{
94			name: "non vim mode focus change stays normal",
95			input: VimModePolicyInput{
96				Trigger:       VimModePolicyTriggerOverlayFocus,
97				VimModeActive: false,
98			},
99			want: VimModePolicyTransitionStay,
100		},
101	}
102
103	uc := NewVimModePolicyUseCase()
104	for _, tt := range tests {
105		t.Run(tt.name, func(t *testing.T) {
106			assert.Equal(t, tt.want, uc.Evaluate(tt.input))
107		})
108	}
109}

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