2025-12-19 10:47:05 +01:00
|
|
|
package pdfrender
|
|
|
|
|
|
|
|
|
|
import (
|
2025-12-19 22:32:43 +01:00
|
|
|
"os"
|
2025-12-19 10:47:05 +01:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLoadTemplateSetFromFiles(t *testing.T) {
|
|
|
|
|
// Test loading template set from actual files
|
|
|
|
|
templateSet, err := LoadTemplateSetFromFiles("../templates/Default_A4_Quer")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to load template set: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify we have templates
|
|
|
|
|
if len(templateSet.Templates) == 0 {
|
|
|
|
|
t.Fatal("Expected templates, got none")
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 22:07:46 +01:00
|
|
|
// Find page_1.html and verify its metadata matches the HTML comments
|
2025-12-19 10:47:05 +01:00
|
|
|
var page1 *TemplateWithMeta
|
|
|
|
|
for i := range templateSet.Templates {
|
2025-12-21 22:07:46 +01:00
|
|
|
if templateSet.Templates[i].Metadata.Name == "page_1.html" {
|
2025-12-19 10:47:05 +01:00
|
|
|
page1 = &templateSet.Templates[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if page1 == nil {
|
2025-12-21 22:07:46 +01:00
|
|
|
t.Fatal("page_1.html not found in template set")
|
2025-12-19 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that blocks were parsed from HTML
|
|
|
|
|
if len(page1.Metadata.Blocks) == 0 {
|
|
|
|
|
t.Error("Expected blocks in page1 metadata")
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 22:32:43 +01:00
|
|
|
// Verify skills_column1 block - read expected value directly from template file
|
2025-12-21 22:07:46 +01:00
|
|
|
templateContent, err := os.ReadFile("../templates/Default_A4_Quer/page_1.html")
|
2025-12-19 22:32:43 +01:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to read template file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedBlocks := ParseTemplateMetadata(string(templateContent))
|
|
|
|
|
var expectedSkillsCol1 *BlockMetadata
|
|
|
|
|
for i := range expectedBlocks {
|
|
|
|
|
if expectedBlocks[i].Name == "skills_column1" {
|
|
|
|
|
expectedSkillsCol1 = &expectedBlocks[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if expectedSkillsCol1 == nil {
|
|
|
|
|
t.Fatal("skills_column1 block not found in template file")
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 10:47:05 +01:00
|
|
|
var skillsCol1 *BlockMetadata
|
|
|
|
|
for i := range page1.Metadata.Blocks {
|
|
|
|
|
if page1.Metadata.Blocks[i].Name == "skills_column1" {
|
|
|
|
|
skillsCol1 = &page1.Metadata.Blocks[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if skillsCol1 == nil {
|
|
|
|
|
t.Error("skills_column1 block not found")
|
|
|
|
|
} else {
|
|
|
|
|
// Should match the MAX value in the template comment
|
2025-12-19 22:32:43 +01:00
|
|
|
if skillsCol1.MaxItems != expectedSkillsCol1.MaxItems {
|
|
|
|
|
t.Errorf("Expected skills_column1 MaxItems %d (from template), got %d", expectedSkillsCol1.MaxItems, skillsCol1.MaxItems)
|
2025-12-19 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
if skillsCol1.ListType != "skills" {
|
|
|
|
|
t.Errorf("Expected ListType 'skills', got '%s'", skillsCol1.ListType)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDefaultA4QuerTemplateSet_LoadsFromFiles(t *testing.T) {
|
|
|
|
|
// Test that DefaultA4QuerTemplateSet now loads from actual files
|
|
|
|
|
templateSet := DefaultA4QuerTemplateSet()
|
|
|
|
|
|
|
|
|
|
if len(templateSet.Templates) == 0 {
|
|
|
|
|
t.Fatal("Expected templates, got none")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify metadata comes from template files, not hardcoded
|
2025-12-19 22:32:43 +01:00
|
|
|
// Read expected value directly from template file
|
2025-12-21 22:07:46 +01:00
|
|
|
templateContent, err := os.ReadFile("../templates/Default_A4_Quer/page_3.html")
|
2025-12-19 22:32:43 +01:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to read template file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedBlocks := ParseTemplateMetadata(string(templateContent))
|
|
|
|
|
var expectedSpellsLeft *BlockMetadata
|
|
|
|
|
for i := range expectedBlocks {
|
2025-12-22 23:20:49 +01:00
|
|
|
if expectedBlocks[i].Name == "spells_column1" {
|
2025-12-19 22:32:43 +01:00
|
|
|
expectedSpellsLeft = &expectedBlocks[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if expectedSpellsLeft == nil {
|
2025-12-22 23:20:49 +01:00
|
|
|
t.Fatal("spells_column1 block not found in template file")
|
2025-12-19 22:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-19 10:47:05 +01:00
|
|
|
var page3 *TemplateWithMeta
|
|
|
|
|
for i := range templateSet.Templates {
|
2025-12-21 22:07:46 +01:00
|
|
|
if templateSet.Templates[i].Metadata.Name == "page_3.html" {
|
2025-12-19 10:47:05 +01:00
|
|
|
page3 = &templateSet.Templates[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if page3 == nil {
|
2025-12-21 22:07:46 +01:00
|
|
|
t.Fatal("page_3.html not found")
|
2025-12-19 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var spellsLeft *BlockMetadata
|
|
|
|
|
for i := range page3.Metadata.Blocks {
|
2025-12-22 23:20:49 +01:00
|
|
|
if page3.Metadata.Blocks[i].Name == "spells_column1" {
|
2025-12-19 10:47:05 +01:00
|
|
|
spellsLeft = &page3.Metadata.Blocks[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if spellsLeft == nil {
|
2025-12-22 23:20:49 +01:00
|
|
|
t.Error("spells_column1 block not found")
|
2025-12-19 10:47:05 +01:00
|
|
|
} else {
|
2025-12-19 22:32:43 +01:00
|
|
|
// Should match the value from the template file
|
|
|
|
|
if spellsLeft.MaxItems != expectedSpellsLeft.MaxItems {
|
2025-12-22 23:20:49 +01:00
|
|
|
t.Errorf("Expected spells_column1 MaxItems %d (from template file), got %d", expectedSpellsLeft.MaxItems, spellsLeft.MaxItems)
|
2025-12-19 10:47:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|