-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathkeybinds_test.go
More file actions
89 lines (81 loc) · 2.91 KB
/
Copy pathkeybinds_test.go
File metadata and controls
89 lines (81 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package config
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestValidateKeybinds_NoConflicts(t *testing.T) {
kb := defaultKeybinds()
conflicts := ValidateKeybinds(kb)
if len(conflicts) != 0 {
t.Errorf("default keybinds have conflicts: %v", conflicts)
}
}
func TestValidateKeybinds_InboxConflict(t *testing.T) {
kb := defaultKeybinds()
kb.Inbox.Archive = kb.Inbox.Delete // same key as delete
conflicts := ValidateKeybinds(kb)
if len(conflicts) == 0 {
t.Fatal("expected conflict, got none")
}
found := false
for _, c := range conflicts {
if strings.Contains(c, "inbox") {
found = true
break
}
}
if !found {
t.Errorf("expected inbox conflict, got: %v", conflicts)
}
}
func TestValidateKeybinds_CrossAreaNotConflict(t *testing.T) {
kb := defaultKeybinds()
// "d" is delete in both inbox and email — intentional, not a conflict
kb.Inbox.Delete = "d"
kb.Email.Delete = "d"
conflicts := ValidateKeybinds(kb)
if len(conflicts) != 0 {
t.Errorf("cross-area duplicates should not be conflicts: %v", conflicts)
}
}
func TestValidateKeybinds_EmptyKeySkipped(t *testing.T) {
kb := defaultKeybinds()
kb.Drafts.Delete = ""
kb.Drafts.Open = ""
conflicts := ValidateKeybinds(kb)
if len(conflicts) != 0 {
t.Errorf("empty keys should not produce conflicts: %v", conflicts)
}
}
func TestLoadKeybindsFromDir_WritesDefault(t *testing.T) {
dir := t.TempDir()
if err := LoadKeybindsFromDir(dir); err != nil {
t.Fatalf("LoadKeybindsFromDir: %v", err)
}
if Keybinds.Inbox.Delete == "" {
t.Error("expected inbox.delete to be set after loading defaults")
}
}
func TestLoadKeybindsFromDir_ParsesCustom(t *testing.T) {
dir := t.TempDir()
// Write defaults first
if err := LoadKeybindsFromDir(dir); err != nil {
t.Fatalf("write defaults: %v", err)
}
// Override inbox delete key
custom := `{"inbox":{"delete":"x","archive":"a","refresh":"r","open":"enter","next_tab":"l","prev_tab":"h","visual_mode":"v"},"global":{"quit":"ctrl+c","cancel":"esc","nav_up":"k","nav_down":"j"},"email":{"reply":"r","forward":"f","delete":"d","archive":"a","toggle_images":"i","rsvp_accept":"1","rsvp_decline":"2","rsvp_tentative":"3","focus_attachments":"tab"},"composer":{"external_editor":"ctrl+e","next_field":"tab","prev_field":"shift+tab","account_picker_filter":"ctrl+f"},"folder":{"next_folder":"tab","prev_folder":"shift+tab","move":"m","focus_preview":"]","focus_inbox":"["},"drafts":{"open":"enter","delete":"d"}}`
if err := os.WriteFile(filepath.Join(dir, "keybinds.json"), []byte(custom), 0600); err != nil {
t.Fatalf("write custom: %v", err)
}
if err := LoadKeybindsFromDir(dir); err != nil {
t.Fatalf("LoadKeybindsFromDir custom: %v", err)
}
if Keybinds.Inbox.Delete != "x" {
t.Errorf("expected inbox.delete=x, got %q", Keybinds.Inbox.Delete)
}
if Keybinds.Composer.AccountPickerFilter != "ctrl+f" {
t.Errorf("expected composer.account_picker_filter=ctrl+f, got %q", Keybinds.Composer.AccountPickerFilter)
}
}