-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_test.go
More file actions
215 lines (209 loc) · 5.48 KB
/
screen_test.go
File metadata and controls
215 lines (209 loc) · 5.48 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package main
import (
"testing"
)
func TestGetWindowDimensions(t *testing.T) {
tests := []struct {
name string
state *WindowState
config Config
expectedWidth int
expectedHeight int
}{
{
name: "defaults when no state or config",
state: nil,
config: Config{},
expectedWidth: DefaultWindowWidth,
expectedHeight: DefaultWindowHeight,
},
{
name: "config overrides defaults",
state: nil,
config: Config{DefaultWidth: 1200, DefaultHeight: 800},
expectedWidth: 1200,
expectedHeight: 800,
},
{
name: "state overrides config",
state: &WindowState{Width: 1400, Height: 900, X: 0, Y: 0},
config: Config{DefaultWidth: 1200, DefaultHeight: 800},
expectedWidth: 1400,
expectedHeight: 900,
},
{
name: "state overrides defaults",
state: &WindowState{Width: 1000, Height: 600, X: 0, Y: 0},
config: Config{},
expectedWidth: 1000,
expectedHeight: 600,
},
{
name: "partial config - only width",
state: nil,
config: Config{DefaultWidth: 1200},
expectedWidth: 1200,
expectedHeight: DefaultWindowHeight,
},
{
name: "partial config - only height",
state: nil,
config: Config{DefaultHeight: 800},
expectedWidth: DefaultWindowWidth,
expectedHeight: 800,
},
{
name: "enforces minimum width",
state: &WindowState{Width: 100, Height: 600, X: 0, Y: 0},
config: Config{},
expectedWidth: MinWindowWidth,
expectedHeight: 600,
},
{
name: "enforces minimum height",
state: &WindowState{Width: 900, Height: 100, X: 0, Y: 0},
config: Config{},
expectedWidth: 900,
expectedHeight: MinWindowHeight,
},
{
name: "config below minimum is enforced",
state: nil,
config: Config{DefaultWidth: 200, DefaultHeight: 150},
expectedWidth: MinWindowWidth,
expectedHeight: MinWindowHeight,
},
{
name: "invalid state uses config",
state: &WindowState{Width: 0, Height: 0},
config: Config{DefaultWidth: 1200, DefaultHeight: 800},
expectedWidth: 1200,
expectedHeight: 800,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
width, height := GetWindowDimensions(tt.state, tt.config)
if width != tt.expectedWidth {
t.Errorf("width = %d, expected %d", width, tt.expectedWidth)
}
if height != tt.expectedHeight {
t.Errorf("height = %d, expected %d", height, tt.expectedHeight)
}
})
}
}
func TestGetWindowPosition(t *testing.T) {
tests := []struct {
name string
state *WindowState
config Config
expectedX int
expectedY int
shouldSet bool
}{
{
name: "no state or config - don't set",
state: nil,
config: Config{},
expectedX: 0,
expectedY: 0,
shouldSet: false,
},
{
name: "config sets position",
state: nil,
config: Config{DefaultX: 100, DefaultY: 200},
expectedX: 100,
expectedY: 200,
shouldSet: true,
},
{
name: "config with only X",
state: nil,
config: Config{DefaultX: 100},
expectedX: 100,
expectedY: 0,
shouldSet: true,
},
{
name: "config with only Y",
state: nil,
config: Config{DefaultY: 200},
expectedX: 0,
expectedY: 200,
shouldSet: true,
},
{
name: "state overrides config",
state: &WindowState{Width: 900, Height: 700, X: 300, Y: 400},
config: Config{DefaultX: 100, DefaultY: 200},
expectedX: 300,
expectedY: 400,
shouldSet: true,
},
{
name: "state at origin still sets position",
state: &WindowState{Width: 900, Height: 700, X: 0, Y: 0},
config: Config{},
expectedX: 0,
expectedY: 0,
shouldSet: true,
},
{
name: "invalid state uses config",
state: &WindowState{Width: 0, Height: 0, X: 300, Y: 400},
config: Config{DefaultX: 100, DefaultY: 200},
expectedX: 100,
expectedY: 200,
shouldSet: true,
},
{
name: "invalid state no config - don't set",
state: &WindowState{Width: 0, Height: 0},
config: Config{},
expectedX: 0,
expectedY: 0,
shouldSet: false,
},
{
name: "negative position from state",
state: &WindowState{Width: 900, Height: 700, X: -100, Y: -50},
config: Config{},
expectedX: -100,
expectedY: -50,
shouldSet: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
x, y, shouldSet := GetWindowPosition(tt.state, tt.config)
if x != tt.expectedX {
t.Errorf("x = %d, expected %d", x, tt.expectedX)
}
if y != tt.expectedY {
t.Errorf("y = %d, expected %d", y, tt.expectedY)
}
if shouldSet != tt.shouldSet {
t.Errorf("shouldSet = %v, expected %v", shouldSet, tt.shouldSet)
}
})
}
}
func TestConstants(t *testing.T) {
// Verify constants have reasonable values
if DefaultWindowWidth < MinWindowWidth {
t.Errorf("DefaultWindowWidth (%d) should be >= MinWindowWidth (%d)",
DefaultWindowWidth, MinWindowWidth)
}
if DefaultWindowHeight < MinWindowHeight {
t.Errorf("DefaultWindowHeight (%d) should be >= MinWindowHeight (%d)",
DefaultWindowHeight, MinWindowHeight)
}
if MinWindowWidth <= 0 {
t.Errorf("MinWindowWidth should be positive, got %d", MinWindowWidth)
}
if MinWindowHeight <= 0 {
t.Errorf("MinWindowHeight should be positive, got %d", MinWindowHeight)
}
}