package web
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
)
func TestRenderReadings(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
html := string(RenderReadings(secs, []string{"wuj"}, "new"))
if !strings.Contains(html, "Ewangelia") || !strings.Contains(html, "class=") {
t.Errorf("reading pane missing heading/classes: %q", html[:min(200, len(html))])
}
}
func TestBuiltinThemes(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{
"transfiguration", "desert_fathers", "benedictines", "franciscans",
"memento_mori", "camaldolese", "advent", "nativity", "lent", "easter",
"pentecost", "ordinary",
} {
if b, err := themeCSS(name); err != nil || len(b) == 0 {
t.Errorf("built-in theme %s not embedded: %v", name, err)
}
}
}
func TestThemeCSSGuardRejectsInvalidNames(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{"../../etc/passwd", "..", "a/b", ""} {
if _, err := themeCSS(name); err == nil {
t.Errorf("themeCSS(%q): expected error, got nil", name)
}
}
}
func TestRenderReadingsEscapesScriptText(t *testing.T) {
secs := []liturgy.Section{{
Heading: "Test",
PartID: "pierwsze_czytanie",
Paragraphs: [][]string{{""}},
}}
html := string(RenderReadings(secs, []string{"pl"}, "new"))
if strings.Contains(html, "") {
t.Errorf("raw