Files
jbergner 862f86dc3e
release-tag / release-image (push) Successful in 6m37s
RC-4 nach umfangreichen Updates
2026-07-21 16:28:24 +02:00

95 lines
2.5 KiB
Go

package badge
import (
"bytes"
"strings"
"testing"
)
func TestRenderEscapesText(t *testing.T) {
data, etag := Render(Options{Label: `<script>`, Message: `A&B`, Extent: "assisted"})
if bytes.Contains(data, []byte(`<script>`)) {
t.Fatal("unescaped label")
}
if !bytes.Contains(data, []byte(`A&amp;B`)) {
t.Fatal("message not escaped")
}
if etag == "" {
t.Fatal("missing etag")
}
}
func TestRenderEmojiIsSquareAndPresetSpecific(t *testing.T) {
data, etag := Render(Options{
Label: "KI-Nutzung",
Message: "Vollständige Inhaltserstellung",
Extent: "full",
Preset: "full",
Theme: "emoji",
})
body := string(data)
for _, expected := range []string{
`width="64" height="64"`,
`viewBox="0 0 64 64"`,
`data-theme="emoji"`,
`data-icon="bolt"`,
`fill="#c53030"`,
`<title>KI-Nutzung: Vollständige Inhaltserstellung</title>`,
} {
if !bytes.Contains(data, []byte(expected)) {
t.Fatalf("emoji SVG missing %q: %s", expected, body)
}
}
if etag == "" {
t.Fatal("missing etag")
}
}
func TestRenderEmojiUsesCustomColoursAndEscapesAccessibleText(t *testing.T) {
data, _ := Render(Options{
Label: `<AI>`,
Message: `Research & review`,
Extent: "assisted",
Preset: "research",
Theme: "emoji",
LeftColor: "#112233",
RightColor: "#abcdef",
})
body := string(data)
for _, expected := range []string{
`data-icon="research"`,
`fill="#abcdef"`,
`stroke="#112233"`,
`&lt;AI&gt;: Research &amp; review`,
} {
if !strings.Contains(body, expected) {
t.Fatalf("emoji SVG missing %q: %s", expected, body)
}
}
if strings.Contains(body, `<AI>`) {
t.Fatal("accessible text was not escaped")
}
}
func TestEmojiIconMapping(t *testing.T) {
tests := []struct {
name string
options Options
icon string
}{
{name: "no AI", options: Options{Extent: "none", Preset: "no-ai", Theme: "emoji"}, icon: "human"},
{name: "research", options: Options{Extent: "assisted", Preset: "research", Theme: "emoji"}, icon: "research"},
{name: "summary", options: Options{Extent: "assisted", Preset: "summary", Theme: "emoji"}, icon: "summary"},
{name: "full", options: Options{Extent: "full", Preset: "full", Theme: "emoji"}, icon: "bolt"},
{name: "article", options: Options{Extent: "mostly", Article: true, Theme: "emoji"}, icon: "article"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, _ := Render(tt.options)
if !bytes.Contains(data, []byte(`data-icon="`+tt.icon+`"`)) {
t.Fatalf("expected icon %q: %s", tt.icon, data)
}
})
}
}