-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathmain_test.go
More file actions
151 lines (140 loc) · 4.97 KB
/
Copy pathmain_test.go
File metadata and controls
151 lines (140 loc) · 4.97 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"testing"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
func TestIsLowMemoryMode(t *testing.T) {
tests := []struct {
name string
env string
want bool
}{
{name: "disabled by default", env: "", want: false},
{name: "enabled with one", env: "1", want: true},
{name: "enabled with true", env: "true", want: true},
{name: "enabled with yes and whitespace", env: " yes ", want: true},
{name: "disabled with false", env: "false", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("GONAVI_LOW_MEMORY_MODE", tt.env)
if got := isLowMemoryMode(); got != tt.want {
t.Fatalf("isLowMemoryMode() = %v, want %v", got, tt.want)
}
})
}
}
func TestResolveWindowVisualOptions(t *testing.T) {
tests := []struct {
name string
goos string
lowMemoryMode bool
wantBackground options.RGBA
wantWebviewOpaque bool
wantWindowOpaque bool
wantWindowsBackdrop windows.BackdropType
}{
{
name: "windows defaults to opaque without acrylic",
goos: "windows",
wantBackground: options.RGBA{R: 255, G: 255, B: 255, A: 255},
wantWebviewOpaque: true,
wantWindowOpaque: true,
wantWindowsBackdrop: windows.None,
},
{
name: "windows low memory remains opaque",
goos: " Windows ",
lowMemoryMode: true,
wantBackground: options.RGBA{R: 255, G: 255, B: 255, A: 255},
wantWebviewOpaque: true,
wantWindowOpaque: true,
wantWindowsBackdrop: windows.None,
},
{
name: "mac default remains transparent",
goos: "darwin",
wantBackground: options.RGBA{R: 0, G: 0, B: 0, A: 0},
wantWebviewOpaque: false,
wantWindowOpaque: false,
wantWindowsBackdrop: windows.Acrylic,
},
{
name: "low memory remains opaque on other platforms",
goos: "darwin",
lowMemoryMode: true,
wantBackground: options.RGBA{R: 255, G: 255, B: 255, A: 255},
wantWebviewOpaque: true,
wantWindowOpaque: true,
wantWindowsBackdrop: windows.None,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
background, windowsOptions := resolveWindowVisualOptions(tt.goos, tt.lowMemoryMode)
if background == nil {
t.Fatal("resolveWindowVisualOptions() background is nil")
}
if got := *background; got != tt.wantBackground {
t.Fatalf("background = %+v, want %+v", got, tt.wantBackground)
}
if windowsOptions == nil {
t.Fatal("resolveWindowVisualOptions() windows options are nil")
}
if got := !windowsOptions.WebviewIsTransparent; got != tt.wantWebviewOpaque {
t.Fatalf("webview opaque = %v, want %v", got, tt.wantWebviewOpaque)
}
if got := !windowsOptions.WindowIsTranslucent; got != tt.wantWindowOpaque {
t.Fatalf("window opaque = %v, want %v", got, tt.wantWindowOpaque)
}
if got := windowsOptions.BackdropType; got != tt.wantWindowsBackdrop {
t.Fatalf("Windows backdrop = %v, want %v", got, tt.wantWindowsBackdrop)
}
})
}
}
func TestBuildMacApplicationMenu(t *testing.T) {
called := 0
appMenu := buildMacApplicationMenu(func() {
called++
}, true)
if appMenu == nil {
t.Fatal("buildMacApplicationMenu() returned nil")
}
if len(appMenu.Items) != 3 {
t.Fatalf("expected 3 top-level menu items, got %d", len(appMenu.Items))
}
if appMenu.Items[0].Role != menu.AppMenuRole {
t.Fatalf("first top-level menu role = %v, want %v", appMenu.Items[0].Role, menu.AppMenuRole)
}
if appMenu.Items[1].Role != menu.EditMenuRole {
t.Fatalf("second top-level menu role = %v, want %v", appMenu.Items[1].Role, menu.EditMenuRole)
}
queryEditorMenu := appMenu.Items[2]
if queryEditorMenu.Label != "SQL" {
t.Fatalf("query editor menu label = %q, want %q", queryEditorMenu.Label, "SQL")
}
if queryEditorMenu.SubMenu == nil || len(queryEditorMenu.SubMenu.Items) != 1 {
t.Fatalf("query editor submenu items = %d, want 1", len(queryEditorMenu.SubMenu.Items))
}
copyCurrentLineItem := queryEditorMenu.SubMenu.Items[0]
if copyCurrentLineItem.Label != "Copy Current Line" {
t.Fatalf("menu item label = %q, want %q", copyCurrentLineItem.Label, "Copy Current Line")
}
if copyCurrentLineItem.Accelerator == nil {
t.Fatal("menu item accelerator is nil")
}
if copyCurrentLineItem.Accelerator.Key != "e" {
t.Fatalf("menu item accelerator key = %q, want %q", copyCurrentLineItem.Accelerator.Key, "e")
}
if len(copyCurrentLineItem.Accelerator.Modifiers) != 1 || copyCurrentLineItem.Accelerator.Modifiers[0] != keys.CmdOrCtrlKey {
t.Fatalf("menu item modifiers = %v, want [%v]", copyCurrentLineItem.Accelerator.Modifiers, keys.CmdOrCtrlKey)
}
copyCurrentLineItem.Click(&menu.CallbackData{MenuItem: copyCurrentLineItem})
if called != 1 {
t.Fatalf("native select-current-line callback called %d times, want 1", called)
}
}