.ics Download und PDF Layout korrigiert

This commit is contained in:
concierge committed 2026-11-18 09:01:33 +01:00
1 parent dc20d7ec5a
commit cc2e85c111
11 files changed
+424 -73

No files matched your search

+91
View File
@@ -3,7 +3,11 @@ package pdf
import (
"bytes"
"compress/zlib"
"fmt"
"io"
"regexp"
"strconv"
"strings"
"testing"
"time"
@@ -178,6 +182,93 @@ func TestFullPlan(t *testing.T) {
}
}
func multiPageRows() (domain.DayRange, []domain.DayPlanRow, []domain.Church, []domain.Person) {
_, _, churches, people := sampleRows()
church := churches[0]
person := people[0]
start := domain.MustDate("2026-01-01")
var rows []domain.DayPlanRow
for index := 0; index < 60; index++ {
date := domain.AddingDays(index, start)
var services []domain.ServiceWithAssignments
for slot := 0; slot < 3; slot++ {
id := fmt.Sprintf("s-%d-%d", index, slot)
services = append(services, domain.ServiceWithAssignments{
Service: domain.ServiceOccurrence{
ID: id, ChurchID: church.ID, Date: date,
TimeMinutes: 8*60 + slot, Title: "Hochamt",
LectorsNeeded: 1, HelpersNeeded: 1,
Kind: domain.KindRegular, CreatedAt: time.Now(),
},
Church: church,
Assignments: []domain.Assignment{{
ID: "a-" + id, ServiceID: id, PersonID: person.ID,
Role: domain.RoleLector, CreatedAt: time.Now(),
}},
})
}
rows = append(rows, domain.DayPlanRow{Date: date, Services: services})
}
return domain.NewDayRange(start, rows[len(rows)-1].Date), rows, churches, people
}
func TestFullPlanPaginatesWithTotalPageCount(t *testing.T) {
r, rows, churches, people := multiPageRows()
var buf bytes.Buffer
if err := FullPlan(&buf, r, rows, churches, people, Options{TenantName: "Bad Godesberg"}); err != nil {
t.Fatalf("render: %v", err)
}
content := string(pdfContentStreams(t, buf.Bytes()))
if strings.Contains(content, "Fortsetzung") {
t.Fatal("continuation title must not appear on later pages")
}
match := regexp.MustCompile(`Seite 1 von (\d+)`).FindStringSubmatch(content)
if match == nil {
t.Fatalf("first page footer is missing the total page count:\n%s", content)
}
total, err := strconv.Atoi(match[1])
if err != nil || total < 2 {
t.Fatalf("total pages = %q, want at least 2", match[1])
}
if !strings.Contains(content, fmt.Sprintf("Seite %d von %d", total, total)) {
t.Fatalf("last page footer is missing: want Seite %d von %d", total, total)
}
if got := strings.Count(content, "Seite "); got != total {
t.Fatalf("footer count = %d, want %d", got, total)
}
}
func TestFullPlanRowHeightGrowsWithSeveralServices(t *testing.T) {
_, rows, _, people := sampleRows()
pdf := newPDF("L")
tr := translator(pdf)
peopleByID := map[string]domain.Person{}
for _, person := range people {
peopleByID[person.ID] = person
}
churchWidth := (297.0 - 8.5*2 - 17.0 - 57.0 - 1.35*5) / 4
row := rows[0]
oneService := fullPlanRowHeight(pdf, tr, row, churchWidth, peopleByID)
base := row.Services[0]
for index := 0; index < 3; index++ {
extra := base
extra.Service.ID = fmt.Sprintf("extra-%d", index)
extra.Service.TimeMinutes = 11*60 + index
row.Services = append(row.Services, extra)
}
fourServices := fullPlanRowHeight(pdf, tr, row, churchWidth, peopleByID)
if fourServices <= oneService {
t.Fatalf("row height did not grow: one service %.1f, four services %.1f", oneService, fourServices)
}
// A row must have room for all four service blocks, not a fixed cap.
if fourServices-oneService < 3*9 {
t.Fatalf("row height %.1f is too small for four services (one service %.1f)", fourServices, oneService)
}
}
func TestCompactPlan(t *testing.T) {
r, rows, _, people := sampleRows()
var buf bytes.Buffer