-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
icons_test.go
462 lines (373 loc) · 15.2 KB
/
icons_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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
package theme_test
import (
"fmt"
"path/filepath"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
func init() {
fyne.SetCurrentApp(&themedApp{})
}
func helperNewStaticResource() *fyne.StaticResource {
return &fyne.StaticResource{
StaticName: "content-remove.svg",
StaticContent: []byte{
60, 115, 118, 103, 32, 120, 109, 108, 110, 115, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 48, 47, 115, 118, 103, 34, 32, 119, 105, 100, 116, 104, 61, 34, 50, 52, 34, 32, 104, 101, 105, 103, 104, 116, 61, 34, 50, 52, 34, 32, 118, 105, 101, 119, 66, 111, 120, 61, 34, 48, 32, 48, 32, 50, 52, 32, 50, 52, 34, 62, 60, 112, 97, 116, 104, 32, 102, 105, 108, 108, 61, 34, 35, 102, 102, 102, 102, 102, 102, 34, 32, 100, 61, 34, 77, 49, 57, 32, 49, 51, 72, 53, 118, 45, 50, 104, 49, 52, 118, 50, 122, 34, 47, 62, 60, 112, 97, 116, 104, 32, 100, 61, 34, 77, 48, 32, 48, 104, 50, 52, 118, 50, 52, 72, 48, 122, 34, 32, 102, 105, 108, 108, 61, 34, 110, 111, 110, 101, 34, 47, 62, 60, 47, 115, 118, 103, 62},
}
}
func helperLoadRes(t *testing.T, name string) fyne.Resource {
path := filepath.Join("testdata", name) // pathObj relative to this file
res, err := fyne.LoadResourceFromPath(path)
if err != nil {
t.Fatal(err)
}
return res
}
func TestIconThemeChangeDoesNotChangeName(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
cancel := theme.CancelIcon()
name := cancel.Name()
fyne.CurrentApp().Settings().SetTheme(theme.LightTheme())
assert.Equal(t, name, cancel.Name())
}
func TestIconThemeChangeContent(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
cancel := theme.CancelIcon()
content := cancel.Content()
fyne.CurrentApp().Settings().SetTheme(theme.LightTheme())
assert.NotEqual(t, content, cancel.Content())
}
func TestIconThemeResourceWithViewboxOnly(t *testing.T) {
r1 := &fyne.StaticResource{
StaticName: "unsplash.svg",
StaticContent: []byte(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.5 6.75V0h9v6.75h-9zm9 3.75H24V24H0V10.5h7.5v6.75h9V10.5z"></path></svg>`),
}
r2 := theme.NewThemedResource(r1)
re := regexp.MustCompile(`\s fill\S `)
content := re.ReplaceAll(r2.Content(), []byte(""))
assert.Equal(t, r1.Content(), content)
}
func TestNewThemedResource_StaticResourceSupport(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
custom := theme.NewThemedResource(helperNewStaticResource())
content := custom.Content()
name := custom.Name()
fyne.CurrentApp().Settings().SetTheme(theme.LightTheme())
assert.NotEqual(t, content, custom.Content())
assert.Equal(t, name, custom.Name())
}
func TestNewColoredResource(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
source := helperNewStaticResource()
custom := theme.NewColoredResource(source, theme.ColorNameSuccess)
assert.Equal(t, theme.ColorNameSuccess, custom.ColorName)
assert.Equal(t, custom.Name(), fmt.Sprintf("success_%v", source.Name()))
custom = theme.NewColoredResource(source, theme.ColorNamePrimary)
assert.Equal(t, custom.Name(), fmt.Sprintf("primary_%v", source.Name()))
}
func TestNewDisabledResource(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
source := helperNewStaticResource()
custom := theme.NewDisabledResource(source)
name := custom.Name()
assert.Equal(t, name, fmt.Sprintf("disabled_%v", source.Name()))
}
func TestThemedResource_Invert(t *testing.T) {
staticResource := helperLoadRes(t, "cancel_Paths.svg")
inverted := theme.NewInvertedThemedResource(staticResource)
assert.Equal(t, "inverted_" staticResource.Name(), inverted.Name())
}
func TestThemedResource_Name(t *testing.T) {
staticResource := helperLoadRes(t, "cancel_Paths.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.Equal(t, "foreground_" staticResource.Name(), themedResource.Name())
}
func TestThemedResource_Content_NoGroupsFile(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "cancel_Paths.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.NotEqual(t, staticResource.Content(), themedResource.Content())
}
func TestThemedResource_Content_GroupPathFile(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "check_GroupPaths.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.NotEqual(t, staticResource.Content(), themedResource.Content())
}
func TestThemedResource_Content_GroupRectFile(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "info_GroupRects.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.NotEqual(t, staticResource.Content(), themedResource.Content())
}
func TestThemedResource_Content_GroupPolygonsFile(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "warning_GroupPolygons.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.NotEqual(t, staticResource.Content(), themedResource.Content())
}
// a black svg object omits the fill tag, this checks if it still properly updated
func TestThemedResource_Content_BlackFillIsUpdated(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "cancel_PathsBlackFill.svg")
themedResource := theme.NewThemedResource(staticResource)
assert.NotEqual(t, staticResource.Content(), themedResource.Content())
}
func TestThemedResource_Error(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
source := helperNewStaticResource()
custom := theme.NewThemedResource(source)
custom.ColorName = theme.ColorNameError
assert.Equal(t, custom.Name(), fmt.Sprintf("error_%v", source.Name()))
custom2 := theme.NewErrorThemedResource(source)
assert.Equal(t, custom2.Name(), fmt.Sprintf("error_%v", source.Name()))
}
func TestThemedResource_Success(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
source := helperNewStaticResource()
custom := theme.NewThemedResource(source)
custom.ColorName = theme.ColorNameSuccess
assert.Equal(t, custom.Name(), fmt.Sprintf("success_%v", source.Name()))
custom = theme.NewSuccessThemedResource(source)
assert.Equal(t, custom.Name(), fmt.Sprintf("success_%v", source.Name()))
}
func TestThemedResource_Warning(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
source := helperNewStaticResource()
custom := theme.NewThemedResource(source)
custom.ColorName = theme.ColorNameWarning
assert.Equal(t, custom.Name(), fmt.Sprintf("warning_%v", source.Name()))
custom = theme.NewWarningThemedResource(source)
assert.Equal(t, custom.Name(), fmt.Sprintf("warning_%v", source.Name()))
}
func TestDisabledResource_Name(t *testing.T) {
staticResource := helperLoadRes(t, "cancel_Paths.svg")
disabledResource := theme.NewDisabledResource(staticResource)
assert.Equal(t, fmt.Sprintf("disabled_%v", staticResource.Name()), disabledResource.Name())
}
func TestDisabledResource_Content_NoGroupsFile(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(theme.DarkTheme())
staticResource := helperLoadRes(t, "cancel_Paths.svg")
disabledResource := theme.NewDisabledResource(staticResource)
assert.NotEqual(t, staticResource.Content(), disabledResource.Content())
}
// Test Asset Sources
func Test_FyneLogo_FileSource(t *testing.T) {
result := theme.FyneLogo().Name()
assert.Equal(t, "fyne.png", result)
}
func Test_CancelIcon_FileSource(t *testing.T) {
result := theme.CancelIcon().Name()
assert.Equal(t, "foreground_cancel.svg", result)
}
func Test_ConfirmIcon_FileSource(t *testing.T) {
result := theme.ConfirmIcon().Name()
assert.Equal(t, "foreground_check.svg", result)
}
func Test_DeleteIcon_FileSource(t *testing.T) {
result := theme.DeleteIcon().Name()
assert.Equal(t, "foreground_delete.svg", result)
}
func Test_SearchIcon_FileSource(t *testing.T) {
result := theme.SearchIcon().Name()
assert.Equal(t, "foreground_search.svg", result)
}
func Test_SearchReplaceIcon_FileSource(t *testing.T) {
result := theme.SearchReplaceIcon().Name()
assert.Equal(t, "foreground_search-replace.svg", result)
}
func Test_CheckButtonIcon_FileSource(t *testing.T) {
result := theme.CheckButtonIcon().Name()
assert.Equal(t, "foreground_check-box.svg", result)
}
func Test_CheckButtonCheckedIcon_FileSource(t *testing.T) {
result := theme.CheckButtonCheckedIcon().Name()
assert.Equal(t, "foreground_check-box-checked.svg", result)
}
func Test_RadioButtonIcon_FileSource(t *testing.T) {
result := theme.RadioButtonIcon().Name()
assert.Equal(t, "foreground_radio-button.svg", result)
}
func Test_RadioButtonCheckedIcon_FileSource(t *testing.T) {
result := theme.RadioButtonCheckedIcon().Name()
assert.Equal(t, "foreground_radio-button-checked.svg", result)
}
func Test_ContentAddIcon_FileSource(t *testing.T) {
result := theme.ContentAddIcon().Name()
assert.Equal(t, "foreground_content-add.svg", result)
}
func Test_ContentRemoveIcon_FileSource(t *testing.T) {
result := theme.ContentRemoveIcon().Name()
assert.Equal(t, "foreground_content-remove.svg", result)
}
func Test_ContentClearIcon_FileSource(t *testing.T) {
result := theme.ContentClearIcon().Name()
assert.Equal(t, "foreground_cancel.svg", result)
}
func Test_ContentCutIcon_FileSource(t *testing.T) {
result := theme.ContentCutIcon().Name()
assert.Equal(t, "foreground_content-cut.svg", result)
}
func Test_ContentCopyIcon_FileSource(t *testing.T) {
result := theme.ContentCopyIcon().Name()
assert.Equal(t, "foreground_content-copy.svg", result)
}
func Test_ContentPasteIcon_FileSource(t *testing.T) {
result := theme.ContentPasteIcon().Name()
assert.Equal(t, "foreground_content-paste.svg", result)
}
func Test_ContentRedoIcon_FileSource(t *testing.T) {
result := theme.ContentRedoIcon().Name()
assert.Equal(t, "foreground_content-redo.svg", result)
}
func Test_ContentUndoIcon_FileSource(t *testing.T) {
result := theme.ContentUndoIcon().Name()
assert.Equal(t, "foreground_content-undo.svg", result)
}
func Test_DocumentCreateIcon_FileSource(t *testing.T) {
result := theme.DocumentCreateIcon().Name()
assert.Equal(t, "foreground_document-create.svg", result)
}
func Test_DocumentPrintIcon_FileSource(t *testing.T) {
result := theme.DocumentPrintIcon().Name()
assert.Equal(t, "foreground_document-print.svg", result)
}
func Test_DocumentSaveIcon_FileSource(t *testing.T) {
result := theme.DocumentSaveIcon().Name()
assert.Equal(t, "foreground_document-save.svg", result)
}
func Test_InfoIcon_FileSource(t *testing.T) {
result := theme.InfoIcon().Name()
assert.Equal(t, "foreground_info.svg", result)
}
func Test_QuestionIcon_FileSource(t *testing.T) {
result := theme.QuestionIcon().Name()
assert.Equal(t, "foreground_question.svg", result)
}
func Test_WarningIcon_FileSource(t *testing.T) {
result := theme.WarningIcon().Name()
assert.Equal(t, "foreground_warning.svg", result)
}
func Test_BrokenImageIcon_FileSource(t *testing.T) {
result := theme.BrokenImageIcon().Name()
assert.Equal(t, "foreground_broken-image.svg", result)
}
func Test_FolderIcon_FileSource(t *testing.T) {
result := theme.FolderIcon().Name()
assert.Equal(t, "foreground_folder.svg", result)
}
func Test_FolderNewIcon_FileSource(t *testing.T) {
result := theme.FolderNewIcon().Name()
assert.Equal(t, "foreground_folder-new.svg", result)
}
func Test_FolderOpenIcon_FileSource(t *testing.T) {
result := theme.FolderOpenIcon().Name()
assert.Equal(t, "foreground_folder-open.svg", result)
}
func Test_HelpIcon_FileSource(t *testing.T) {
result := theme.HelpIcon().Name()
assert.Equal(t, "foreground_help.svg", result)
}
func Test_HomeIcon_FileSource(t *testing.T) {
result := theme.HomeIcon().Name()
assert.Equal(t, "foreground_home.svg", result)
}
func Test_SettingsIcon_FileSource(t *testing.T) {
result := theme.SettingsIcon().Name()
assert.Equal(t, "foreground_settings.svg", result)
}
func Test_MailAttachmentIcon_FileSource(t *testing.T) {
result := theme.MailAttachmentIcon().Name()
assert.Equal(t, "foreground_mail-attachment.svg", result)
}
func Test_MailComposeIcon_FileSource(t *testing.T) {
result := theme.MailComposeIcon().Name()
assert.Equal(t, "foreground_mail-compose.svg", result)
}
func Test_MailForwardIcon_FileSource(t *testing.T) {
result := theme.MailForwardIcon().Name()
assert.Equal(t, "foreground_mail-forward.svg", result)
}
func Test_MailReplyIcon_FileSource(t *testing.T) {
result := theme.MailReplyIcon().Name()
assert.Equal(t, "foreground_mail-reply.svg", result)
}
func Test_MailReplyAllIcon_FileSource(t *testing.T) {
result := theme.MailReplyAllIcon().Name()
assert.Equal(t, "foreground_mail-reply_all.svg", result)
}
func Test_MailSendIcon_FileSource(t *testing.T) {
result := theme.MailSendIcon().Name()
assert.Equal(t, "foreground_mail-send.svg", result)
}
func Test_MoveDownIcon_FileSource(t *testing.T) {
result := theme.MoveDownIcon().Name()
assert.Equal(t, "foreground_arrow-down.svg", result)
}
func Test_MoveUpIcon_FileSource(t *testing.T) {
result := theme.MoveUpIcon().Name()
assert.Equal(t, "foreground_arrow-up.svg", result)
}
func Test_NavigateBackIcon_FileSource(t *testing.T) {
result := theme.NavigateBackIcon().Name()
assert.Equal(t, "foreground_arrow-back.svg", result)
}
func Test_NavigateNextIcon_FileSource(t *testing.T) {
result := theme.NavigateNextIcon().Name()
assert.Equal(t, "foreground_arrow-forward.svg", result)
}
func Test_ViewFullScreenIcon_FileSource(t *testing.T) {
result := theme.ViewFullScreenIcon().Name()
assert.Equal(t, "foreground_view-fullscreen.svg", result)
}
func Test_ViewRestoreIcon_FileSource(t *testing.T) {
result := theme.ViewRestoreIcon().Name()
assert.Equal(t, "foreground_view-zoom-fit.svg", result)
}
func Test_ViewRefreshIcon_FileSource(t *testing.T) {
result := theme.ViewRefreshIcon().Name()
assert.Equal(t, "foreground_view-refresh.svg", result)
}
func Test_ZoomFitIcon_FileSource(t *testing.T) {
result := theme.ZoomFitIcon().Name()
assert.Equal(t, "foreground_view-zoom-fit.svg", result)
}
func Test_ZoomInIcon_FileSource(t *testing.T) {
result := theme.ZoomInIcon().Name()
assert.Equal(t, "foreground_view-zoom-in.svg", result)
}
func Test_ZoomOutIcon_FileSource(t *testing.T) {
result := theme.ZoomOutIcon().Name()
assert.Equal(t, "foreground_view-zoom-out.svg", result)
}
func Test_VisibilityIcon_FileSource(t *testing.T) {
result := theme.VisibilityIcon().Name()
assert.Equal(t, "foreground_visibility.svg", result)
}
func Test_VisibilityOffIcon_FileSource(t *testing.T) {
result := theme.VisibilityOffIcon().Name()
assert.Equal(t, "foreground_visibility-off.svg", result)
}
func Test_AccountIcon_FileSource(t *testing.T) {
result := theme.AccountIcon().Name()
assert.Equal(t, "foreground_account.svg", result)
}
func Test_LoginIcon_FileSource(t *testing.T) {
result := theme.LoginIcon().Name()
assert.Equal(t, "foreground_login.svg", result)
}
func Test_LogoutIcon_FileSource(t *testing.T) {
result := theme.LogoutIcon().Name()
assert.Equal(t, "foreground_logout.svg", result)
}
func Test_ListIcon_FileSource(t *testing.T) {
result := theme.ListIcon().Name()
assert.Equal(t, "foreground_list.svg", result)
}
func Test_GridIcon_FileSource(t *testing.T) {
result := theme.GridIcon().Name()
assert.Equal(t, "foreground_grid.svg", result)
}