forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme_test.go
217 lines (176 loc) · 6.6 KB
/
theme_test.go
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
216
217
package theme
import (
"image/color"
"testing"
"fyne.io/fyne/v2"
"github.com/stretchr/testify/assert"
)
func TestThemeChange(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
bg := BackgroundColor()
fyne.CurrentApp().Settings().SetTheme(LightTheme())
assert.NotEqual(t, bg, BackgroundColor())
}
func TestTheme_Bootstrapping(t *testing.T) {
current := fyne.CurrentApp().Settings().Theme()
fyne.CurrentApp().Settings().SetTheme(nil)
// this should not crash
BackgroundColor()
fyne.CurrentApp().Settings().SetTheme(current)
}
func TestBuiltinTheme_ShadowColor(t *testing.T) {
shadow := ShadowColor()
_, _, _, a := shadow.RGBA()
assert.NotEqual(t, 255, a)
}
func TestTheme_Dark_ReturnsCorrectBackground(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
bg := BackgroundColor()
assert.Equal(t, DarkTheme().Color(ColorNameBackground, VariantDark), bg, "wrong dark theme background color")
}
func TestTheme_Light_ReturnsCorrectBackground(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(LightTheme())
bg := BackgroundColor()
assert.Equal(t, LightTheme().Color(ColorNameBackground, VariantLight), bg, "wrong light theme background color")
}
func Test_ButtonColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := ButtonColor()
assert.Equal(t, DarkTheme().Color(ColorNameButton, VariantDark), c, "wrong button color")
}
func Test_TextColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := ForegroundColor()
assert.Equal(t, DarkTheme().Color(ColorNameForeground, VariantDark), c, "wrong text color")
}
func Test_DisabledTextColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := DisabledColor()
assert.Equal(t, DarkTheme().Color(ColorNameDisabled, VariantDark), c, "wrong disabled text color")
}
func Test_PlaceHolderColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := PlaceHolderColor()
assert.Equal(t, DarkTheme().Color(ColorNamePlaceHolder, VariantDark), c, "wrong placeholder color")
}
func Test_PrimaryColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := PrimaryColor()
assert.Equal(t, DarkTheme().Color(ColorNamePrimary, VariantDark), c, "wrong primary color")
}
func Test_HoverColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := HoverColor()
assert.Equal(t, DarkTheme().Color(ColorNameHover, VariantDark), c, "wrong hover color")
}
func Test_FocusColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := FocusColor()
assert.Equal(t, DarkTheme().Color(ColorNameFocus, VariantDark), c, "wrong focus color")
}
func Test_ScrollBarColor(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
c := ScrollBarColor()
assert.Equal(t, DarkTheme().Color(ColorNameScrollBar, VariantDark), c, "wrong scrollbar color")
}
func Test_TextSize(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
assert.Equal(t, DarkTheme().Size(SizeNameText), TextSize(), "wrong text size")
}
func Test_TabWidth(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
assert.Equal(t, DarkTheme().Size(SizeNameTabWidth), current().Size(SizeNameTabWidth), "wrong tab width")
}
func Test_TextFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Regular.ttf"
result := TextFont().Name()
assert.Equal(t, expect, result, "wrong regular text font")
}
func Test_TextBoldFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Bold.ttf"
result := TextBoldFont().Name()
assert.Equal(t, expect, result, "wrong bold text font")
}
func Test_TextItalicFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Italic.ttf"
result := TextItalicFont().Name()
assert.Equal(t, expect, result, "wrong italic text font")
}
func Test_TextBoldItalicFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-BoldItalic.ttf"
result := TextBoldItalicFont().Name()
assert.Equal(t, expect, result, "wrong bold italic text font")
}
func Test_TextMonospaceFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "DejaVuSansMono-Powerline.ttf"
result := TextMonospaceFont().Name()
assert.Equal(t, expect, result, "wrong monospace font")
}
func Test_Padding(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
assert.Equal(t, DarkTheme().Size(SizeNamePadding), Padding(), "wrong padding")
}
func Test_IconInlineSize(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
assert.Equal(t, DarkTheme().Size(SizeNameInlineIcon), IconInlineSize(), "wrong inline icon size")
}
func Test_ScrollBarSize(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
assert.Equal(t, DarkTheme().Size(SizeNameScrollBar), ScrollBarSize(), "wrong inline icon size")
}
func Test_DefaultTextFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Regular.ttf"
result := DefaultTextFont().Name()
assert.Equal(t, expect, result, "wrong default text font")
}
func Test_DefaultTextBoldFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Bold.ttf"
result := DefaultTextBoldFont().Name()
assert.Equal(t, expect, result, "wrong default text bold font")
}
func Test_DefaultTextBoldItalicFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-BoldItalic.ttf"
result := DefaultTextBoldItalicFont().Name()
assert.Equal(t, expect, result, "wrong default text bold italic font")
}
func Test_DefaultTextItalicFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "NotoSans-Italic.ttf"
result := DefaultTextItalicFont().Name()
assert.Equal(t, expect, result, "wrong default text italic font")
}
func Test_DefaultTextMonospaceFont(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
expect := "DejaVuSansMono-Powerline.ttf"
result := DefaultTextMonospaceFont().Name()
assert.Equal(t, expect, result, "wrong default monospace font")
}
func TestEmptyTheme(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(&emptyTheme{})
assert.NotNil(t, ForegroundColor())
assert.NotNil(t, TextFont())
assert.NotNil(t, HelpIcon())
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
}
type emptyTheme struct {
}
func (e *emptyTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
return nil
}
func (e *emptyTheme) Font(s fyne.TextStyle) fyne.Resource {
return nil
}
func (e *emptyTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
return nil
}
func (e *emptyTheme) Size(n fyne.ThemeSizeName) float32 {
return 0
}