Landwelle Gitea CI / Go tests and vet (push) Successful in 1m33s
Landwelle Gitea source ZIP / source-zip (push) Failing after 11m45s
Landwelle Gitea CI / JavaScript and deployment-script checks (push) Failing after 14m47s
Landwelle Gitea CI / Linux x64 production build (push) Failing after 14m53s
Replace the static excursions promo with eight published editorial links, category and date; share ordered query with existing story cards. Add template and PostgreSQL regression tests.
165 lines
6.1 KiB
Go
165 lines
6.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDefaultNavigationContainsLandwelleVorOrtUnderUnserNorden(t *testing.T) {
|
|
items := defaultNavigationItems()
|
|
for _, item := range items {
|
|
if item.Label != "Unser Norden" {
|
|
continue
|
|
}
|
|
for _, child := range item.Children {
|
|
if child.Label == "Landwelle vor Ort" && child.URL == "/landwelle-vor-ort" && child.Active {
|
|
return
|
|
}
|
|
}
|
|
t.Fatal("Unser Norden enthält keinen aktiven Menüpunkt Landwelle vor Ort")
|
|
}
|
|
t.Fatal("Hauptnavigation enthält Unser Norden nicht")
|
|
}
|
|
|
|
func TestLandwelleVorOrtOverviewTemplateListsPublishedEntries(t *testing.T) {
|
|
funcs := template.FuncMap{
|
|
"seoHead": func(...any) template.HTML { return "" },
|
|
"publicNavigation": func() template.HTML { return navigationHTML(defaultNavigationItems()) },
|
|
"year": func() int { return 2026 },
|
|
}
|
|
tmpl, err := template.New("root").Funcs(funcs).ParseFS(webFS, "web/partials.html", "web/landwelle-vor-ort.html")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data := editorialStoriesPageData{
|
|
SectionTitle: "Alle Beiträge",
|
|
Entries: []EditorialEntry{{
|
|
Title: "Landwelle besucht den Norden", Slug: "landwelle-besucht-den-norden", ContentType: "traditionen", ContentTypeLabel: "Traditionen", HomepageSection: true, Teaser: "Ein Beitrag vor Ort.", Location: "Visselhövede", PublishedAt: time.Date(2026, 8, 28, 12, 0, 0, 0, time.UTC),
|
|
}},
|
|
}
|
|
var out bytes.Buffer
|
|
if err := tmpl.ExecuteTemplate(&out, "landwelle-vor-ort.html", data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
html := out.String()
|
|
for _, want := range []string{"Landwelle vor Ort", "Alle Beiträge", "/landwelle-vor-ort/traditionen/landwelle-besucht-den-norden", "Visselhövede", "Landwelle besucht den Norden"} {
|
|
if !strings.Contains(html, want) {
|
|
t.Fatalf("Übersicht enthält %q nicht", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLandwelleVorOrtNavigationMigration(t *testing.T) {
|
|
body, err := os.ReadFile("../../migrations/0045_landwelle_vor_ort_public_index.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := string(body)
|
|
for _, want := range []string{"Unser Norden", "Landwelle vor Ort", "/landwelle-vor-ort", "navigation_items"} {
|
|
if !strings.Contains(s, want) {
|
|
t.Fatalf("Migration enthält %q nicht", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProductionPublicTemplateSetContainsLandwelleVorOrt(t *testing.T) {
|
|
want := "web/landwelle-vor-ort.html"
|
|
found := false
|
|
for _, file := range publicTemplateFiles {
|
|
if file == want {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("produktives öffentliches Template-Set enthält %s nicht", want)
|
|
}
|
|
|
|
funcs := template.FuncMap{
|
|
"seoHead": seoHead,
|
|
"publicNavigation": func() template.HTML { return navigationHTML(defaultNavigationItems()) },
|
|
"year": func() int { return 2026 },
|
|
"playlistURL": playlistPageURL,
|
|
"paragraphs": managedParagraphs,
|
|
"seq": func(a, b int) []int {
|
|
out := make([]int, 0, b-a+1)
|
|
for i := a; i <= b; i++ {
|
|
out = append(out, i)
|
|
}
|
|
return out
|
|
},
|
|
}
|
|
tmpl, err := template.New("production-public").Funcs(funcs).ParseFS(webFS, publicTemplateFiles...)
|
|
if err != nil {
|
|
t.Fatalf("produktives öffentliches Template-Set kann nicht geladen werden: %v", err)
|
|
}
|
|
if tmpl.Lookup("landwelle-vor-ort.html") == nil {
|
|
t.Fatal("landwelle-vor-ort.html ist nach ParseFS im produktiven Template-Set nicht verfügbar")
|
|
}
|
|
}
|
|
|
|
func TestLandwelleVorOrtOverviewQueryHasNoArtificialLimit(t *testing.T) {
|
|
allQuery := homepageStoriesQuery(0)
|
|
if strings.Contains(strings.ToUpper(allQuery), " LIMIT ") {
|
|
t.Fatalf("Übersichtsabfrage darf kein LIMIT enthalten: %s", allQuery)
|
|
}
|
|
|
|
homeQuery := homepageStoriesQuery(homepageRecentStoryLimit)
|
|
if !strings.Contains(strings.ToUpper(homeQuery), " LIMIT 8") {
|
|
t.Fatalf("Startseitenabfrage soll auf acht Beiträge begrenzt sein: %s", homeQuery)
|
|
}
|
|
}
|
|
|
|
func TestLandwelleVorOrtUsesCategoryHierarchy(t *testing.T) {
|
|
entry := EditorialEntry{ContentType: "traditionen", ContentTypeLabel: "Traditionen", Slug: "bauernmarkt", HomepageSection: true}
|
|
if got, want := entry.PublicPath(), "/landwelle-vor-ort/traditionen/bauernmarkt"; got != want {
|
|
t.Fatalf("PublicPath = %q, want %q", got, want)
|
|
}
|
|
if got, want := entry.CategoryPath(), "/landwelle-vor-ort/traditionen"; got != want {
|
|
t.Fatalf("CategoryPath = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLandwelleVorOrtCategoryQueryFiltersWithoutLimit(t *testing.T) {
|
|
q := homepageStoriesByCategoryQuery("traditionen")
|
|
upper := strings.ToUpper(q)
|
|
if strings.Contains(upper, " LIMIT ") {
|
|
t.Fatalf("Kategorieabfrage darf kein LIMIT enthalten: %s", q)
|
|
}
|
|
if !strings.Contains(q, "e.content_type='traditionen'") {
|
|
t.Fatalf("Kategorieabfrage filtert nicht nach content_type: %s", q)
|
|
}
|
|
}
|
|
|
|
func TestLandwelleVorOrtCategoryNavigationTemplate(t *testing.T) {
|
|
funcs := template.FuncMap{
|
|
"seoHead": func(...any) template.HTML { return "" },
|
|
"publicNavigation": func() template.HTML { return navigationHTML(defaultNavigationItems()) },
|
|
"year": func() int { return 2026 },
|
|
}
|
|
tmpl, err := template.New("root").Funcs(funcs).ParseFS(webFS, "web/partials.html", "web/landwelle-vor-ort.html")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
category := EditorialContentType{Slug: "traditionen", Name: "Traditionen", HomepageSection: true, Active: true}
|
|
data := editorialStoriesPageData{
|
|
Categories: []EditorialContentType{category}, ActiveCategory: category, HasActiveCategory: true,
|
|
PageTitle: "Landwelle vor Ort: Traditionen", MetaDescription: "Traditionen aus dem Norden", CanonicalPath: "/landwelle-vor-ort/traditionen", SectionTitle: "Traditionen",
|
|
Entries: []EditorialEntry{{Title: "Bauernmarkt", Slug: "bauernmarkt", ContentType: "traditionen", ContentTypeLabel: "Traditionen", HomepageSection: true, PublishedAt: time.Date(2026, 9, 1, 12, 0, 0, 0, time.UTC)}},
|
|
}
|
|
var out bytes.Buffer
|
|
if err := tmpl.ExecuteTemplate(&out, "landwelle-vor-ort.html", data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
html := out.String()
|
|
for _, want := range []string{"/landwelle-vor-ort/traditionen", "/landwelle-vor-ort/traditionen/bauernmarkt", "Traditionen"} {
|
|
if !strings.Contains(html, want) {
|
|
t.Fatalf("Kategorieansicht enthält %q nicht", want)
|
|
}
|
|
}
|
|
}
|