@@ -10,7 +10,7 @@ import (
1010
1111func TestNewIcons (t * testing.T ) {
1212 t .Run ("Standard" , func (t * testing.T ) {
13- c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , Icon : "test" }
13+ c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , StaticPath : fs . Abs ( "./testdata" ), Icon : "test" }
1414 result := NewIcons (c )
1515 assert .NotEmpty (t , result )
1616 assert .Len (t , result , len (IconSizes )+ len (MaskableIconSizes ))
@@ -20,21 +20,36 @@ func TestNewIcons(t *testing.T) {
2020 assert .Equal (t , "" , result [0 ].Purpose )
2121 })
2222 t .Run ("Maskable" , func (t * testing.T ) {
23- c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , Icon : "test" }
23+ c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , StaticPath : fs . Abs ( "./testdata" ), Icon : "test" }
2424 result := NewIcons (c )
25- maskable := make (Icons , 0 , len (MaskableIconSizes ))
26- for _ , icon := range result {
27- if icon .Purpose == "maskable" {
28- maskable = append (maskable , icon )
29- }
30- }
25+ maskable := maskableIcons (result )
3126 assert .Len (t , maskable , len (MaskableIconSizes ))
3227 assert .Equal (t , "https://demo-cdn.photoprism.app/static/icons/test/maskable/192.png" , maskable [0 ].Src )
3328 assert .Equal (t , "192x192" , maskable [0 ].Sizes )
3429 assert .Equal (t , "image/png" , maskable [0 ].Type )
3530 assert .Equal (t , "https://demo-cdn.photoprism.app/static/icons/test/maskable/512.png" , maskable [1 ].Src )
3631 assert .Equal (t , "512x512" , maskable [1 ].Sizes )
3732 })
33+ t .Run ("MaskablePartial" , func (t * testing.T ) {
34+ c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , StaticPath : fs .Abs ("./testdata" ), Icon : "partial" }
35+ result := NewIcons (c )
36+ maskable := maskableIcons (result )
37+ assert .Len (t , maskable , 1 )
38+ assert .Equal (t , "https://demo-cdn.photoprism.app/static/icons/partial/maskable/192.png" , maskable [0 ].Src )
39+ assert .Len (t , result , len (IconSizes )+ 1 )
40+ })
41+ t .Run ("MaskableMissing" , func (t * testing.T ) {
42+ c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , StaticPath : fs .Abs ("./testdata" ), Icon : "nomask" }
43+ result := NewIcons (c )
44+ assert .Empty (t , maskableIcons (result ))
45+ assert .Len (t , result , len (IconSizes ))
46+ })
47+ t .Run ("StaticPathUnset" , func (t * testing.T ) {
48+ c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , Icon : "test" }
49+ result := NewIcons (c )
50+ assert .Empty (t , maskableIcons (result ))
51+ assert .Len (t , result , len (IconSizes ))
52+ })
3853 t .Run ("Custom" , func (t * testing.T ) {
3954 c := Config {StaticUri : "https://demo-cdn.photoprism.app/static" , Icon : "/test.png" }
4055 result := NewIcons (c )
@@ -56,3 +71,30 @@ func TestNewIcons(t *testing.T) {
5671 assert .Equal (t , "" , result [0 ].Purpose )
5772 })
5873}
74+
75+ func TestMaskableIconExists (t * testing.T ) {
76+ staticPath := fs .Abs ("./testdata" )
77+ t .Run ("Exists" , func (t * testing.T ) {
78+ assert .True (t , maskableIconExists (staticPath , "test" , 192 ))
79+ assert .True (t , maskableIconExists (staticPath , "test" , 512 ))
80+ })
81+ t .Run ("Missing" , func (t * testing.T ) {
82+ assert .False (t , maskableIconExists (staticPath , "test" , 256 ))
83+ assert .False (t , maskableIconExists (staticPath , "partial" , 512 ))
84+ assert .False (t , maskableIconExists (staticPath , "nomask" , 192 ))
85+ })
86+ t .Run ("StaticPathUnset" , func (t * testing.T ) {
87+ assert .False (t , maskableIconExists ("" , "test" , 192 ))
88+ })
89+ }
90+
91+ // maskableIcons returns the subset of icons emitted with purpose "maskable".
92+ func maskableIcons (icons Icons ) Icons {
93+ maskable := make (Icons , 0 , len (MaskableIconSizes ))
94+ for _ , icon := range icons {
95+ if icon .Purpose == "maskable" {
96+ maskable = append (maskable , icon )
97+ }
98+ }
99+ return maskable
100+ }
0 commit comments