aboutsummaryrefslogtreecommitdiff
path: root/internal/web/render_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/render_test.go')
-rw-r--r--internal/web/render_test.go56
1 files changed, 48 insertions, 8 deletions
diff --git a/internal/web/render_test.go b/internal/web/render_test.go
index b7f5b1e..de3c7c1 100644
--- a/internal/web/render_test.go
+++ b/internal/web/render_test.go
@@ -11,12 +11,52 @@ import (
func TestRenderReadings(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "Ewangelia") || !strings.Contains(html, "class=") {
t.Errorf("reading pane missing heading/classes: %q", html[:min(200, len(html))])
}
}
+// TestRenderReadingsDayInfoHeader checks RenderReadings prepends a
+// "<p class="dayinfo">" header carrying the celebration Name (heading role)
+// and Season (citation role, muted) ahead of the reading sections, and that
+// it reuses the existing role classes rather than inventing new ones.
+func TestRenderReadingsDayInfoHeader(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
+ info := liturgy.DayInfo{Name: "Święto św. Marii Magdaleny", Colour: "white"}
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", info))
+ if !strings.Contains(html, `class="dayinfo"`) {
+ t.Errorf("missing dayinfo header: %q", html[:min(300, len(html))])
+ }
+ if !strings.Contains(html, "Święto św. Marii Magdaleny") {
+ t.Errorf("dayinfo header missing the day name: %q", html[:min(300, len(html))])
+ }
+ if i := strings.Index(html, `class="dayinfo"`); i > strings.Index(html, "reading-section") && strings.Index(html, "reading-section") != -1 {
+ t.Errorf("dayinfo header should come before the reading sections: %q", html[:min(400, len(html))])
+ }
+}
+
+// TestRenderReadingsDayInfoSeason checks the Season (traditional lectionary
+// only) renders as a muted citation-role span alongside Name.
+func TestRenderReadingsDayInfoSeason(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Gospel", PartID: "evangelium"}}
+ info := liturgy.DayInfo{Name: "St. Mary Magdalene", Season: "Feria IV after VIII Sunday after Pentecost", Colour: "white"}
+ html := string(RenderReadings(secs, []string{"wuj"}, "traditional", "horizontal", "en", info))
+ if !strings.Contains(html, "Feria IV after VIII Sunday after Pentecost") {
+ t.Errorf("dayinfo header missing Season: %q", html[:min(400, len(html))])
+ }
+}
+
+// TestRenderReadingsNoDayInfoHeaderWhenEmpty checks the header is entirely
+// omitted (never an empty/error stub) when the source yielded no DayInfo.
+func TestRenderReadingsNoDayInfoHeaderWhenEmpty(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
+ if strings.Contains(html, `class="dayinfo"`) {
+ t.Errorf("dayinfo header should be omitted when Name is empty: %q", html)
+ }
+}
+
func TestBuiltinThemes(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{
@@ -45,7 +85,7 @@ func TestRenderReadingsEscapesScriptText(t *testing.T) {
PartID: "pierwsze_czytanie",
Paragraphs: [][]string{{"<script>alert(1)</script>"}},
}}
- html := string(RenderReadings(secs, []string{"bt"}, "new", "horizontal", "pl"))
+ html := string(RenderReadings(secs, []string{"bt"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "<script>alert(1)</script>") {
t.Errorf("raw <script> leaked into rendered output: %q", html)
}
@@ -56,7 +96,7 @@ func TestRenderReadingsEscapesScriptText(t *testing.T) {
func TestRenderReadingsVertical(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "vertical", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "vertical", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "display-vertical") {
t.Errorf("vertical output missing display-vertical container: %q", html[:min(300, len(html))])
}
@@ -70,7 +110,7 @@ func TestRenderReadingsVertical(t *testing.T) {
func TestRenderReadingsInterlinear(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "ilverse") {
t.Errorf("interlinear output missing ilverse: %q", html[:min(300, len(html))])
}
@@ -91,7 +131,7 @@ func TestRenderReadingsInterlinear(t *testing.T) {
func TestRenderReadingsInterlinearExcludesBT(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"bt", "vul"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"bt", "vul"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "Biblia Tysiąclecia (niedziela.pl)") {
t.Errorf("interlinear output should substitute wuj for bt, not carry bt's label: %q", html[:min(300, len(html))])
}
@@ -102,7 +142,7 @@ func TestRenderReadingsInterlinearExcludesBT(t *testing.T) {
func TestRenderReadingsInterlinearNoVersifiedNote(t *testing.T) {
secs := []liturgy.Section{{Heading: "Bez odwołania", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "ilverse") {
t.Errorf("expected no ilverse blocks when nothing resolves: %q", html)
}
@@ -115,7 +155,7 @@ func TestRenderReadingsInterlinearNoVersifiedNote(t *testing.T) {
// "no verses to align" note (finding §1) follows lang, not always Polish.
func TestRenderReadingsInterlinearNoVersifiedNoteLang(t *testing.T) {
secs := []liturgy.Section{{Heading: "Bez odwołania", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "en"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "en", liturgy.DayInfo{}))
if !strings.Contains(html, "(no verses to align)") {
t.Errorf("en no-verses note missing/wrong: %q", html)
}
@@ -130,7 +170,7 @@ func TestRenderReadingsInterlinearNoVersifiedNoteLang(t *testing.T) {
// citation stays exactly as scraped.
func TestRenderReadingsLocalizesEN(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"vul"}, "new", "horizontal", "en"))
+ html := string(RenderReadings(secs, []string{"vul"}, "new", "horizontal", "en", liturgy.DayInfo{}))
if !strings.Contains(html, "Gospel (J 20, 1. 11-18)") {
t.Errorf("en output missing localised heading: %q", html[:min(300, len(html))])
}