完善后台的图标库引用逻辑和在线图标库的引用
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package api
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"home-vue-go/internal/config"
|
||||
)
|
||||
|
||||
func TestURLValidation(t *testing.T) {
|
||||
for _, value := range []string{"https://example.com", "http://localhost:8080"} {
|
||||
@@ -30,6 +35,49 @@ func TestURLValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIconValueValidation(t *testing.T) {
|
||||
for _, value := range []string{
|
||||
"fas fa-home",
|
||||
"fab fa-github",
|
||||
"iconify:mdi:home",
|
||||
"iconify:material-symbols:add-home-outline",
|
||||
} {
|
||||
if !validIconValue(value) {
|
||||
t.Errorf("expected valid icon value: %s", value)
|
||||
}
|
||||
}
|
||||
for _, value := range []string{
|
||||
"",
|
||||
"iconify:MDI:home",
|
||||
"iconify:mdi:",
|
||||
"iconify:mdi:home/../../x",
|
||||
"fas fa-home\"><script>",
|
||||
strings.Repeat("a", maxIconValueLength+1),
|
||||
} {
|
||||
if validIconValue(value) {
|
||||
t.Errorf("expected invalid icon value: %s", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAboutLinkIconValidation(t *testing.T) {
|
||||
settings := config.DefaultSiteSettings()
|
||||
settings.AboutLinks[0].Icon = ""
|
||||
if err := validateSiteSettings(settings); err != nil {
|
||||
t.Fatalf("expected empty about link icon to use the frontend fallback: %v", err)
|
||||
}
|
||||
|
||||
settings.AboutLinks[0].Icon = "iconify:tabler:brand-github"
|
||||
if err := validateSiteSettings(settings); err != nil {
|
||||
t.Fatalf("expected valid Iconify about link: %v", err)
|
||||
}
|
||||
|
||||
settings.AboutLinks[0].Icon = "<script>"
|
||||
if err := validateSiteSettings(settings); err == nil {
|
||||
t.Fatal("expected invalid about link icon to be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPercentageCountsSumsToOneHundred(t *testing.T) {
|
||||
values := percentageCounts(map[string]int{"direct": 1, "search": 1, "other": 1}, 3)
|
||||
total := 0
|
||||
|
||||
Reference in New Issue
Block a user